Update bootstrap-Windows.ps1 script
* Add 1Password install step * Add Scoop install step * Remove SSH key generation step * Make 1Password, Hyper-V, Containers, and SSH Server steps optional * Refactor to run Scoop install as unelevated then relaunch as elevated for remaining tasks
This commit is contained in:
parent
3606f4bbb9
commit
eddeb98a22
@ -31,7 +31,7 @@ $ curl -O https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Fedora
|
|||||||
To bootstrap a Windows instance:
|
To bootstrap a Windows instance:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Windows.ps1'))
|
$ Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-WebRequest -Uri "https://git.infektor.net/config/bootstrap/raw/update/bootstrap-Windows.ps1" -OutFile "./bootstrap-Windows.ps1"; ./bootstrap-Windows.ps1; Remove-Item ./bootstrap-Windows.ps1
|
||||||
```
|
```
|
||||||
|
|
||||||
## Package
|
## Package
|
||||||
|
@ -1,26 +1,65 @@
|
|||||||
[CmdletBinding()]
|
$IsElevated = [bool]([Security.Principal.WindowsPrincipal] `
|
||||||
Param(
|
[Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
|
||||||
[Parameter(Mandatory=$true)]
|
$Choices = '&Yes', '&No'
|
||||||
[String]$email,
|
|
||||||
[String]$sshKeyType = "ed25519"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Install Chocolatey
|
if (-Not $IsElevated) {
|
||||||
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
|
Write-Host "Not running as Administrator. Performing unprivileged actions."
|
||||||
|
|
||||||
# Enable Hyper-V and containters
|
# Install Scoop
|
||||||
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
|
Write-Host "`nInstall Scoop"
|
||||||
Enable-WindowsOptionalFeature -Online -FeatureName Containers -All
|
$ScoopInstaller = "$env:USERPROFILE/Downloads/ScoopInstaller.ps1"
|
||||||
|
Invoke-WebRequest -Uri https://get.scoop.sh -OutFile $ScoopInstaller
|
||||||
|
&$ScoopInstaller -ScoopDir "$env:LocalAppData/Scoop" -ScoopGlobalDir "$env:ProgramData/Scoop"
|
||||||
|
|
||||||
# Install OpenSSH and start service
|
$Decision = $Host.UI.PromptForChoice('Relaunch as Administrator', 'Proceed?', $Choices, 0)
|
||||||
choco install --yes "--package-parameters=/SSHServerFeature" openssh
|
if ($Decision -eq 0) {
|
||||||
Start-Service sshd
|
$Bootstrap = $MyInvocation.MyCommand.Path
|
||||||
Set-Service -Name sshd -StartupType 'Automatic'
|
Start-Process powershell.exe "-ExecutionPolicy ByPass -NoProfile -File $Bootstrap" -Verb RunAs
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host "Running as Administrator. Performing privileged actions."
|
||||||
|
|
||||||
# generate keys and authorize them
|
# Install 1Password
|
||||||
ssh-keygen -t "$sshKeyType" -C "$email" -f "$env:USERPROFILE/.ssh/$sshKeyType"
|
$Decision = $Host.UI.PromptForChoice('Install 1Password', 'Proceed?', $Choices, 0)
|
||||||
# TODO: authorize public key for admin
|
if ($Decision -eq 0) {
|
||||||
|
$1passwordInstaller = "$env:USERPROFILE/Downloads/1PasswordSetup-latest.exe"
|
||||||
|
Invoke-WebRequest -Uri "https://downloads.1password.com/win/1PasswordSetup-latest.exe" -OutFile "$1passwordInstaller"
|
||||||
|
&$1passwordInstaller
|
||||||
|
Remove-Item $1passwordInstaller
|
||||||
|
} else {
|
||||||
|
echo 'Skipping 1Password'
|
||||||
|
}
|
||||||
|
|
||||||
# Install Windows-Terminal and Debian
|
# Enable Hyper-V
|
||||||
choco install --yes microsoft-windows-terminal
|
$Decision = $Host.UI.PromptForChoice('Enable Hyper-V', 'Proceed?', $Choices, 0)
|
||||||
wsl --install --distribution Debia
|
if ($Decision -eq 0) {
|
||||||
|
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
|
||||||
|
} else {
|
||||||
|
echo 'Skipping Hyper-V'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Enable Containters
|
||||||
|
$Decision = $Host.UI.PromptForChoice('Enable Containers', 'Proceed?', $Choices, 0)
|
||||||
|
if ($Decision -eq 0) {
|
||||||
|
Enable-WindowsOptionalFeature -Online -FeatureName Containers -All
|
||||||
|
} else {
|
||||||
|
echo 'Skipping Containers'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Install Chocolatey
|
||||||
|
Write-Host "`nInstall Chocolatey"
|
||||||
|
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
|
||||||
|
|
||||||
|
# Install SSH Server
|
||||||
|
$Decision = $Host.UI.PromptForChoice('Install SSH Server', 'Proceed?', $Choices, 0)
|
||||||
|
if ($Decision -eq 0) {
|
||||||
|
choco install --yes "--package-parameters=/SSHServerFeature" openssh
|
||||||
|
Start-Service sshd
|
||||||
|
Set-Service -Name sshd -StartupType 'Automatic'
|
||||||
|
} else {
|
||||||
|
echo 'Skipping SSH Server'
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host 'Press any key to continue...'
|
||||||
|
[System.Console]::ReadKey($true)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user