From 48a1913401a55f61c1a5fa75ebc107c0440ec23e Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Mon, 11 Mar 2024 17:32:47 +0100 Subject: [PATCH] Include Unattend settings in `PortValhalla` --- scripts/Windows/OS/InitialBoot.ps1 | 16 ++ scripts/Windows/OS/Setup.ps1 | 18 +- .../Resources/Autounattend.template.xml | 223 ++++++++++++++++++ 3 files changed, 254 insertions(+), 3 deletions(-) create mode 100644 scripts/Windows/OS/InitialBoot.ps1 create mode 100644 scripts/Windows/Resources/Autounattend.template.xml diff --git a/scripts/Windows/OS/InitialBoot.ps1 b/scripts/Windows/OS/InitialBoot.ps1 new file mode 100644 index 00000000..bd55d157 --- /dev/null +++ b/scripts/Windows/OS/InitialBoot.ps1 @@ -0,0 +1,16 @@ +[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; + +choco install -y git --params='/WindowsTerminalProfile /DefaultBranchName:main'; +choco install -y powershell-core --install-arguments='"ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 REGISTER_MANIFEST=1 USE_MU=1 ENABLE_MU=1"'; +refreshenv; + +if (-not $(Get-Command winget)) { + choco install -y winget; +} + +Set-Location C:/; +git clone https://git.nuth.ch/manuth/PortValhalla.git; +Set-Location PortValhalla; diff --git a/scripts/Windows/OS/Setup.ps1 b/scripts/Windows/OS/Setup.ps1 index f3a1bd68..b1d0dd44 100644 --- a/scripts/Windows/OS/Setup.ps1 +++ b/scripts/Windows/OS/Setup.ps1 @@ -10,7 +10,7 @@ $unattendedConfig.PreserveWhitespace = $true; $readerSettings = [System.Xml.XmlReaderSettings]::new(); $readerSettings.IgnoreComments = $true; -$reader = [System.Xml.XmlReader]::Create("$drive\Autounattend.template.xml", $readerSettings); +$reader = [System.Xml.XmlReader]::Create("$PSScriptRoot/../Resources/Autounattend.template.xml", $readerSettings); $unattendedConfig.Load($reader); $namespace = New-Object -TypeName "Xml.XmlNamespaceManager" -ArgumentList $unattendedConfig.NameTable; @@ -29,15 +29,27 @@ function Get-PassSettings { $specializeSettings = Get-PassSettings "specialize"; $specializeSettings.SelectSingleNode("./ua:component[@name='Microsoft-Windows-Shell-Setup']/ua:ComputerName", $namespace).InnerText = "$env:WIN_COMPUTER_NAME"; +# Execute corresponding installer script after startup $oobeSystemSettings = Get-PassSettings "oobeSystem"; -$oobeSystemSettings.SelectSingleNode("./ua:component/ua:FirstLogonCommands/ua:SynchronousCommand[last()]/ua:CommandLine", $namespace).InnerText += "; pwsh '$env:SETUP_SCRIPT_NAME';"; +$installationCommand = $oobeSystemSettings.SelectSingleNode("./ua:component/ua:FirstLogonCommands/ua:SynchronousCommand[last()]/ua:CommandLine", $namespace); +$newCommand = $installationCommand.CloneNode($true); + +$newCommand.SelectSingleNode("./ua:CommandLine", $namespace).InnerText = ` + "powershell -Command " + ` + $(Get-Content "$PSScriptRoot/InitialBoot.ps1") + ` + "; pwsh '$env:SETUP_SCRIPT_NAME';"; + +$order = [int]$newCommand.SelectSingleNode("./ua:Order", $namespace).InnerText; +$newCommand.SelectSingleNode("./ua:Order", $namespace).InnerText = $order++; +$newCommand.SelectSingleNode("./ua:Description", $namespace).InnerText = "Install PowerShell Core and git and run setup script"; +$installationCommand.ParentNode.AppendChild($newCommand); if ($Global:SetupConfigPostprocessor) { $Global:SetupConfigPostprocessor.Invoke($unattendedConfig, $namespace); } $unattendedConfig.PreserveWhitespace = $true; -$unattendedConfig.Save("$drive\Autounattend.xml"); +$unattendedConfig.Save("$drive/Autounattend.xml"); Write-Warning "Attention: This program will completely wipe your current disk #1 and install Windows on it. Are you sure you want to do this?" Read-Host -Prompt "Hit enter to continue or CTRL+C to abort" diff --git a/scripts/Windows/Resources/Autounattend.template.xml b/scripts/Windows/Resources/Autounattend.template.xml new file mode 100644 index 00000000..075f51e8 --- /dev/null +++ b/scripts/Windows/Resources/Autounattend.template.xml @@ -0,0 +1,223 @@ + + + + + + en-US + + 0807:00000807 + en-US + en-US + en-US + en-US + + + + + 0 + true + + + + 1 + Primary + 300 + + + + 2 + EFI + 100 + + + + 3 + MSR + 128 + + + + 4 + Primary + true + + + + + + 1 + 1 + + NTFS + de94bba4-06d1-4d40-a16a-bfd50179d6ac + + + + 2 + 2 + + FAT32 + + + + 3 + 3 + + + + 4 + 4 + + C + NTFS + + + + OnError + + + + + 0 + 4 + + + + + + VK7JG-NPHTM-C97JM-9MPGT-3V66T + Never + + true + Admin + + + + + + + false + + + + + 1 + + + + + 0807:00000807 + de-CH + en-US + en-US + de-CH + + + true + + + 0 + + + + VK7JG-NPHTM-C97JM-9MPGT-3V66T + + + + + + + + true</PlainText> + </Password> + <Enabled>true</Enabled> + <Username>Admin</Username> + </AutoLogon> + <OOBE> + <HideEULAPage>true</HideEULAPage> + <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen> + <HideOnlineAccountScreens>true</HideOnlineAccountScreens> + <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE> + <NetworkLocation>Home</NetworkLocation> + <SkipUserOOBE>true</SkipUserOOBE> + <SkipMachineOOBE>true</SkipMachineOOBE> + <ProtectYourPC>1</ProtectYourPC> + </OOBE> + <UserAccounts> + <LocalAccounts> + <LocalAccount wcm:action="add"> + <Password> + <Value></Value> + <PlainText>true</PlainText> + </Password> + <Description></Description> + <DisplayName>Admin</DisplayName> + <Group>Administrators</Group> + <Name>Admin</Name> + </LocalAccount> + </LocalAccounts> + </UserAccounts> + <RegisteredOrganization></RegisteredOrganization> + <RegisteredOwner>Admin</RegisteredOwner> + <DisableAutoDaylightTimeSet>false</DisableAutoDaylightTimeSet> + <FirstLogonCommands> + <!-- <SynchronousCommand wcm:action="add"> + <Description>Control Panel View</Description> + <Order>1</Order> + <CommandLine>reg add + "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel" + /v StartupPage /t REG_DWORD /d 1 /f</CommandLine> + <RequiresUserInput>true</RequiresUserInput> + </SynchronousCommand> --> + <!-- <SynchronousCommand wcm:action="add"> + <Order>2</Order> + <Description>Control Panel Icon Size</Description> + <RequiresUserInput>false</RequiresUserInput> + <CommandLine>reg add + "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel" + /v AllItemsIconView /t REG_DWORD /d 0 /f</CommandLine> + </SynchronousCommand> --> + <SynchronousCommand wcm:action="add"> + <Order>1</Order> + <RequiresUserInput>true</RequiresUserInput> + <CommandLine>cmd /C wmic useraccount where name="Admin" set PasswordExpires=false</CommandLine> + <Description>Password Never Expires</Description> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <Order>2</Order> + <RequiresUserInput>false</RequiresUserInput> + <CommandLine>powershell -Command "Set-ExecutionPolicy -Force Bypass"</CommandLine> + <Description>Allow PowerShell scripts from anywhere.</Description> + </SynchronousCommand> + </FirstLogonCommands> + <TimeZone>W. Europe Standard Time</TimeZone> + </component> + </settings> +</unattend>