From 8a25cfa01ab175c02e9f7cf8b97f30b4b35d15be Mon Sep 17 00:00:00 2001
From: Dennis Ahrens <dennis.ahrens@hs-hannover.de>
Date: Wed, 22 Aug 2018 14:17:34 +0200
Subject: [PATCH] Initial commit

---
 Install.ps1 | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 README.md   |  8 ++++++-
 2 files changed, 73 insertions(+), 1 deletion(-)
 create mode 100644 Install.ps1

diff --git a/Install.ps1 b/Install.ps1
new file mode 100644
index 0000000..099c274
--- /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 a771617..b22ed3e 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'))
+```
-- 
GitLab