Compare commits

..

29 commits

Author SHA1 Message Date
Manuel Thalmann eae1d94b26 Ensure the script path is detected properly 2024-08-09 14:45:50 +02:00
Manuel Thalmann 451b7a21e6 Allow automatic script execution for MS accounts 2024-08-09 14:45:29 +02:00
Manuel Thalmann a41016ea86 Reorder winget arguments 2024-08-09 14:45:05 +02:00
Manuel Thalmann 3388ddc84e Allow registering reboot for the default user 2024-08-09 14:44:57 +02:00
Manuel Thalmann 8e155a00d5 Add a dedicated function for disabling boot message 2024-08-09 13:35:12 +02:00
Manuel Thalmann cac1df3027 Implement root install loop using a switch 2024-08-09 13:34:46 +02:00
Manuel Thalmann 3b79053455 Force computer reboots 2024-08-09 04:42:55 +02:00
Manuel Thalmann 16a8f8d499 Add scripts for controlling UAC 2024-08-09 04:29:26 +02:00
Manuel Thalmann 44d8223cd5 Set displayname of all users 2024-08-09 04:20:00 +02:00
Manuel Thalmann 797fde65af Login to users for configuration 2024-08-09 04:19:49 +02:00
Manuel Thalmann fc95d4c76d Skip PWSH_PATH if undefined 2024-08-09 04:08:22 +02:00
Manuel Thalmann c5ccae9b35 Fix typo 2024-08-09 03:38:10 +02:00
Manuel Thalmann 8efc752218 Add missing setup stage 2024-08-09 03:02:25 +02:00
Manuel Thalmann 79098f5efb Make Get-Users output explicit 2024-08-09 03:02:17 +02:00
Manuel Thalmann 86374baf2f Allow displaying a boot message 2024-08-09 02:59:06 +02:00
Manuel Thalmann 5ad857320d Disable users by default 2024-08-09 02:58:01 +02:00
Manuel Thalmann 05ad26763a Add a stage for configuring users 2024-08-09 02:27:24 +02:00
Manuel Thalmann c08afd1221 Detect installation properly 2024-08-09 02:24:59 +02:00
Manuel Thalmann bc4055d760 Remove unnecessary icon 2024-08-09 02:23:56 +02:00
Manuel Thalmann 65c2d8e714 Add Predator Z301C to the hardware list 2024-08-09 02:23:41 +02:00
Manuel Thalmann 5b084342c5 Add support for the sudo command 2024-08-09 02:22:45 +02:00
Manuel Thalmann 245af3c2a0 Fix renaming user 2024-08-09 02:20:27 +02:00
Manuel Thalmann aeeedd02ee Make specifying PWSH_PATH optional 2024-08-09 02:12:27 +02:00
Manuel Thalmann bb3de634f9 Show error properly 2024-08-09 02:00:18 +02:00
Manuel Thalmann b16094f8f7 Fix typo 2024-08-09 01:53:59 +02:00
Manuel Thalmann 9e37f99036 Remove code duplication 2024-08-09 01:33:04 +02:00
Manuel Thalmann 116d6d9676 Remove unnecessary console output 2024-08-09 01:22:51 +02:00
Manuel Thalmann 3d67480a80 Fix incorrect file paths 2024-08-09 00:17:05 +02:00
Manuel Thalmann c79bec479d Fix incorrect hardware name 2024-08-09 00:03:45 +02:00
13 changed files with 645 additions and 383 deletions

View file

