Compare commits
5 commits
2d58aece66
...
85dc2a8c48
Author | SHA1 | Date | |
---|---|---|---|
Manuel Thalmann | 85dc2a8c48 | ||
Manuel Thalmann | e5a3bdd0b8 | ||
Manuel Thalmann | b62adc9f9a | ||
Manuel Thalmann | ea6f8d3dfe | ||
Manuel Thalmann | e52a389b0b |
|
@ -1,6 +1,5 @@
|
|||
#!/bin/pwsh
|
||||
. "$PSScriptRoot/../../../scripts/Windows/Scripts/Prerequisites.ps1";
|
||||
. "$PSScriptRoot/../Scripts/Choco.ps1";
|
||||
. "$PSScriptRoot/../Scripts/Config.ps1";
|
||||
. "$PSScriptRoot/../Scripts/Hooks.ps1";
|
||||
. "$PSScriptRoot/../Scripts/PowerManagement.ps1";
|
||||
|
@ -11,213 +10,216 @@
|
|||
. "$PSScriptRoot/Manage.ps1";
|
||||
. "$PSScriptRoot/User/Install.ps1";
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Finishes the installation of a running Windows machine.
|
||||
#>
|
||||
function Start-WindowsInstallation {
|
||||
Start-InstallationLoop;
|
||||
}
|
||||
|
||||
<#
|
||||
.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;
|
||||
$null = New-Module {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Finishes the installation of a running Windows machine.
|
||||
#>
|
||||
function Start-WindowsInstallation {
|
||||
$ErrorActionPreference = 'Inquire';
|
||||
Start-InstallationLoop;
|
||||
}
|
||||
|
||||
<#
|
||||
.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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Invoke-Hook "Install-PSModules" -Fallback {
|
||||
Install-Module -AcceptLicense -Force PSWindowsUpdate;
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Invoke-Hook "Install-PSModules" -Fallback {
|
||||
Install-Module -AcceptLicense -Force PSWindowsUpdate;
|
||||
};
|
||||
|
||||
if (Test-Path $env:PWSH_PATH) {
|
||||
attrib "-R" "$env:PWSH_PATH\*" /S /D;
|
||||
Remove-Item -Recurse -Force $env:PWSH_PATH;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (-not (Test-Command winget)) {
|
||||
. "$PSScriptRoot/../Software/winget/Manage.ps1";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (-not (& { wsl --status; $?; })) {
|
||||
wsl --install --no-launch;
|
||||
Restart-Intermediate;
|
||||
return;
|
||||
|
||||
if (Test-Path $env:PWSH_PATH) {
|
||||
attrib "-R" "$env:PWSH_PATH\*" /S /D;
|
||||
Remove-Item -Recurse -Force $env:PWSH_PATH;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (-not (Test-Command winget)) {
|
||||
. "$PSScriptRoot/../Software/winget/Manage.ps1";
|
||||
continue;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (wsl --shell-type login type -t nix) {
|
||||
Set-Stage ([SetupStage]::Configure);
|
||||
}
|
||||
} else {
|
||||
ubuntu install --root;
|
||||
wsl -- sh `<`(curl -L https://nixos.org/nix/install`) --daemon --yes;
|
||||
wsl --shutdown;
|
||||
}
|
||||
|
||||
if (wsl --shell-type login type -t nix) {
|
||||
Set-Stage ([SetupStage]::Configure);
|
||||
}
|
||||
} else {
|
||||
$null = Import-Module PSWindowsUpdate;
|
||||
|
||||
Invoke-Hook "Invoke-WindowsUpdate" -Fallback {
|
||||
Update-WindowsInstallation;
|
||||
};
|
||||
|
||||
if ((Get-WURebootStatus -Silent)) {
|
||||
Restart-Intermediate;
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
$null = Import-Module PSWindowsUpdate;
|
||||
|
||||
Invoke-Hook "Invoke-WindowsUpdate" -Fallback {
|
||||
Update-WindowsInstallation;
|
||||
};
|
||||
|
||||
if ((Get-WURebootStatus -Silent)) {
|
||||
Restart-Intermediate;
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
([SetupStage]::Install) {
|
||||
Write-Host "Entering install phase";
|
||||
Set-IsFinished $true;
|
||||
}
|
||||
Default {}
|
||||
}
|
||||
([SetupStage]::Install) {
|
||||
Write-Host "Entering install phase";
|
||||
Set-IsFinished $true;
|
||||
}
|
||||
Default {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-WindowsInstallation([Context] $context) {
|
||||
$Global:InformationPreference = "Continue";
|
||||
$Global:ErrorActionPreference = "Inquire";
|
||||
$context.UserNames ??= @("Manuel");
|
||||
Start-OldWindowsInstallationScript $context;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$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";
|
||||
|
||||
$context.RemoveDesktopIcon("*Microsoft Edge*");
|
||||
$context.SetStage($prerequisitesStage);
|
||||
break;
|
||||
}
|
||||
# Always install updates
|
||||
default {
|
||||
Write-Host "Starting Installation and Restoration of Windows";
|
||||
Update-WindowsInstallation $context;
|
||||
}
|
||||
$prerequisitesStage {
|
||||
Write-Host "Installing prerequisites for installing software";
|
||||
|
||||
if (-not $(Get-Command winget)) {
|
||||
choco install -y winget;
|
||||
}
|
||||
|
||||
Install-Module -AcceptLicense -Force "NuGet";
|
||||
Import-Module NuGet;
|
||||
|
||||
Install-Firefox $context;
|
||||
choco install -y selenium-gecko-driver;
|
||||
$null = Install-Package -Force Selenium.WebDriver -RequiredVersion 4.10.0 -SkipDependencies;
|
||||
|
||||
winget install --accept-source-agreements --accept-package-agreements -e --id AutoHotkey.AutoHotkey;
|
||||
|
||||
$context.SetStage($driverStage);
|
||||
break;
|
||||
}
|
||||
$driverStage {
|
||||
Write-Host "Installing drivers";
|
||||
|
||||
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;
|
||||
function Invoke-WindowsInstallation([Context] $context) {
|
||||
$Global:InformationPreference = "Continue";
|
||||
$Global:ErrorActionPreference = "Inquire";
|
||||
$context.UserNames ??= @("Manuel");
|
||||
Start-OldWindowsInstallationScript $context;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$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";
|
||||
|
||||
$context.RemoveDesktopIcon("*Microsoft Edge*");
|
||||
$context.SetStage($prerequisitesStage);
|
||||
break;
|
||||
}
|
||||
# Always install updates
|
||||
default {
|
||||
Write-Host "Starting Installation and Restoration of Windows";
|
||||
Update-WindowsInstallation $context;
|
||||
}
|
||||
$prerequisitesStage {
|
||||
Write-Host "Installing prerequisites for installing software";
|
||||
|
||||
if (-not $(Get-Command winget)) {
|
||||
choco install -y winget;
|
||||
}
|
||||
|
||||
Install-Module -AcceptLicense -Force "NuGet";
|
||||
Import-Module NuGet;
|
||||
|
||||
Install-Firefox $context;
|
||||
choco install -y selenium-gecko-driver;
|
||||
$null = Install-Package -Force Selenium.WebDriver -RequiredVersion 4.10.0 -SkipDependencies;
|
||||
|
||||
winget install --accept-source-agreements --accept-package-agreements -e --id AutoHotkey.AutoHotkey;
|
||||
|
||||
$context.SetStage($driverStage);
|
||||
break;
|
||||
}
|
||||
$driverStage {
|
||||
Write-Host "Installing drivers";
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -76,7 +76,7 @@ $null = New-Module {
|
|||
$scriptPath = "$PSScriptRoot/../../Common/Scripts/config.fish";
|
||||
|
||||
function fish {
|
||||
wsl --shell-type login -- nix --extra-experimental-features "nix-command flakes" nixpkgs`#fish $args
|
||||
wsl --shell-type login -- nix --extra-experimental-features "nix-command flakes" run nixpkgs`#fish $args
|
||||
}
|
||||
|
||||
fish -c ". $(ConvertTo-LinuxPath $scriptPath); $Script" | ConvertFrom-Json;
|
||||
|
|
|
@ -9,6 +9,20 @@ enum InstallerAction {
|
|||
$null = New-Module {
|
||||
$userArgument = "name";
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Gets the name of the software.
|
||||
#>
|
||||
function Get-SoftwareName {
|
||||
$path = ${Function:Install-Software}.File;
|
||||
|
||||
if ($path -ne "$PSCommandPath") {
|
||||
Split-Path -Leaf (Split-Path -Parent $path);
|
||||
} else {
|
||||
$null;
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Installs the software.
|
||||
|
@ -40,10 +54,20 @@ $null = New-Module {
|
|||
[InstallerAction] $Action,
|
||||
[hashtable] $Arguments
|
||||
)
|
||||
|
||||
$null = $softwareName;
|
||||
|
||||
if ($null -ne (Get-SoftwareName)) {
|
||||
$softwareName = "``$(Get-SoftwareName)``";
|
||||
} else {
|
||||
$softwareName = "unknown software";
|
||||
}
|
||||
|
||||
if (($null -eq $Action) -or ($action -eq ([InstallerAction]::Install))) {
|
||||
Write-Host "Installing $softwareName…";
|
||||
Install-Software @Arguments;
|
||||
} elseif ($action -eq ([InstallerAction]::Configure)) {
|
||||
Write-Host "Configuring $softwareName…";
|
||||
Set-SoftwareConfiguration @Arguments;
|
||||
|
||||
foreach ($user in Get-Users) {
|
||||
|
@ -56,6 +80,7 @@ $null = New-Module {
|
|||
$Arguments.Add($userArgument, ($env:UserName));
|
||||
}
|
||||
|
||||
Write-Host "Configuring $softwareName for user ``$($Arguments[$userArgument])``…";
|
||||
Set-SoftwareUserConfiguration @Arguments;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue