2023-07-12 20:37:31 +00:00
|
|
|
#!/bin/pwsh
|
2024-03-23 16:53:43 +00:00
|
|
|
. "$PSScriptRoot/../Scripts/Prerequisites.ps1";
|
|
|
|
|
2023-06-16 18:24:22 +00:00
|
|
|
. "$PSScriptRoot/Manage.ps1";
|
2024-03-23 14:38:06 +00:00
|
|
|
. "$PSScriptRoot/User/Install.ps1";
|
2023-06-22 15:53:12 +00:00
|
|
|
. "$PSScriptRoot/../Scripts/Context.ps1";
|
2023-07-16 10:39:07 +00:00
|
|
|
. "$PSScriptRoot/../Software/Firefox/Install.ps1";
|
2023-06-16 18:24:22 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
$null = New-Module {
|
2024-08-01 19:32:33 +00:00
|
|
|
. "$PSScriptRoot/../Scripts/Config.ps1";
|
2024-08-01 19:49:46 +00:00
|
|
|
. "$PSScriptRoot/../Scripts/Hooks.ps1";
|
2024-08-06 09:39:57 +00:00
|
|
|
. "$PSScriptRoot/../Scripts/Operations.ps1";
|
2024-08-01 19:49:46 +00:00
|
|
|
. "$PSScriptRoot/../Scripts/PowerManagement.ps1";
|
2024-08-07 11:36:31 +00:00
|
|
|
. "$PSScriptRoot/../Scripts/Software.ps1";
|
2024-08-01 19:49:46 +00:00
|
|
|
. "$PSScriptRoot/../Scripts/SoftwareManagement.ps1";
|
|
|
|
. "$PSScriptRoot/../Scripts/Update.ps1";
|
2024-08-06 14:54:11 +00:00
|
|
|
. "$PSScriptRoot/../Types/InstallerAction.ps1";
|
2024-08-01 19:32:33 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Finishes the installation of a running Windows machine.
|
|
|
|
#>
|
|
|
|
function Start-WindowsInstallation {
|
2024-08-05 21:09:58 +00:00
|
|
|
Start-Operation {
|
|
|
|
Start-InstallationLoop;
|
|
|
|
};
|
2024-08-01 17:02:12 +00:00
|
|
|
}
|
2024-07-31 14:15:09 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Starts the installation loop.
|
|
|
|
#>
|
|
|
|
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;
|
|
|
|
}
|
2024-07-31 14:15:09 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
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"';
|
|
|
|
};
|
2024-08-01 00:59:32 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
Restart-Intermediate;
|
|
|
|
return;
|
|
|
|
}
|
2024-08-01 12:06:40 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
if (Test-Path $env:PWSH_PATH) {
|
|
|
|
attrib "-R" "$env:PWSH_PATH\*" /S /D;
|
|
|
|
Remove-Item -Recurse -Force $env:PWSH_PATH;
|
|
|
|
continue;
|
|
|
|
}
|
2024-08-01 14:28:48 +00:00
|
|
|
|
2024-08-06 16:19:33 +00:00
|
|
|
Invoke-Hook "Install-PSModules" -Fallback {
|
|
|
|
Install-Module -AcceptLicense -Force PSWindowsUpdate;
|
|
|
|
};
|
|
|
|
|
2024-08-07 01:34:12 +00:00
|
|
|
if (-not (Test-Winget)) {
|
2024-08-01 17:02:12 +00:00
|
|
|
. "$PSScriptRoot/../Software/winget/Manage.ps1";
|
|
|
|
continue;
|
|
|
|
}
|
2024-08-01 00:59:32 +00:00
|
|
|
|
2024-08-07 11:36:31 +00:00
|
|
|
if (-not (Test-PSPackage Selenium.WebDriver)) {
|
|
|
|
Install-Module -AcceptLicense -Force NuGet;
|
|
|
|
Import-Module NuGet;
|
|
|
|
$null = Install-Package -Force Selenium.WebDriver -RequiredVersion 4.10.0 -SkipDependencies;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-08-07 13:24:56 +00:00
|
|
|
Install-ChocoPackage selenium-gecko-driver firefox;
|
2024-08-07 11:36:31 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
if (-not (& { wsl --status; $?; })) {
|
|
|
|
wsl --install --no-launch;
|
|
|
|
Restart-Intermediate;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
ubuntu install --root;
|
|
|
|
wsl -- sh `<`(curl -L https://nixos.org/nix/install`) --daemon --yes;
|
|
|
|
wsl --shutdown;
|
|
|
|
}
|
2024-08-01 00:59:32 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
if (wsl --shell-type login type -t nix) {
|
|
|
|
Set-Stage ([SetupStage]::Configure);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$null = Import-Module PSWindowsUpdate;
|
2024-08-01 00:59:32 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
Invoke-Hook "Invoke-WindowsUpdate" -Fallback {
|
|
|
|
Update-WindowsInstallation;
|
|
|
|
};
|
2024-08-01 14:32:03 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
if ((Get-WURebootStatus -Silent)) {
|
|
|
|
Restart-Intermediate;
|
|
|
|
return;
|
|
|
|
}
|
2024-08-01 14:32:03 +00:00
|
|
|
|
2024-08-06 14:54:11 +00:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Deploys an action for each software.
|
|
|
|
|
|
|
|
.PARAMETER Action
|
|
|
|
The action to execute by default.
|
|
|
|
#>
|
|
|
|
function Deploy-SoftwareAction {
|
|
|
|
param(
|
|
|
|
[InstallerAction] $Action
|
|
|
|
)
|
|
|
|
|
|
|
|
$arguments = [hashtable]@{ };
|
|
|
|
|
|
|
|
if ($Action) {
|
|
|
|
$arguments.Add("action", $Action);
|
|
|
|
}
|
|
|
|
|
2024-08-07 14:17:49 +00:00
|
|
|
# Drivers
|
|
|
|
$null = New-Module {
|
|
|
|
$driverPath = "$PSScriptRoot/../Drivers";
|
|
|
|
$mbPath = "$driverPath/ROG Zenith Extreme Alpha";
|
|
|
|
|
|
|
|
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 (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.corsairLighting") {
|
|
|
|
Install-ChocoPackage icue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Get-Config "valhalla.hardware.elgatoWave") {
|
|
|
|
Install-ChocoPackage wavelink;
|
|
|
|
Remove-DesktopIcon "*Wave Link*";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Get-Config "valhalla.hardware.eyeX") {
|
|
|
|
. "$driverPath/Tobii EyeX/Manage.ps1" @arguments;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-08-06 14:54:11 +00:00
|
|
|
# Windows Config
|
|
|
|
. "$PSScriptRoot/../Software/Windows/Manage.ps1" @arguments;
|
|
|
|
|
|
|
|
if (Test-Collection "essential") {
|
|
|
|
# Essentials
|
|
|
|
. "$PSScriptRoot/../Software/OpenSSH/Manage.ps1" @arguments;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
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;
|
|
|
|
}
|
2024-08-01 14:32:03 +00:00
|
|
|
}
|
2024-08-01 23:44:56 +00:00
|
|
|
|
|
|
|
Set-Stage ([SetupStage]::Install);
|
2024-08-01 14:32:03 +00:00
|
|
|
}
|
2024-08-01 17:02:12 +00:00
|
|
|
([SetupStage]::Install) {
|
|
|
|
Write-Host "Entering install phase";
|
2024-08-06 14:54:11 +00:00
|
|
|
Deploy-SoftwareAction;
|
2024-08-01 17:02:12 +00:00
|
|
|
Set-IsFinished $true;
|
|
|
|
}
|
2024-08-01 14:32:03 +00:00
|
|
|
}
|
2024-07-31 14:09:50 +00:00
|
|
|
}
|
2024-07-31 13:52:41 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-23 14:09:58 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
function Invoke-WindowsInstallation([Context] $context) {
|
|
|
|
$Global:InformationPreference = "Continue";
|
|
|
|
$Global:ErrorActionPreference = "Inquire";
|
|
|
|
$context.UserNames ??= @("Manuel");
|
|
|
|
Start-OldWindowsInstallationScript $context;
|
|
|
|
}
|
2024-03-23 14:09:58 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
function Start-OldWindowsInstallationScript([Context] $context) {
|
|
|
|
. "$PSScriptRoot/Upgrade.ps1";
|
|
|
|
$finished = $false;
|
|
|
|
Remove-Item Env:\POSH_THEME -ErrorAction SilentlyContinue;
|
|
|
|
$configPath = "$PSScriptRoot/../Config";
|
|
|
|
$softwarePath = "$PSScriptRoot/../Software";
|
|
|
|
$initialConfigStage = "InitialConfiguration";
|
|
|
|
$prerequisitesStage = "InstallationPrerequisites";
|
|
|
|
$driverStage = "DriverInstallation";
|
|
|
|
$softwareStage = "MachineWideSoftwareInstallation";
|
|
|
|
$userStage = "CreatingUser";
|
|
|
|
$restorationStage = "Restoring";
|
|
|
|
|
|
|
|
|
|
|
|
while (-not $finished) {
|
|
|
|
switch ($context.GetStage()) {
|
|
|
|
{ (-not $_) -or ($_ -eq $initialConfigStage) } {
|
|
|
|
$context.SetStage($initialConfigStage);
|
|
|
|
|
|
|
|
if ((Get-Command Initialize-Configuration -ErrorAction SilentlyContinue)) {
|
|
|
|
Write-Information "Configuration initialization function was found. Running...";
|
|
|
|
Initialize-Configuration $context;
|
|
|
|
}
|
2024-03-23 14:09:58 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
$null = Enable-WindowsOptionalFeature -Online -All -FeatureName "NetFx3";
|
|
|
|
|
|
|
|
. "$configPath/Windows/Install.ps1" $context;
|
|
|
|
. "$configPath/Explorer/Install.ps1" $context;
|
|
|
|
. "$configPath/OpenSSH/Install.ps1" $context;
|
|
|
|
. "$configPath/chocolatey/Install.ps1";
|
2024-03-23 14:09:58 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
$context.RemoveDesktopIcon("*Microsoft Edge*");
|
|
|
|
$context.SetStage($prerequisitesStage);
|
|
|
|
break;
|
2024-03-23 14:09:58 +00:00
|
|
|
}
|
2024-08-01 17:02:12 +00:00
|
|
|
# Always install updates
|
|
|
|
default {
|
|
|
|
Write-Host "Starting Installation and Restoration of Windows";
|
|
|
|
Update-WindowsInstallation $context;
|
|
|
|
}
|
|
|
|
$prerequisitesStage {
|
|
|
|
Write-Host "Installing prerequisites for installing software";
|
2024-03-23 14:09:58 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
if (-not $(Get-Command winget)) {
|
|
|
|
choco install -y winget;
|
|
|
|
}
|
2024-03-23 14:09:58 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
Install-Module -AcceptLicense -Force "NuGet";
|
|
|
|
Import-Module NuGet;
|
2024-03-23 14:09:58 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
Install-Firefox $context;
|
|
|
|
choco install -y selenium-gecko-driver;
|
|
|
|
$null = Install-Package -Force Selenium.WebDriver -RequiredVersion 4.10.0 -SkipDependencies;
|
2024-03-23 14:09:58 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
winget install --accept-source-agreements --accept-package-agreements -e --id AutoHotkey.AutoHotkey;
|
2024-03-23 14:09:58 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
$context.SetStage($driverStage);
|
|
|
|
break;
|
2024-03-23 14:09:58 +00:00
|
|
|
}
|
2024-08-01 17:02:12 +00:00
|
|
|
$driverStage {
|
|
|
|
Write-Host "Installing drivers";
|
2024-03-23 14:09:58 +00:00
|
|
|
|
2024-08-01 17:02:12 +00:00
|
|
|
if ((Get-Command Install-PortValhallaDrivers -ErrorAction SilentlyContinue)) {
|
|
|
|
Write-Information "Driver installation function was found. Starting installation";
|
|
|
|
Install-PortValhallaDrivers $context;
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Information "Finished installing drivers";
|
|
|
|
$context.SetStage($softwareStage);
|
|
|
|
$context.Reboot();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
$softwareStage {
|
|
|
|
Write-Host "Setting up software with default app associations";
|
|
|
|
. "$softwarePath/WinSCP/Install.ps1" $context;
|
|
|
|
. "$softwarePath/Thunderbird/Install.ps1" $context;
|
|
|
|
|
|
|
|
Write-Host "Installing default settings for new users";
|
|
|
|
. "$softwarePath/aliae/Install.ps1" $context;
|
|
|
|
. "$softwarePath/posh-git/Install.ps1";
|
|
|
|
. "$softwarePath/Terminal-Icons/Install.ps1";
|
|
|
|
. "$softwarePath/Oh My Posh/Install.ps1" $context;
|
|
|
|
$context.SetStage($userStage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$userStage {
|
|
|
|
Install-PersonalUsers $context;
|
|
|
|
$context.SetStage($restorationStage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$restorationStage {
|
|
|
|
Restore-WindowsInstallation $context;
|
|
|
|
$finished = $true;
|
|
|
|
break;
|
|
|
|
}
|
2024-03-23 14:09:58 +00:00
|
|
|
}
|
2023-08-13 23:32:57 +00:00
|
|
|
}
|
2023-07-16 10:56:54 +00:00
|
|
|
}
|
2024-08-01 17:02:12 +00:00
|
|
|
};
|