@ -32,6 +32,7 @@
hardware = { hardware = {
components = [ components = [
"ROG Zenith Extreme Alpha" "ROG Zenith Extreme Alpha"
"Predator Z301C"
]; ];
eyeX = true; eyeX = true;

View file

@ -7,6 +7,7 @@ enum SetupStage {
Configure Configure
Install Install
CreateUser CreateUser
ConfigureUser
} }
$null = New-Module { $null = New-Module {
@ -149,9 +150,21 @@ $null = New-Module {
Gets the names of the users to create. Gets the names of the users to create.
#> #>
function Get-Users { function Get-Users {
[OutputType([string[]])]
param()
Get-Attributes "valhalla.windows.users"; Get-Attributes "valhalla.windows.users";
} }
<#
.SYNOPSIS
Gets the name of the setup user.
#>
function Get-SetupUser {
[OutputType([string])]
param()
Get-Config "valhalla.windows.setupUser";
}
<# <#
.SYNOPSIS .SYNOPSIS
Gets the value of an option related to the setup. Gets the value of an option related to the setup.

View file

@ -10,5 +10,6 @@ function Start-Operation {
$env:CONFIG_MODULE = Resolve-Path $env:CONFIG_MODULE; $env:CONFIG_MODULE = Resolve-Path $env:CONFIG_MODULE;
} }
New-Alias "sudo" gsudo;
& $Action; & $Action;
} }

View file

@ -72,7 +72,8 @@ $null = New-Module {
winget install ` winget install `
--accept-source-agreements --accept-package-agreements ` --accept-source-agreements --accept-package-agreements `
--source winget ` --source winget `
--exact --id $name $ArgumentList; $ArgumentList `
--exact --id $name ;
} else { } else {
Write-Host "Package ``$name`` is already installed" Write-Host "Package ``$name`` is already installed"
} }

View file

@ -1,6 +1,9 @@
#!/bin/pwsh #!/bin/pwsh
using namespace System.Security.Principal;
. "$PSScriptRoot/../../../scripts/Windows/Scripts/Prerequisites.ps1"; . "$PSScriptRoot/../../../scripts/Windows/Scripts/Prerequisites.ps1";
. "$PSScriptRoot/../../Common/Scripts/Context.ps1"; . "$PSScriptRoot/../../Common/Scripts/Context.ps1";
. "$PSScriptRoot/../Scripts/Security.ps1";
. "$PSScriptRoot/../Software/Firefox/Install.ps1"; . "$PSScriptRoot/../Software/Firefox/Install.ps1";
. "$PSScriptRoot/Manage.ps1"; . "$PSScriptRoot/Manage.ps1";
. "$PSScriptRoot/User/Install.ps1"; . "$PSScriptRoot/User/Install.ps1";
@ -8,6 +11,7 @@
$null = New-Module { $null = New-Module {
. "$PSScriptRoot/../Scripts/Hooks.ps1"; . "$PSScriptRoot/../Scripts/Hooks.ps1";
. "$PSScriptRoot/../Scripts/PowerManagement.ps1"; . "$PSScriptRoot/../Scripts/PowerManagement.ps1";
. "$PSScriptRoot/../Scripts/Registry.ps1";
. "$PSScriptRoot/../Scripts/Update.ps1"; . "$PSScriptRoot/../Scripts/Update.ps1";
. "$PSScriptRoot/../Scripts/Users.ps1"; . "$PSScriptRoot/../Scripts/Users.ps1";
. "$PSScriptRoot/../../Common/Scripts/Config.ps1"; . "$PSScriptRoot/../../Common/Scripts/Config.ps1";
@ -32,9 +36,12 @@ $null = New-Module {
#> #>
function Start-InstallationLoop { function Start-InstallationLoop {
while (-not (Get-IsFinished)) { while (-not (Get-IsFinished)) {
if ($null -eq (Get-Stage)) { switch (Get-Stage) {
($null) {
Set-Stage ([SetupStage]::Initialize); Set-Stage ([SetupStage]::Initialize);
} elseif ((Get-Stage) -eq ([SetupStage]::Initialize)) { break;
}
([SetupStage]::Initialize) {
if (-not ((Test-Command "choco") -and (Test-Command "refreshenv"))) { if (-not ((Test-Command "choco") -and (Test-Command "refreshenv"))) {
Invoke-Hook "Install-Chocolatey" -Fallback { Invoke-Hook "Install-Chocolatey" -Fallback {
# Install chocolatey # Install chocolatey
@ -47,6 +54,12 @@ $null = New-Module {
continue; continue;
} }
if (-not (Test-Command "gsudo")) {
Install-ChocoPackage gsudo;
refreshenv;
continue;
}
if (-not (Test-Command "git")) { if (-not (Test-Command "git")) {
Install-ChocoPackage git; Install-ChocoPackage git;
refreshenv; refreshenv;
@ -62,7 +75,7 @@ $null = New-Module {
return; return;
} }
if (Test-Path $env:PWSH_PATH) { if ($env:PWSH_PATH -and (Test-Path $env:PWSH_PATH)) {
attrib "-R" "$env:PWSH_PATH\*" /S /D; attrib "-R" "$env:PWSH_PATH\*" /S /D;
Remove-Item -Recurse -Force $env:PWSH_PATH; Remove-Item -Recurse -Force $env:PWSH_PATH;
continue; continue;
@ -107,7 +120,9 @@ $null = New-Module {
}; };
Set-Stage ([SetupStage]::Configure); Set-Stage ([SetupStage]::Configure);
} else { break;
}
default {
$null = Import-Module PSWindowsUpdate; $null = Import-Module PSWindowsUpdate;
Invoke-Hook "Invoke-WindowsUpdate" -Fallback { Invoke-Hook "Invoke-WindowsUpdate" -Fallback {
@ -135,10 +150,10 @@ $null = New-Module {
$arguments = [hashtable]@{ }; $arguments = [hashtable]@{ };
if ($Action) { if ($Action) {
$install = $true; $install = ($Action -eq ([InstallerAction]::Install));
$null = $arguments.Add("action", $Action); $null = $arguments.Add("action", $Action);
} else { } else {
$install = ($Action -eq ([InstallerAction]::Install)); $install = $true;
} }
# Drivers # Drivers
@ -173,7 +188,7 @@ $null = New-Module {
Remove-DesktopIcon "*Geforce*"; Remove-DesktopIcon "*Geforce*";
} }
if (Get-Config "valhalla.hardware.corsairLighting") { if (Get-Config "valhalla.hardware.corsairDevice") {
Install-ChocoPackage icue; Install-ChocoPackage icue;
} }
@ -387,7 +402,7 @@ $null = New-Module {
. "$softwarePath/ManiaPlanet/Manage.ps1" @arguments; . "$softwarePath/ManiaPlanet/Manage.ps1" @arguments;
. "$softwarePath/osu!/Manage.ps1" @arguments; . "$softwarePath/osu!/Manage.ps1" @arguments;
. "$softwarePath/osu!lazer/Manage.ps1" @arguments; . "$softwarePath/osu!lazer/Manage.ps1" @arguments;
. "$softwarePath/RetorArch/Manage.ps1" @arguments; . "$softwarePath/RetroArch/Manage.ps1" @arguments;
. "$softwarePath/reWASD/Manage.ps1" @arguments; . "$softwarePath/reWASD/Manage.ps1" @arguments;
} }
}; };
@ -419,12 +434,56 @@ $null = New-Module {
} }
([SetupStage]::CreateUser) { ([SetupStage]::CreateUser) {
Start-ValhallaUserSetup; 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;
Disable-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") {
Enable-UAC;
Disable-Autologin;
Set-BootMessage -Caption "Login" -Message "Please login using your account.";
} else {
Set-AutologinUser "$user";
}
Restart-Intermediate -DefaultUser;
return;
}
}
Set-IsFinished $true; Set-IsFinished $true;
} }
} }
} }
} }
} }
}
function Invoke-WindowsInstallation([Context] $context) { function Invoke-WindowsInstallation([Context] $context) {
$Global:InformationPreference = "Continue"; $Global:InformationPreference = "Continue";

View file

@ -61,7 +61,6 @@ $null = New-Module {
[System.Xml.XmlNode] $association = $null; [System.Xml.XmlNode] $association = $null;
$document = Get-DefaultAppAssociations; $document = Get-DefaultAppAssociations;
$candidates = $document.SelectNodes((& $getSelector $Identifier)); $candidates = $document.SelectNodes((& $getSelector $Identifier));
Write-Host "Number of potential associations: $($candidates.Count)"
if ($candidates.Count -eq 1) { if ($candidates.Count -eq 1) {
$association = $candidates[0]; $association = $candidates[0];

View file

@ -1,17 +1,41 @@
using namespace Microsoft.Win32; using namespace Microsoft.Win32;
$null = New-Module { $null = New-Module {
. "$PSScriptRoot/../Scripts/Registry.ps1";
. "$PSScriptRoot/../../Common/Scripts/Config.ps1";
. "$PSScriptRoot/../../Common/Scripts/Scripting.ps1"; . "$PSScriptRoot/../../Common/Scripts/Scripting.ps1";
[RegistryKey] $key = $null; [RegistryKey] $key = $null;
$runOncePath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce"; $runOncePath = "Software\Microsoft\Windows\CurrentVersion\RunOnce";
$systemRunOncePath = "HKLM:\$runOncePath";
$logonPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
$runOnceName = "PortValhalla"; $runOnceName = "PortValhalla";
$autologinOption = "AutoAdminLogon";
$domainOption = "DefaultDomainName";
$userOption = "DefaultUserName";
$passwordOption = "DefaultPassword";
<# <#
.SYNOPSIS .SYNOPSIS
Gets the reghistry key containing the `RunOnce` commands. Gets the reghistry key containing the `RunOnce` commands.
#> #>
function Get-RunOnceKey { function Get-RunOnceKey {
Get-Item $runOncePath; param(
[RegistryKey] $UserKey
)
[string] $path;
if ($UserKey) {
$path = "$($UserKey.PSPath)\$runOncePath";
} else {
$path = $systemRunOncePath;
}
if (-not (Test-Path $path)) {
New-Item $path;
} else {
Get-Item $path;
}
} }
<# <#
@ -23,15 +47,34 @@ $null = New-Module {
#> #>
function Register-Setup { function Register-Setup {
param( param(
[Parameter(ParameterSetName="System")]
[switch] $System,
[Parameter(ParameterSetName="User",Mandatory)]
[switch] $User,
[Parameter(Mandatory)]
[RegistryKey] $UserKey [RegistryKey] $UserKey
) )
if ($User.IsPresent) {
if (-not $UserKey) {
$UserKey = Get-Item "HKCU:\";
}
$key = Get-RunOnceKey $UserKey; $key = Get-RunOnceKey $UserKey;
} else {
$key = Get-RunOnceKey;
}
Set-ItemProperty -Path $key.PSPath -Name $runOnceName -Type "ExpandString" -Value ( Set-ItemProperty -Path $key.PSPath -Name $runOnceName -Type "ExpandString" -Value (
"pwsh -Command " + "pwsh -Command " +
"`$env:PWSH_PATH = $(ConvertTo-Injection $env:PWSH_PATH);" + (& {
"`$env:INSTALLER_SCRIPT = $(ConvertTo-Injection $env:INSTALLER_SCRIPT);" + if ($env:PWSH_PATH) {
"`$env:PWSH_PATH = $(ConvertTo-Injection $env:PWSH_PATH);"
} else {
""
}
}) +
"`$env:INSTALLER_SCRIPT = $(ConvertTo-Injection (Resolve-Path $env:INSTALLER_SCRIPT));" +
"`$env:CONFIG_MODULE = $(ConvertTo-Injection $env:CONFIG_MODULE);" + "`$env:CONFIG_MODULE = $(ConvertTo-Injection $env:CONFIG_MODULE);" +
"& `$env:INSTALLER_SCRIPT;" "& `$env:INSTALLER_SCRIPT;"
); );
@ -39,12 +82,79 @@ $null = New-Module {
$key.Handle.Close(); $key.Handle.Close();
} }
<#
.SYNOPSIS
Sets the user to login automatically on boot.
.PARAMETER Name
The name of the user to login automatically.
#>
function Set-AutologinUser {
param(
[string] $Name
)
Set-ItemProperty $autologinOption -Name $autologinOption "1";
if (-not $Name) {
$Name = Get-SetupUser;
}
$options = @{
$domainOption = "";
$userOption = $Name;
$passwordOption = "";
};
foreach ($key in $options.Keys) {
Set-ItemProperty -Name $key
$displayName = Get-UserConfig -UserName $name "displayName";
$userArguments = @{
name = $name;
};
if ($displayName) {
$userArguments.fullName = $displayName;
} -Value $options[$key];
}
}
<#
.SYNOPSIS
Disables the automatic login.
#>
function Disable-Autologin {
Set-ItemProperty $logonPath -Name $autologinOption "0";
foreach ($key in @($domainOption, $userOption, $passwordOption)) {
Remove-ItemProperty $logonPath -Name $key -ErrorAction SilentlyContinue;
}
}
<# <#
.SYNOPSIS .SYNOPSIS
Reboots the machine intermediately and restarts the setup after the next login. Reboots the machine intermediately and restarts the setup after the next login.
#> #>
function Restart-Intermediate { function Restart-Intermediate {
Register-Setup; param(
Restart-Computer; [switch] $DefaultUser
)
$register = { param($Key) Register-Setup -UserKey $Key; };
if ($DefaultUser) {
Edit-DefaultUserKey {
param(
[RegistryKey] $Key
)
& $register -Key $Key;
}
}
& $register;
Read-Host "Press enter to reboot";
Restart-Computer -Force;
} }
} }

