Skip to content

Instantly share code, notes, and snippets.

@tylergannon
Last active June 22, 2018 23:19
Show Gist options
  • Save tylergannon/474adbd3124cd6f4979116a27ea4d41e to your computer and use it in GitHub Desktop.
Save tylergannon/474adbd3124cd6f4979116a27ea4d41e to your computer and use it in GitHub Desktop.
Configure Git, Download Repository, Start Kubo inside of project.
# Command to run:
# $file = [System.IO.Path]::GetTempFileName(); (New-Object System.Net.WebClient).DownloadString('https://kubobuild.page.link/rniX') | Out-File -FilePath "${file}.ps1"; . "${file}.ps1"
& {
$wid=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$prp=new-object System.Security.Principal.WindowsPrincipal($wid)
$adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator
$IsAdmin=$prp.IsInRole($adm)
if ($IsAdmin)
{
Write-Host -ForegroundColor Yellow "This should not be run as administrator."
Write-Host -ForegroundColor Yellow "Please open a new powershell, and try again."
exit 2
}
else
{
$name = Read-Host -Prompt "Please give your full name for Git config"
$email = Read-Host -Prompt "Enter your email for Git config"
$repo = Read-Host -Prompt "Please enter the location of your git repository"
$machineId = Read-Host -Prompt "Please enter the machine ID (number between 1 and 20) from your manager."
$captures = [regex]::Match($repo, "git@([\w.-_]+):.*\/(.*).git").captures
$gitService = $captures.groups[1].value
$project = $captures.groups[2].value
if (-not (Test-Path -Path "${home}\.ssh\id_rsa")) {
Write-Host "You don't have an SSH key so I'll go ahead and create one."
Write-Host "An empty passphrase is normally fine."
New-Item -Force -Type Directory -Path "${home}\.ssh"
ssh-keygen -t rsa -f "${home}\.ssh\id_rsa"
} else {
Write-Host "Not creating an SSH key since you already have one."
}
git config --global user.name "${name}"
git config --global user.email "${email}"
git config --global core.autocrlf input
Get-Content ${home}\.ssh\id_rsa.pub | Set-Clipboard
Write-Host "I've copied your public key to your clipboard."
if ($repo -match "^git@gitlab\.com") {
$url = "https://gitlab.com/profile/keys"
$githost = "Gitlab"
} elseif ($repo -match "^git@github\.com") {
$url = "https://github.com/settings/ssh/new"
$githost = "Github"
}
if ($githost) {
Write-Host "Press any key to open the web page for adding your public key to ${githost}."
Write-Host "Press control-V to paste the key into the page."
Write-Host ""
Write-Host "If you lose the contents of the clipboard, run the following to get it back:"
Write-Host 'Get-Content ${home}\.ssh\id_rsa.pub | Set-Clipboard'
Write-Host ""
Write-Host "Then return back here after saving your public key."
Read-Host -Prompt 'press a key to open a browser...'
Start-Process $url
} else {
Write-Host "Now go to your Git service and add the new key to your account there, and come back."
}
Read-Host -Prompt "Then press a key to continue..."
git clone $repo
Set-Location $project
Write-Output "${project}" |
Out-File -FilePath "projectname" -Encoding utf8 -NoNewLine
Write-Output "MACHINE_ID=${machineId}" |
Out-File -FilePath ".env.local" -Encoding utf8 -NoNewLine
vagrant plugin install vagrant-scp
$startApp = Read-Host -Prompt "Shall I start your app for you?"
if ($startApp -match "^y") {
$url = "https://${project}.dev"
Write-Host "Okay this will take a few minutes. You should soon be able to navigate to ${url}."
vagrant.exe up
vagrant.exe ssh -c "cd ${project} `&`& bin/start"
} else {
Write-Host 'Okay you''re all set to do a ''vagrant up'''
}
}
}
@tylergannon
Copy link
Author

Run command in PowerShell:

$file = [System.IO.Path]::GetTempFileName(); (New-Object System.Net.WebClient).DownloadString('https://kubobuild.page.link/rniX') | Out-File -FilePath "${file}.ps1"; . "${file}.ps1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment