From ae1c05ff35f289798a985ff08a94ee1e94d8dbfb Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Fri, 9 Aug 2024 13:34:46 +0200 Subject: [PATCH] Implement root install loop using a `switch` --- scripts/Windows/OS/Install.ps1 | 810 +++++++++++++++++---------------- 1 file changed, 408 insertions(+), 402 deletions(-) diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1 index 659e41a2..80371769 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -35,442 +35,448 @@ $null = New-Module { #> function Start-InstallationLoop { while (-not (Get-IsFinished)) { - if ($null -eq (Get-Stage)) { - Set-Stage ([SetupStage]::Initialize); - } elseif ((Get-Stage) -eq ([SetupStage]::Initialize)) { - if (-not ((Test-Command "choco") -and (Test-Command "refreshenv"))) { - Invoke-Hook "Install-Chocolatey" -Fallback { - # Install chocolatey - [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; - Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')); - Import-Module $env:ChocolateyInstall/helpers/chocolateyProfile.psm1; - refreshenv; - }; - - continue; + switch (Get-Stage) { + ($null) { + Set-Stage ([SetupStage]::Initialize); + break; } - - if (-not (Test-Command "gsudo")) { - Install-ChocoPackage gsudo; - refreshenv; - continue; - } - - if (-not (Test-Command "git")) { - Install-ChocoPackage git; - refreshenv; - continue; - } - - if (-not (Test-ChocoPackage "powershell-core")) { - Invoke-Hook "Install-PowerShellCore" -Fallback { - choco install -y powershell-core --install-arguments='"ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 REGISTER_MANIFEST=1 USER_MU=1 ENABLE_MU=1"'; - }; - - Restart-Intermediate; - return; - } - - if ($env:PWSH_PATH -and (Test-Path $env:PWSH_PATH)) { - attrib "-R" "$env:PWSH_PATH\*" /S /D; - Remove-Item -Recurse -Force $env:PWSH_PATH; - continue; - } - - if (-not (Test-Winget)) { - . "$PSScriptRoot/../Software/winget/Manage.ps1"; - continue; - } - - if (-not (& { $null = wsl --status; $?; })) { - wsl --install --no-launch; - Restart-Intermediate; - return; - } - - if (-not (& { $null = wsl -l; $?; })) { - ubuntu install --root; - continue; - } - - if (-not (wsl --shell-type login type -t nix)) { - wsl -- sh `<`(curl -L https://nixos.org/nix/install`) --daemon --yes; - wsl --shutdown; - continue; - } - - if (-not (Test-PSPackage Selenium.WebDriver)) { - Write-Host "Installing browser automation tools…"; - Install-Module -AcceptLicense -Force NuGet; - Import-Module NuGet; - $null = Install-Package -Force Selenium.WebDriver -RequiredVersion 4.10.0 -SkipDependencies; - continue; - } - - Install-ChocoPackage selenium-gecko-driver firefox; - - Invoke-Hook "Install-PSModules" -Fallback { - Install-Module -AcceptLicense -Force PSWindowsUpdate; - Install-Module -AcceptLicense -Force PSScriptAnalyzer; - . "$PSScriptRoot/../Software/PinnedItem/Manage.ps1"; - }; - - Set-Stage ([SetupStage]::Configure); - } else { - $null = Import-Module PSWindowsUpdate; - - Invoke-Hook "Invoke-WindowsUpdate" -Fallback { - Update-WindowsInstallation; - }; - - if ((Get-WURebootStatus -Silent)) { - Restart-Intermediate; - return; - } - - <# - .SYNOPSIS - Deploys an action for each software. - - .PARAMETER Action - The action to execute by default. - #> - function Deploy-SoftwareAction { - param( - [InstallerAction] $Action - ) - - [bool] $install = $null; - $arguments = [hashtable]@{ }; - - if ($Action) { - $install = ($Action -eq ([InstallerAction]::Install)); - $null = $arguments.Add("action", $Action); - } else { - $install = $true; + ([SetupStage]::Initialize) { + if (-not ((Test-Command "choco") -and (Test-Command "refreshenv"))) { + Invoke-Hook "Install-Chocolatey" -Fallback { + # Install chocolatey + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; + Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')); + Import-Module $env:ChocolateyInstall/helpers/chocolateyProfile.psm1; + refreshenv; + }; + + continue; } - # Drivers - $null = New-Module { - $driverPath = "$PSScriptRoot/../Drivers"; - $mbPath = "$driverPath/ROG Zenith Extreme Alpha"; + if (-not (Test-Command "gsudo")) { + Install-ChocoPackage gsudo; + refreshenv; + continue; + } + + if (-not (Test-Command "git")) { + Install-ChocoPackage git; + refreshenv; + continue; + } - foreach ($component in (Get-Config "valhalla.hardware.components")) { + if (-not (Test-ChocoPackage "powershell-core")) { + Invoke-Hook "Install-PowerShellCore" -Fallback { + choco install -y powershell-core --install-arguments='"ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 REGISTER_MANIFEST=1 USER_MU=1 ENABLE_MU=1"'; + }; + + Restart-Intermediate; + return; + } - switch ($component) { - ("ROG Zenith Extreme Alpha") { - . "$mbPath/MarvellEthernet/Manage.ps1" @arguments; - . "$mbPath/IntelWiFi/Manage.ps1" @arguments; - . "$mbPath/IntelBluetooth/Manage.ps1" @arguments; - . "$mbPath/AMDChipsetX399/Manage.ps1" @arguments; - . "$driverPath/AMDChipsetX399/Manage.ps1" @arguments; - } - ("Predator Z301C") { - . "$driverPath/Predator Z301C/Manage.ps1" @arguments; - } - } - } + if ($env:PWSH_PATH -and (Test-Path $env:PWSH_PATH)) { + attrib "-R" "$env:PWSH_PATH\*" /S /D; + Remove-Item -Recurse -Force $env:PWSH_PATH; + continue; + } + + if (-not (Test-Winget)) { + . "$PSScriptRoot/../Software/winget/Manage.ps1"; + continue; + } + + if (-not (& { $null = wsl --status; $?; })) { + wsl --install --no-launch; + Restart-Intermediate; + return; + } - if ($install) { - if (Get-Config "valhalla.hardware.amdCPU") { - Install-ChocoPackage amd-ryzen-master; - # ToDo: backup Ryzen energy saving plan - } + if (-not (& { $null = wsl -l; $?; })) { + ubuntu install --root; + continue; + } - if (Get-Config "valhalla.hardware.nvidiaGPU") { - Install-ChocoPackage geforce-game-ready-driver; - Remove-DesktopIcon "*Geforce*"; - } + if (-not (wsl --shell-type login type -t nix)) { + wsl -- sh `<`(curl -L https://nixos.org/nix/install`) --daemon --yes; + wsl --shutdown; + continue; + } - if (Get-Config "valhalla.hardware.corsairDevice") { - Install-ChocoPackage icue; - } + if (-not (Test-PSPackage Selenium.WebDriver)) { + Write-Host "Installing browser automation tools…"; + Install-Module -AcceptLicense -Force NuGet; + Import-Module NuGet; + $null = Install-Package -Force Selenium.WebDriver -RequiredVersion 4.10.0 -SkipDependencies; + continue; + } - if (Get-Config "valhalla.hardware.elgatoWave") { - if (-not (Test-ChocoPackage wavelink)) { - Install-ChocoPackage wavelink -ArgumentList '--install-arguments="/norestart"'; - Remove-DesktopIcon "*Wave Link*"; - Restart-Intermediate; - exit; - } - } - } - - if (Get-Config "valhalla.hardware.eyeX") { - . "$driverPath/Tobii EyeX/Manage.ps1" @arguments; - } + Install-ChocoPackage selenium-gecko-driver firefox; + + Invoke-Hook "Install-PSModules" -Fallback { + Install-Module -AcceptLicense -Force PSWindowsUpdate; + Install-Module -AcceptLicense -Force PSScriptAnalyzer; + . "$PSScriptRoot/../Software/PinnedItem/Manage.ps1"; }; - $null = New-Module { - # Windows Config - $softwarePath = "$PSScriptRoot/../Software"; - $commonSoftware = "$PSScriptRoot/../../Common/Software"; - . "$softwarePath/Windows/Manage.ps1" @arguments; + Set-Stage ([SetupStage]::Configure); + break; + } + default { + $null = Import-Module PSWindowsUpdate; + + Invoke-Hook "Invoke-WindowsUpdate" -Fallback { + Update-WindowsInstallation; + }; + + if ((Get-WURebootStatus -Silent)) { + Restart-Intermediate; + return; + } - if (Get-Config "valhalla.hardware.logitechG") { - . "$softwarePath/LGHub/Manage.ps1" @arguments; + <# + .SYNOPSIS + Deploys an action for each software. + + .PARAMETER Action + The action to execute by default. + #> + function Deploy-SoftwareAction { + param( + [InstallerAction] $Action + ) + + [bool] $install = $null; + $arguments = [hashtable]@{ }; + + if ($Action) { + $install = ($Action -eq ([InstallerAction]::Install)); + $null = $arguments.Add("action", $Action); + } else { + $install = $true; } - if (Test-Collection "essential") { - # Essentials - . "$softwarePath/OpenSSH/Manage.ps1" @arguments; - . "$softwarePath/PowerShell/Manage.ps1" @arguments; - . "$softwarePath/chocolatey/Manage.ps1" @arguments; - . "$softwarePath/zoxide/Manage.ps1" @arguments; - . "$commonSoftware/posh-git/Manage.ps1" @arguments; - . "$commonSoftware/Terminal-Icons/Manage.ps1" @arguments; - . "$commonSoftware/Oh My Posh/Manage.ps1" @arguments; - - if ($install) { - Install-ChocoPackage ` - procexp ` - procmon ` - ; - - Install-WingetPackage ` - KDE.KDEConnect ` - ; - } - } + # Drivers + $null = New-Module { + $driverPath = "$PSScriptRoot/../Drivers"; + $mbPath = "$driverPath/ROG Zenith Extreme Alpha"; - if (Test-Collection "common") { - # Common Software - . "$softwarePath/WinSCP/Manage.ps1" @arguments; - . "$softwarePath/Thunderbird/Manage.ps1" @arguments; - . "$softwarePath/PuTTY/Manage.ps1" @arguments; - - if ($install) { - Install-ChocoPackage ` - 7zip ` - chocolateygui ` - DefaultProgramsEditor ` - bitwarden ` - keepass ` - ; - - Install-WingetPackage ` - SomePythonThings.WingetUIStore ` - ; + foreach ($component in (Get-Config "valhalla.hardware.components")) { + + switch ($component) { + ("ROG Zenith Extreme Alpha") { + . "$mbPath/MarvellEthernet/Manage.ps1" @arguments; + . "$mbPath/IntelWiFi/Manage.ps1" @arguments; + . "$mbPath/IntelBluetooth/Manage.ps1" @arguments; + . "$mbPath/AMDChipsetX399/Manage.ps1" @arguments; + . "$driverPath/AMDChipsetX399/Manage.ps1" @arguments; + } + ("Predator Z301C") { + . "$driverPath/Predator Z301C/Manage.ps1" @arguments; + } + } } - } - if (Test-Collection "desktopExperience") { if ($install) { - # Fonts - Install-ChocoPackage nerd-fonts-CascadiaCode; + if (Get-Config "valhalla.hardware.amdCPU") { + Install-ChocoPackage amd-ryzen-master; + # ToDo: backup Ryzen energy saving plan + } + + if (Get-Config "valhalla.hardware.nvidiaGPU") { + Install-ChocoPackage geforce-game-ready-driver; + Remove-DesktopIcon "*Geforce*"; + } + + if (Get-Config "valhalla.hardware.corsairDevice") { + Install-ChocoPackage icue; + } + + if (Get-Config "valhalla.hardware.elgatoWave") { + if (-not (Test-ChocoPackage wavelink)) { + Install-ChocoPackage wavelink -ArgumentList '--install-arguments="/norestart"'; + Remove-DesktopIcon "*Wave Link*"; + Restart-Intermediate; + exit; + } + } + } + + if (Get-Config "valhalla.hardware.eyeX") { + . "$driverPath/Tobii EyeX/Manage.ps1" @arguments; + } + }; + + $null = New-Module { + # Windows Config + $softwarePath = "$PSScriptRoot/../Software"; + $commonSoftware = "$PSScriptRoot/../../Common/Software"; + . "$softwarePath/Windows/Manage.ps1" @arguments; + + if (Get-Config "valhalla.hardware.logitechG") { + . "$softwarePath/LGHub/Manage.ps1" @arguments; + } + + if (Test-Collection "essential") { + # Essentials + . "$softwarePath/OpenSSH/Manage.ps1" @arguments; + . "$softwarePath/PowerShell/Manage.ps1" @arguments; + . "$softwarePath/chocolatey/Manage.ps1" @arguments; + . "$softwarePath/zoxide/Manage.ps1" @arguments; + . "$commonSoftware/posh-git/Manage.ps1" @arguments; + . "$commonSoftware/Terminal-Icons/Manage.ps1" @arguments; + . "$commonSoftware/Oh My Posh/Manage.ps1" @arguments; + + if ($install) { + Install-ChocoPackage ` + procexp ` + procmon ` + ; + + Install-WingetPackage ` + KDE.KDEConnect ` + ; + } + } + + if (Test-Collection "common") { + # Common Software + . "$softwarePath/WinSCP/Manage.ps1" @arguments; + . "$softwarePath/Thunderbird/Manage.ps1" @arguments; + . "$softwarePath/PuTTY/Manage.ps1" @arguments; + + if ($install) { + Install-ChocoPackage ` + 7zip ` + chocolateygui ` + DefaultProgramsEditor ` + bitwarden ` + keepass ` + ; + + Install-WingetPackage ` + SomePythonThings.WingetUIStore ` + ; + } + } + + if (Test-Collection "desktopExperience") { + if ($install) { + # Fonts + Install-ChocoPackage nerd-fonts-CascadiaCode; + + # Internet Access + Install-WingetPackage Brave.Brave kamranahmedse.pennywise; + Remove-DesktopIcon "*Brave*"; + Remove-TaskbarItem "*Brave*"; + Remove-DesktopIcon "Pennywise*"; + + # Tools + Install-SetupPackage -Source "https://github.com/mRemoteNG/mRemoteNG/releases/download/2023.03.03-v1.77.3-nb/mRemoteNG-Installer-1.77.3.nb-1784.msi" -ArgumentList "/Quiet"; + Remove-DesktopIcon "mRemoteNG*"; + + Install-ChocoPackage ` + gimp ` + gpu-z ` + windirstat ` + winmerge ` + handbrake ` + hwmonitor ` + qbittorrent ` + imgburn ` + inkscape ` + krita ` + MetaX ` + obs-studio ` + ; + + Remove-DesktopIcon "GPU-Z*"; + Remove-DesktopIcon "WinDirStat*"; + Remove-DesktopIcon "*HWMonitor*"; + Remove-DesktopIcon "ImgBurn*"; + Remove-DesktopIcon "InkScape*"; + Remove-DesktopIcon "Krita*"; + Remove-DesktopIcon "MetaX*"; + Remove-DesktopIcon "OBS Studio*"; + + Install-WingetPackage ` + AntSoftware.AntRenamer ` + AppWork.JDownloader; + + Remove-DesktopIcon "JDownloader*"; + } + + # ToDo: Consider hiding behind own config? + . "$softwarePath/Ubiquiti UniFi Controller/Manage.ps1" @arguments; # Internet Access - Install-WingetPackage Brave.Brave kamranahmedse.pennywise; - Remove-DesktopIcon "*Brave*"; - Remove-TaskbarItem "*Brave*"; - Remove-DesktopIcon "Pennywise*"; + . "$softwarePath/Firefox/Manage.ps1" @arguments; + . "$softwarePath/MSEdgeRedirect/Manage.ps1" @arguments; - # Tools - Install-SetupPackage -Source "https://github.com/mRemoteNG/mRemoteNG/releases/download/2023.03.03-v1.77.3-nb/mRemoteNG-Installer-1.77.3.nb-1784.msi" -ArgumentList "/Quiet"; - Remove-DesktopIcon "mRemoteNG*"; - - Install-ChocoPackage ` - gimp ` - gpu-z ` - windirstat ` - winmerge ` - handbrake ` - hwmonitor ` - qbittorrent ` - imgburn ` - inkscape ` - krita ` - MetaX ` - obs-studio ` - ; - - Remove-DesktopIcon "GPU-Z*"; - Remove-DesktopIcon "WinDirStat*"; - Remove-DesktopIcon "*HWMonitor*"; - Remove-DesktopIcon "ImgBurn*"; - Remove-DesktopIcon "InkScape*"; - Remove-DesktopIcon "Krita*"; - Remove-DesktopIcon "MetaX*"; - Remove-DesktopIcon "OBS Studio*"; - - Install-WingetPackage ` - AntSoftware.AntRenamer ` - AppWork.JDownloader; - - Remove-DesktopIcon "JDownloader*"; + if (Test-Collection "fileSync") { + . "$softwarePath/Nextcloud/Manage.ps1" @arguments; + } } - # ToDo: Consider hiding behind own config? - . "$softwarePath/Ubiquiti UniFi Controller/Manage.ps1" @arguments; + if (Test-Collection "socialMedia") { + if ($install) { + Install-ChocoPackage ` + signal ` + threema-desktop ` + element-desktop ` + teamspeak ` + ; - # Internet Access - . "$softwarePath/Firefox/Manage.ps1" @arguments; - . "$softwarePath/MSEdgeRedirect/Manage.ps1" @arguments; - - if (Test-Collection "fileSync") { - . "$softwarePath/Nextcloud/Manage.ps1" @arguments; - } - } - - if (Test-Collection "socialMedia") { - if ($install) { - Install-ChocoPackage ` - signal ` - threema-desktop ` - element-desktop ` - teamspeak ` - ; - - Remove-DesktopIcon "*Element*"; - Remove-DesktopIcon "*TeamSpeak*"; - - Install-WingetPackage Discord.Discord; - Remove-DesktopIcon "*Discord*"; - } - } - - if (Test-Collection "media") { - if ($install) { - Install-ChocoPackage ` - k-litecodecpackmega ` - jellyfin-media-player ` - vlc ` - ; - - Remove-DesktopIcon "VLC*"; - Install-WingetPackage Ytmdesktop.Ytmdesktop; - Remove-DesktopIcon "Youtube Music*"; - } - } - - if (Test-Collection "coding") { - if ($install) { - Install-ChocoPackage vscode -ArgumentList "--params","/NoDesktopIcon"; - Install-ChocoPackage vscodium -ArgumentList "--params","/NoDesktopIcon /AssociateWithFiles"; - - Install-ChocoPackage ` - gh ` - github-desktop ` - ida-free ` - HxD ` - docker-desktop ` - imhex ` - dotpeek ` - ; - - Remove-DesktopIcon "IDA *"; - Remove-DesktopIcon "GitHub*"; - Remove-DesktopIcon "Docker*"; + Remove-DesktopIcon "*Element*"; + Remove-DesktopIcon "*TeamSpeak*"; + + Install-WingetPackage Discord.Discord; + Remove-DesktopIcon "*Discord*"; + } } - . "$softwarePath/VisualStudio/Manage.ps1" @arguments; + if (Test-Collection "media") { + if ($install) { + Install-ChocoPackage ` + k-litecodecpackmega ` + jellyfin-media-player ` + vlc ` + ; - # Node.js - . "$softwarePath/NVS/Manage.ps1" @arguments; - } - - if (Test-Collection "gaming") { - # Gaming - if ($install) { - Install-ChocoPackage ` - goggalaxy ` - epicgameslauncher ` - steam ` - rayman-controlpanel ` - ppsspp ` - ; - - Remove-DesktopIcon "*Epic Games*"; - Remove-DesktopIcon "*Steam*"; - Remove-DesktopIcon "*PPSSPP *-Bit*"; - - Install-ChocoPackage ubisoft-connect -ArgumentList "--ignore-checksums"; - Remove-DesktopIcon "*Ubisoft Connect*"; - - Install-WingetPackage ElectronicArts.EADesktop; - Remove-DesktopIcon "EA.*"; + Remove-DesktopIcon "VLC*"; + Install-WingetPackage Ytmdesktop.Ytmdesktop; + Remove-DesktopIcon "Youtube Music*"; + } } - . "$softwarePath/TrackMania Nations Forever/Manage.ps1" @arguments; - . "$softwarePath/TrackMania United Forever/Manage.ps1" @arguments; - . "$softwarePath/ManiaPlanet/Manage.ps1" @arguments; - . "$softwarePath/osu!/Manage.ps1" @arguments; - . "$softwarePath/osu!lazer/Manage.ps1" @arguments; - . "$softwarePath/RetroArch/Manage.ps1" @arguments; - . "$softwarePath/reWASD/Manage.ps1" @arguments; - } - }; - } - - switch (Get-Stage) { - ([SetupStage]::Configure) { - if (Get-Config "valhalla.windows.dualboot.enable") { - # Fix synchronization between Linux and Windows clocks. - Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\TimeZoneInformation" -Name "RealTimeIsUniversal" -Value 1 -Type "DWord"; - - # Force time resynchronization - $service = Get-Service W32Time; - $stopped = ($service.Status -eq "Stopped"); - Start-Service $service; - w32tm /resync /force; - - if ($stopped) { - Stop-Service $service; - } - } + if (Test-Collection "coding") { + if ($install) { + Install-ChocoPackage vscode -ArgumentList "--params","/NoDesktopIcon"; + Install-ChocoPackage vscodium -ArgumentList "--params","/NoDesktopIcon /AssociateWithFiles"; - Set-Stage ([SetupStage]::Install); - } - ([SetupStage]::Install) { - Write-Host "Entering install phase"; - Deploy-SoftwareAction; - Set-Stage ([SetupStage]::CreateUser); - } - ([SetupStage]::CreateUser) { - Start-ValhallaUserSetup; - Set-Stage ([SetupStage]::ConfigureUser); - } - ([SetupStage]::ConfigureUser) { - $userOption = "CurrentUser"; + Install-ChocoPackage ` + gh ` + github-desktop ` + ida-free ` + HxD ` + docker-desktop ` + imhex ` + dotpeek ` + ; - function Get-CurrentUser { - (Get-SetupOption $userOption) ?? 0; - } - - function Set-CurrentUser { - param([int] $Value) - Set-SetupOption $userOption $Value; - } - - [string[]] $users = Get-Users; - $currentUser = Get-CurrentUser; - Set-BootMessage; - - if ($currentUser -lt $users.Count) { - $user = Get-LocalUser $users[$currentUser]; - - Add-LocalGroupMember ` - -SID ([SecurityIdentifier]::new([WellKnownSidType]::BuiltinAdministratorsSid, $null))` - $user ` - -ErrorAction SilentlyContinue; - - if ($env:UserName -ne "$user") { - Disable-LocalUser $env:UserName; - Enable-LocalUser $user; - - if (Get-UserConfig -UserName "$user" -Name "microsoftAccount") { - Disable-Autologin; - Set-BootMessage -Caption "Login" -Message "Please login using your account."; - } else { - Set-AutologinUser "$user"; + Remove-DesktopIcon "IDA *"; + Remove-DesktopIcon "GitHub*"; + Remove-DesktopIcon "Docker*"; } - Restart-Intermediate - return; - } - } + . "$softwarePath/VisualStudio/Manage.ps1" @arguments; - Set-IsFinished $true; + # Node.js + . "$softwarePath/NVS/Manage.ps1" @arguments; + } + + if (Test-Collection "gaming") { + # Gaming + if ($install) { + Install-ChocoPackage ` + goggalaxy ` + epicgameslauncher ` + steam ` + rayman-controlpanel ` + ppsspp ` + ; + + Remove-DesktopIcon "*Epic Games*"; + Remove-DesktopIcon "*Steam*"; + Remove-DesktopIcon "*PPSSPP *-Bit*"; + + Install-ChocoPackage ubisoft-connect -ArgumentList "--ignore-checksums"; + Remove-DesktopIcon "*Ubisoft Connect*"; + + Install-WingetPackage ElectronicArts.EADesktop; + Remove-DesktopIcon "EA.*"; + } + + . "$softwarePath/TrackMania Nations Forever/Manage.ps1" @arguments; + . "$softwarePath/TrackMania United Forever/Manage.ps1" @arguments; + . "$softwarePath/ManiaPlanet/Manage.ps1" @arguments; + . "$softwarePath/osu!/Manage.ps1" @arguments; + . "$softwarePath/osu!lazer/Manage.ps1" @arguments; + . "$softwarePath/RetroArch/Manage.ps1" @arguments; + . "$softwarePath/reWASD/Manage.ps1" @arguments; + } + }; + } + + switch (Get-Stage) { + ([SetupStage]::Configure) { + if (Get-Config "valhalla.windows.dualboot.enable") { + # Fix synchronization between Linux and Windows clocks. + Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\TimeZoneInformation" -Name "RealTimeIsUniversal" -Value 1 -Type "DWord"; + + # Force time resynchronization + $service = Get-Service W32Time; + $stopped = ($service.Status -eq "Stopped"); + Start-Service $service; + w32tm /resync /force; + + if ($stopped) { + Stop-Service $service; + } + } + + Set-Stage ([SetupStage]::Install); + } + ([SetupStage]::Install) { + Write-Host "Entering install phase"; + Deploy-SoftwareAction; + Set-Stage ([SetupStage]::CreateUser); + } + ([SetupStage]::CreateUser) { + Start-ValhallaUserSetup; + Set-Stage ([SetupStage]::ConfigureUser); + } + ([SetupStage]::ConfigureUser) { + $userOption = "CurrentUser"; + + function Get-CurrentUser { + (Get-SetupOption $userOption) ?? 0; + } + + function Set-CurrentUser { + param([int] $Value) + Set-SetupOption $userOption $Value; + } + + [string[]] $users = Get-Users; + $currentUser = Get-CurrentUser; + Set-BootMessage; + + if ($currentUser -lt $users.Count) { + $user = Get-LocalUser $users[$currentUser]; + + Add-LocalGroupMember ` + -SID ([SecurityIdentifier]::new([WellKnownSidType]::BuiltinAdministratorsSid, $null))` + $user ` + -ErrorAction SilentlyContinue; + + if ($env:UserName -ne "$user") { + Disable-LocalUser $env:UserName; + Enable-LocalUser $user; + + if (Get-UserConfig -UserName "$user" -Name "microsoftAccount") { + Disable-Autologin; + Set-BootMessage -Caption "Login" -Message "Please login using your account."; + } else { + Set-AutologinUser "$user"; + } + + Restart-Intermediate + return; + } + } + + Set-IsFinished $true; + } } } }