diff --git a/Install.ps1 b/Install.ps1 new file mode 100644 index 0000000000000000000000000000000000000000..099c2748f20e7fc9f3153951c1dfcc71124ef2f9 --- /dev/null +++ b/Install.ps1 @@ -0,0 +1,66 @@ +$targetDirectory = "C:\hshgitlab" +$gitDir = "${env:programfiles}\Git\" +$sshKeygenExe = "$gitDir\usr\bin\ssh-keygen.exe" +$sshKeyName = "$targetDirectory\id_rsa" +$sshPublicKey = "$sshKeyName.pub" +<# +Check whether a program is installed. + +Note that is searches in the string which you can find in Control Panel -> Programs and Features. +e.g. it will not find "python3" but "python 3" +#> +function Is-Installed($program) { + $x86 = ((Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall") | + Where-Object { $_.GetValue( "DisplayName" ) -like "*$program*" } ).Length -gt 0; + $x64 = ((Get-ChildItem "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall") | + Where-Object { $_.GetValue( "DisplayName" ) -like "*$program*" } ).Length -gt 0; + return $x86 -or $x64; +} + +"Install just-install for painless installs..." +if(Is-Installed("just-install")) { + "just-install is already installed" +} else { + Start-Process -NoNewWindow msiexec.exe -Wait -ArgumentList '-I https://stable.just-install.it -quiet' +} + +"Install git" +if(Is-Installed("git")) { + "git is already installed" +} else { + Start-Process -NoNewWindow just-install -Wait -ArgumentList 'python3' +} + +"Make some sanity checks in the environment - verify python and git are located where we think they are..." +if (!(Test-Path $pythonExe) ) { + "python.exe is not located at: $pythonExe" + "either the installation was not successful or the path changed." +} +if (!(Test-Path $gitDir) ) { + "git installation not found at: $gitDir" + "either the installation was not successful or the path changed." +} + +"Sanity successfully verified: begin to install our worker" +"Create a directory for our files at $targetDirectory" +if(!(Test-Path -Path $targetDirectory )){ + New-Item -ItemType directory -Path $targetDirectory | Out-Null +} + +"Generate an SSH Keypair for our server to be able to receive code from git" +"It is located at $sshKeyName(.pub)" +if (!(Test-Path $sshKeyName) ) { + Start-Process -NoNewWindow $sshKeygenExe -Wait -ArgumentList "-q -b 4096 -f $sshKeyName -N ''" +} else { + "There was already a key located at $sshKeyName, proceed with this one" +} + +if (!(Test-Path $sshKeyName) ) { + "Key generation not successful" + exit +} + +"You now need to tell gitlab about this ssh public key and can proceed with what you want to install" +"" +cat $sshPublicKey +"" diff --git a/README.md b/README.md index a7716172359a1f047486ccc74523b1b59db3861f..b22ed3eafd8bfe62f19fc45080d832e7b4d0305c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ # bootstrap-git Use this repository to bootstrap git on your windows box. -It also automatically creates a key pair that can be used to connect to a git server. \ No newline at end of file +It also automatically creates a key pair that can be used to connect to a git server. + +Be careful, this executes code directly on your machine. You are expected to read the script before you execute it. + +```powershell +Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://lab.it.hs-hannover.de/powershell/bootstrap-git/raw/master/Install.ps1')) +```