bootstrap/bootstrap-Windows.ps1
Kenneth Benzie (Benie) fbf1530d01 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
2024-08-09 14:42:40 +01:00

65 lines
2.6 KiB
PowerShell

$is_elevated = [bool]([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
$choices = '&Yes', '&No'
if (-Not $is_elevated) {
Write-Host "Not running as Administrator. Performing unprivileged actions..."
# Install Scoop
Write-Host "`nInstall Scoop"
$scoop_installer = "$env:USERPROFILE/Downloads/ScoopInstaller.ps1"
Invoke-WebRequest -Uri https://get.scoop.sh -OutFile $scoop_installer
&$scoop_installer -ScoopDir "$env:LocalAppData/Scoop" -ScoopGlobalDir "$env:ProgramData/Scoop"
# The command you want to run with elevated privileges
$Command = "Set-ExecutionPolicy Bypass -Scope Process -Force; " +
"[System.Net.ServicePointManager]::SecurityProtocol = " +
"[System.Net.ServicePointManager]::SecurityProtocol -bor 3072; " +
"iex ((New-Object System.Net.WebClient).DownloadString('https://git.infektor.net/config/bootstrap/raw/update/bootstrap-Windows.ps1'))"
# Relaunch with admin privileges
Start-Process powershell.exe "-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs
} else {
Write-Host "Running as Administrator. Performing privileged actions..."
# Install 1Password
$decision = $Host.UI.PromptForChoice('Install 1Password', 'Proceed?', $choices, 0)
if ($decision -eq 0) {
$1password_installer = "$env:USERPROFILE/Downloads/1PasswordSetup-latest.exe"
Invoke-WebRequest -Uri "https://downloads.1password.com/win/1PasswordSetup-latest.exe" -OutFile "$1password_installer"
&$1password_installer
Remove-Item $1password_installer
} else {
echo 'Skipping 1Password'
}
# Enable Hyper-V
$decision = $Host.UI.PromptForChoice('Enable Hyper-V', 'Proceed?', $choices, 0)
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 Scoop"
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'
}
}