View file

@ -16,4 +16,41 @@ $null = New-Module {
[System.GC]::Collect(); [System.GC]::Collect();
& reg unload $regRootPath; & reg unload $regRootPath;
} }
<#
.SYNOPSIS
Sets a message to show on the login screen.
.PARAMETER Caption
The title of the message.
.PARAMETER Message
The text of the message.
#>
function Set-BootMessage {
param(
[string] $Caption,
[string] $Message
)
$options = @{
legalnoticecaption = $Caption;
legalnoticetext = $Message;
};
foreach ($key in $options.Keys) {
Set-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" `
-Name $key `
-Type "String" `
-Value ($options[$key]);
}
}
<#
.SYNOPSIS
Disables the boot message.
#>
function Disable-BootMessage {
Set-BootMessage;
}
} }

View file

@ -0,0 +1,36 @@
$null = New-Module {
$uacOption = "EnableLUA";
$systemPolicyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System";
$uacSetter = {
param(
[bool] $Value
)
Set-ItemProperty -Path $systemPolicyPath -Name $uacOption -Value ([int]$Value);
}
<#
.SYNOPSIS
Determines whether UAC is enabled.
#>
function Get-UACStatus {
[bool](Get-ItemProperty -Path $systemPolicyPath -Name $uacOption);
}
<#
.SYNOPSIS
Enables UAC.
#>
function Enable-UAC {
& $uacSetter $true;
}
<#
.SYNOPSIS
Disables UAC.
#>
function Disable-UAC {
& $uacSetter $false;
}
};

