From 6997a800b915082530fd80902ebf7f50a2f8f318 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 6 Aug 2024 00:04:02 +0200 Subject: [PATCH] Add scripts for installing essential software --- scripts/Windows/OS/Install.ps1 | 10 ++++- scripts/Windows/Scripts/Config.ps1 | 15 +++++++ scripts/Windows/Software/OpenSSH/Manage.ps1 | 20 ++++++++++ .../Windows/Software/chocolatey/Manage.ps1 | 40 +++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 scripts/Windows/Software/OpenSSH/Manage.ps1 create mode 100644 scripts/Windows/Software/chocolatey/Manage.ps1 diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1 index be49ef89..903c4334 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -115,9 +115,17 @@ $null = New-Module { } ([SetupStage]::Install) { Write-Host "Entering install phase"; + + # Windows Config + . "$PSScriptRoot/../Software/Windows/Manage.ps1"; + + if (Test-Collection "essential") { + # Essentials + . "$PSScriptRoot/../Software/OpenSSH/Manage.ps1"; + } + Set-IsFinished $true; } - Default {} } } } diff --git a/scripts/Windows/Scripts/Config.ps1 b/scripts/Windows/Scripts/Config.ps1 index 564c6d7a..26f24c0e 100644 --- a/scripts/Windows/Scripts/Config.ps1 +++ b/scripts/Windows/Scripts/Config.ps1 @@ -199,6 +199,21 @@ $null = New-Module { Set-SetupOption $finishedOption $true; } + <# + .SYNOPSIS + Checks whether the specified software collection is enabled. + + .PARAMETER Name + The name of the collection to check. + #> + function Test-Collection { + param( + [string] $Name + ) + + Get-Config "valhalla.software.$Name"; + } + <# .SYNOPSIS Checks whether the active session is executed with admin rights. diff --git a/scripts/Windows/Software/OpenSSH/Manage.ps1 b/scripts/Windows/Software/OpenSSH/Manage.ps1 new file mode 100644 index 00000000..43507671 --- /dev/null +++ b/scripts/Windows/Software/OpenSSH/Manage.ps1 @@ -0,0 +1,20 @@ +using namespace Microsoft.Win32; + +param( + $Action, + [hashtable] $Arguments +) + +. "$PSScriptRoot/../../Scripts/Software.ps1"; + +Start-SoftwareInstaller @PSBoundParameters ` + -Installer { + param( + [scriptblock] $Installer + ) + + & $Installer -Action ([InstallerAction]::Configure) + } ` + -Configurator { + Set-Service ssh-agent -StartupType AutomaticDelayedStart; + }; diff --git a/scripts/Windows/Software/chocolatey/Manage.ps1 b/scripts/Windows/Software/chocolatey/Manage.ps1 new file mode 100644 index 00000000..d48becad --- /dev/null +++ b/scripts/Windows/Software/chocolatey/Manage.ps1 @@ -0,0 +1,40 @@ +using namespace Microsoft.Win32; + +param( + $Action, + [hashtable] $Arguments +) + +. "$PSScriptRoot/../../Scripts/Software.ps1"; + +Start-SoftwareInstaller @PSBoundParameters ` + -Installer { + param( + [scriptblock] $Installer + ) + + & $Installer -Action ([InstallerAction]::Configure) + } ` + -Configurator { + $nativeProfile = powershell -c '$PROFILE'; + New-Item -Force $nativeProfile; + choco install -y --force chocolatey; + Copy-Item -Force $nativeProfile $PROFILE; + + Push-Location ~; + $files = @($nativeProfile, $PROFILE) | ForEach-Object { Resolve-Path -Relative $_ }; + Pop-Location; + + foreach ($path in $files) { + $fullName = "$env:SystemDrive/Users/Default/$path"; + $dirName = Split-Path -Parent $fullName; + + if (-not (Test-Path -PathType Container $dirName)) { + $null = New-Item -Force -ItemType Directory $dirName; + } + + Copy-Item -Force ~/"$path" $fullName; + } + + Import-Module "$env:ChocolateyInstall/helpers/chocolateyProfile.psm1"; + };