diff --git a/GatherUserInput.ps1 b/GatherUserInput.ps1 index af8c937..b32ab4b 100644 --- a/GatherUserInput.ps1 +++ b/GatherUserInput.ps1 @@ -3,13 +3,13 @@ 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 "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 + 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 '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 $LaunchOneClickInstall = Read-Host diff --git a/SetupDeveloperMachine.ps1 b/SetupDeveloperMachine.ps1 index b08894c..0602fa2 100644 --- a/SetupDeveloperMachine.ps1 +++ b/SetupDeveloperMachine.ps1 @@ -10,8 +10,9 @@ function Run { RunWindowsUpdate AddBoxstarterDoneRestorePoint SetGitUser - #InstallAndConfigureWireguard - #CloneAllGitlabRepositories + 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/id_ed25519" + Write-Host "Creating Gitlab SSH key.." + if (!(Test-Path $KeyLocation)) { + 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" + } + + 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]}) { + Write-Host "..key already uploaded" + } else { + $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" + } + } +} + function CloneAllGitlabRepositories { $GitlabBaseUrl = [Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_GITLAB_BASE_URL", "User") $GitlabToken = [Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_GITLAB_TOKEN", "User")