From 7dc63699f10c0be7cf295f082170206adfd2681d Mon Sep 17 00:00:00 2001 From: Daniel Edholm Ignat Date: Tue, 28 Sep 2021 19:35:05 +0200 Subject: [PATCH 1/6] Re-enable Wireguard setup --- GatherUserInput.ps1 | 8 ++++---- SetupDeveloperMachine.ps1 | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/GatherUserInput.ps1 b/GatherUserInput.ps1 index af8c937..8fda4a6 100644 --- a/GatherUserInput.ps1 +++ b/GatherUserInput.ps1 @@ -3,10 +3,10 @@ function Run { Write-Host "" Read-HostAndSaveToEnv -Description "Git user name (eg. John Doe)" -EnvironmentKey WIN10_DEV_BOX_GIT_USER_NAME Read-HostAndSaveToEnv -Description "Git email (eg. john.doe@example.com)" -EnvironmentKey WIN10_DEV_BOX_GIT_EMAIL - #Read-HostAndSaveToEnv -Description "Wireguard config path (eg. C:\wg0.conf)" -EnvironmentKey WIN10_DEV_BOX_WIREGUARD_CONFIG_PATH - #if(!(Test-Path "$([Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_WIREGUARD_CONFIG_PATH", "User"))")) { - # throw "Wireguard config path does not point to a file that exists!" - #} + Read-HostAndSaveToEnv -Description "Wireguard config path (eg. C:\wg0.conf)" -EnvironmentKey WIN10_DEV_BOX_WIREGUARD_CONFIG_PATH + if(!(Test-Path "$([Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_WIREGUARD_CONFIG_PATH", "User"))")) { + throw "Wireguard config path does not point to a file that exists!" + } #Read-HostAndSaveToEnv -Description "Gitlab base url (eg. http://gitlab.example.com)" -EnvironmentKey WIN10_DEV_BOX_GITLAB_BASE_URL #Read-HostAndSaveToEnv -Description "Gitlab api token with 'read api' access (eg. qyfymyD3syW_KqVPXhMH)" -EnvironmentKey WIN10_DEV_BOX_GITLAB_TOKEN #Read-HostAndSaveToEnv -Description "Gitlab group to clone (eg. 12)" -EnvironmentKey WIN10_DEV_BOX_GITLAB_GROUP_ID diff --git a/SetupDeveloperMachine.ps1 b/SetupDeveloperMachine.ps1 index b08894c..5acc9a2 100644 --- a/SetupDeveloperMachine.ps1 +++ b/SetupDeveloperMachine.ps1 @@ -10,7 +10,7 @@ function Run { RunWindowsUpdate AddBoxstarterDoneRestorePoint SetGitUser - #InstallAndConfigureWireguard + InstallAndConfigureWireguard #CloneAllGitlabRepositories OpenManualInstructions } From 5af3f648bea6dffcb9463df0e33f249320b9dc44 Mon Sep 17 00:00:00 2001 From: Daniel Edholm Ignat Date: Tue, 28 Sep 2021 19:58:42 +0200 Subject: [PATCH 2/6] Set up SSH key in gitlab --- GatherUserInput.ps1 | 4 ++-- SetupDeveloperMachine.ps1 | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/GatherUserInput.ps1 b/GatherUserInput.ps1 index 8fda4a6..adc73bc 100644 --- a/GatherUserInput.ps1 +++ b/GatherUserInput.ps1 @@ -7,8 +7,8 @@ function Run { if(!(Test-Path "$([Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_WIREGUARD_CONFIG_PATH", "User"))")) { throw "Wireguard config path does not point to a file that exists!" } - #Read-HostAndSaveToEnv -Description "Gitlab base url (eg. http://gitlab.example.com)" -EnvironmentKey WIN10_DEV_BOX_GITLAB_BASE_URL - #Read-HostAndSaveToEnv -Description "Gitlab api token with 'read api' access (eg. qyfymyD3syW_KqVPXhMH)" -EnvironmentKey WIN10_DEV_BOX_GITLAB_TOKEN + Read-HostAndSaveToEnv -Description "Gitlab base url (eg. http://gitlab.example.com)" -EnvironmentKey WIN10_DEV_BOX_GITLAB_BASE_URL + Read-HostAndSaveToEnv -Description "Gitlab api token with 'api' access (eg. qyfymyD3syW_KqVPXhMH)" -EnvironmentKey WIN10_DEV_BOX_GITLAB_TOKEN #Read-HostAndSaveToEnv -Description "Gitlab group to clone (eg. 12)" -EnvironmentKey WIN10_DEV_BOX_GITLAB_GROUP_ID Write-Host "Done! Do you want to launch a One Click install of SetupDeveloperMachine.ps1 i Microsoft Edge? [y/N]" -ForegroundColor green Write-Host "> " -NoNewline diff --git a/SetupDeveloperMachine.ps1 b/SetupDeveloperMachine.ps1 index 5acc9a2..6de4653 100644 --- a/SetupDeveloperMachine.ps1 +++ b/SetupDeveloperMachine.ps1 @@ -11,6 +11,7 @@ function Run { AddBoxstarterDoneRestorePoint SetGitUser InstallAndConfigureWireguard + ConfigureGitlabSSH #CloneAllGitlabRepositories OpenManualInstructions } @@ -284,6 +285,32 @@ function InstallAndConfigureWireguard { } } +function ConfigureGitlabSSH { + $GitlabBaseUrl = [Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_GITLAB_BASE_URL", "User") + $GitlabToken = [Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_GITLAB_TOKEN", "User") + if ($GitlabBaseUrl -and $GitlabToken) { + $KeyLocation = "$env:USERPROFILE/.ssh/gitlab" + Write-Host "Creating Gitlab SSH key.." + if (!(Test-Path $KeyLocation)) { + ssh-keygen -t ed25519 -f $KeyLocation -q -N """" + Write-Host "..gitlab SSH key created" + } else { + Write-Host "..gitlab SSH key already created" + } + + Write-Host "Uploading Gitlab SSH key.." + $PublicKey = Get-Content "$($KeyLocation).pub" + $CurrentKeys = Invoke-WebRequest "$GitlabBaseUrl/api/v4/user/keys?&private_token=$GitlabToken" | ConvertFrom-Json + if(($CurrentKeys | Where-Object {$_.key.Split(" ")[1] -eq $PublicKey.Split(" ")[1]}).Count -gt 0) { + Write-Host "..key already uploaded" + } else { + $PostParams = @{title='Boxstarter';key=$PublicKey} + Invoke-WebRequest -Uri "$GitlabBaseUrl/api/v4/user/keys?private_token=$GitlabToken" -Method POST -Body $PostParams + Write-Host "..key uploaded" + } + } +} + function CloneAllGitlabRepositories { $GitlabBaseUrl = [Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_GITLAB_BASE_URL", "User") $GitlabToken = [Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_GITLAB_TOKEN", "User") From c820dba7b3e208734aa00297354d085e7db306ae Mon Sep 17 00:00:00 2001 From: Daniel Edholm Ignat Date: Tue, 28 Sep 2021 19:59:20 +0200 Subject: [PATCH 3/6] Re-enable git clone all --- GatherUserInput.ps1 | 2 +- SetupDeveloperMachine.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GatherUserInput.ps1 b/GatherUserInput.ps1 index adc73bc..b32ab4b 100644 --- a/GatherUserInput.ps1 +++ b/GatherUserInput.ps1 @@ -9,7 +9,7 @@ function Run { } Read-HostAndSaveToEnv -Description "Gitlab base url (eg. http://gitlab.example.com)" -EnvironmentKey WIN10_DEV_BOX_GITLAB_BASE_URL Read-HostAndSaveToEnv -Description "Gitlab api token with 'api' access (eg. qyfymyD3syW_KqVPXhMH)" -EnvironmentKey WIN10_DEV_BOX_GITLAB_TOKEN - #Read-HostAndSaveToEnv -Description "Gitlab group to clone (eg. 12)" -EnvironmentKey WIN10_DEV_BOX_GITLAB_GROUP_ID + Read-HostAndSaveToEnv -Description "Gitlab group to clone (eg. 12)" -EnvironmentKey WIN10_DEV_BOX_GITLAB_GROUP_ID Write-Host "Done! Do you want to launch a One Click install of SetupDeveloperMachine.ps1 i Microsoft Edge? [y/N]" -ForegroundColor green Write-Host "> " -NoNewline $LaunchOneClickInstall = Read-Host diff --git a/SetupDeveloperMachine.ps1 b/SetupDeveloperMachine.ps1 index 6de4653..e6e4089 100644 --- a/SetupDeveloperMachine.ps1 +++ b/SetupDeveloperMachine.ps1 @@ -12,7 +12,7 @@ function Run { SetGitUser InstallAndConfigureWireguard ConfigureGitlabSSH - #CloneAllGitlabRepositories + CloneAllGitlabRepositories OpenManualInstructions } From 0a948d932754bf07a032e5d434f28aa614ecbefa Mon Sep 17 00:00:00 2001 From: Daniel Edholm Ignat Date: Wed, 29 Sep 2021 20:47:41 +0200 Subject: [PATCH 4/6] Simplify SSH key uploaded check --- SetupDeveloperMachine.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SetupDeveloperMachine.ps1 b/SetupDeveloperMachine.ps1 index e6e4089..da9cc43 100644 --- a/SetupDeveloperMachine.ps1 +++ b/SetupDeveloperMachine.ps1 @@ -301,7 +301,7 @@ function ConfigureGitlabSSH { Write-Host "Uploading Gitlab SSH key.." $PublicKey = Get-Content "$($KeyLocation).pub" $CurrentKeys = Invoke-WebRequest "$GitlabBaseUrl/api/v4/user/keys?&private_token=$GitlabToken" | ConvertFrom-Json - if(($CurrentKeys | Where-Object {$_.key.Split(" ")[1] -eq $PublicKey.Split(" ")[1]}).Count -gt 0) { + if($CurrentKeys | Where-Object {$_.key.Split(" ")[1] -eq $PublicKey.Split(" ")[1]}) { Write-Host "..key already uploaded" } else { $PostParams = @{title='Boxstarter';key=$PublicKey} From 19487d9ba9d3be3e32d0d34693f73fe394c04afb Mon Sep 17 00:00:00 2001 From: Daniel Edholm Ignat Date: Wed, 29 Sep 2021 21:07:59 +0200 Subject: [PATCH 5/6] Rename SSH key so that it will be automatically used by git --- SetupDeveloperMachine.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SetupDeveloperMachine.ps1 b/SetupDeveloperMachine.ps1 index da9cc43..7d926f6 100644 --- a/SetupDeveloperMachine.ps1 +++ b/SetupDeveloperMachine.ps1 @@ -289,7 +289,7 @@ function ConfigureGitlabSSH { $GitlabBaseUrl = [Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_GITLAB_BASE_URL", "User") $GitlabToken = [Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_GITLAB_TOKEN", "User") if ($GitlabBaseUrl -and $GitlabToken) { - $KeyLocation = "$env:USERPROFILE/.ssh/gitlab" + $KeyLocation = "$env:USERPROFILE/.ssh/id_ed25519" Write-Host "Creating Gitlab SSH key.." if (!(Test-Path $KeyLocation)) { ssh-keygen -t ed25519 -f $KeyLocation -q -N """" From 10d1facd7119b2220006c1df90985610d82a0a3f Mon Sep 17 00:00:00 2001 From: Daniel Edholm Ignat Date: Wed, 29 Sep 2021 21:12:39 +0200 Subject: [PATCH 6/6] Add computer name to SSH key comment and title --- SetupDeveloperMachine.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SetupDeveloperMachine.ps1 b/SetupDeveloperMachine.ps1 index 7d926f6..0602fa2 100644 --- a/SetupDeveloperMachine.ps1 +++ b/SetupDeveloperMachine.ps1 @@ -292,7 +292,7 @@ function ConfigureGitlabSSH { $KeyLocation = "$env:USERPROFILE/.ssh/id_ed25519" Write-Host "Creating Gitlab SSH key.." if (!(Test-Path $KeyLocation)) { - ssh-keygen -t ed25519 -f $KeyLocation -q -N """" + ssh-keygen -t ed25519 -f $KeyLocation -q -C $env:computername -N """" Write-Host "..gitlab SSH key created" } else { Write-Host "..gitlab SSH key already created" @@ -304,7 +304,7 @@ function ConfigureGitlabSSH { if($CurrentKeys | Where-Object {$_.key.Split(" ")[1] -eq $PublicKey.Split(" ")[1]}) { Write-Host "..key already uploaded" } else { - $PostParams = @{title='Boxstarter';key=$PublicKey} + $PostParams = @{title="Boxstarter $env:computername";key=$PublicKey} Invoke-WebRequest -Uri "$GitlabBaseUrl/api/v4/user/keys?private_token=$GitlabToken" -Method POST -Body $PostParams Write-Host "..key uploaded" }