View file

@ -57,7 +57,7 @@ $null = New-Module {
"So sorry…") -join "`n"); "So sorry…") -join "`n");
Write-Host "Create a user for ``$Name`` manually (because Windows is too stupid)…"; Write-Host "Create a user for ``$Name`` manually (because Windows is too stupid)…";
Read-Host "Hit enter once you're done"; $null = Read-Host "Hit enter once you're done";
$newUsers = @(Get-LocalUser | Where-Object { -not ($currentUsers -contains $_.Name) }); $newUsers = @(Get-LocalUser | Where-Object { -not ($currentUsers -contains $_.Name) });
@ -96,7 +96,8 @@ $null = New-Module {
return $newUsers[$result - 1]; return $newUsers[$result - 1];
} }
} }
} else {
Write-Host "";
Write-Host "Unable to determine the new user"; Write-Host "Unable to determine the new user";
Write-Host "Retrying…"; Write-Host "Retrying…";
} }
@ -111,10 +112,6 @@ $null = New-Module {
Set-SetupOption $userOption $i; Set-SetupOption $userOption $i;
$name = $users[$i]; $name = $users[$i];
Write-Host "Creating personal user ``$name``"; Write-Host "Creating personal user ``$name``";
if (Get-UserConfig -UserName $name "microsoftAccount") {
Add-MicrosoftAccount $name;
} else {
$displayName = Get-UserConfig -UserName $name "displayName"; $displayName = Get-UserConfig -UserName $name "displayName";
$userArguments = @{ $userArguments = @{
@ -125,8 +122,13 @@ $null = New-Module {
$userArguments.fullName = $displayName; $userArguments.fullName = $displayName;
} }
New-LocalUser -NoPassword @userArguments; if (Get-UserConfig -UserName $name "microsoftAccount") {
Add-MicrosoftAccount $name;
} else {
New-LocalUser -Disabled -NoPassword @userArguments;
} }
Set-LocalUser @userArguments;
} }
} }
}; };

View file

@ -4,10 +4,12 @@ param(
) )
. "$PSScriptRoot/../../../Common/Scripts/Software.ps1"; . "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
. "$PSScriptRoot/../../../Common/Scripts/System.ps1";
Start-SoftwareInstaller @PSBoundParameters ` Start-SoftwareInstaller @PSBoundParameters `
-Installer { -Installer {
Install-WingetPackage Nadeo.ManiaPlanet; Install-WingetPackage Nadeo.ManiaPlanet;
Remove-DesktopIcon "ManiaPlanet*";
}; };
# ToDo: Add restoration # ToDo: Add restoration

View file

@ -5,8 +5,8 @@ param(
[hashtable] $Arguments [hashtable] $Arguments
) )
. "$PSScriptRoot/../../Scripts/Software.ps1"; . "$PSScriptRoot/../../Scripts/AppAssociations.ps1";
. "$PSScriptRoot/../../../Common/Scripts/AppAssociations.ps1"; . "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
Start-SoftwareInstaller @PSBoundParameters ` Start-SoftwareInstaller @PSBoundParameters `
-Installer { -Installer {

View file

@ -21,9 +21,10 @@ $null = New-Module {
$packageName = $version[0]; $packageName = $version[0];
Write-Host "Installing ``$packageName``"; Write-Host "Installing ``$packageName``";
Install-ChocoPackage $packageName; Install-ChocoPackage $packageName;
}
Remove-DesktopIcon "CocosCreator*"; Remove-DesktopIcon "CocosCreator*";
Remove-DesktopIcon "Unity Hub*"; Remove-DesktopIcon "Unity Hub*";
}
}; };
# ToDo: Add restoration # ToDo: Add restoration