Pass boot script path via env variable

This commit is contained in:
Manuel Thalmann 2024-07-27 18:59:47 +02:00
parent 2b9558f720
commit 800261791e

View file

@ -4,9 +4,6 @@ $Global:ErrorActionPreference = "Inquire";
$null = $env:WIN_COMPUTER_NAME; $null = $env:WIN_COMPUTER_NAME;
$null = $env:SETUP_SCRIPT_NAME; $null = $env:SETUP_SCRIPT_NAME;
# Find `winiso` installation medium
$drives = & wmic volume get "DriveLetter,Label";
$drive = $($($drives | Select-String -Pattern "winiso") -split "\s+")[0];
[xml]$unattendedConfig = [xml]::new(); [xml]$unattendedConfig = [xml]::new();
$unattendedConfig.PreserveWhitespace = $true; $unattendedConfig.PreserveWhitespace = $true;
@ -36,10 +33,25 @@ $oobeSystemSettings = Get-PassSettings "oobeSystem";
$installationCommand = $oobeSystemSettings.SelectSingleNode("./ua:component/ua:FirstLogonCommands/ua:SynchronousCommand[last()]", $namespace); $installationCommand = $oobeSystemSettings.SelectSingleNode("./ua:component/ua:FirstLogonCommands/ua:SynchronousCommand[last()]", $namespace);
$newCommand = $installationCommand.ParentNode.AppendChild($installationCommand.CloneNode($true)); $newCommand = $installationCommand.ParentNode.AppendChild($installationCommand.CloneNode($true));
function Get-RemoteScriptPath($path) {
$relativePath = [System.IO.Path]::GetRelativePath("$PSScriptRoot/../../..", $path);
Join-Path $env:REMOTE_PROJECT_PATH $relativePath;
}
function Get-Injection($value) {
"([System.Text.Encoding]::Default.GetString([System.Convert]::FromBase64String('$(
[System.Convert]::ToBase64String([System.Text.Encoding]::Default.GetBytes($value))
)')))"
}
function Get-ScriptPathInjection($path) {
"(Join-Path `$env:SystemDrive $(Get-Injection (Get-RemoteScriptPath $path)))"
}
$newCommand.SelectSingleNode("./ua:CommandLine", $namespace).InnerText = ` $newCommand.SelectSingleNode("./ua:CommandLine", $namespace).InnerText = `
"powershell -Command " + ` "powershell -Command " + `
$(Get-Content "$PSScriptRoot/InitialBoot.ps1") + ` "`$env:INSTALLER_SCRIPT = $(Get-ScriptPathInjection $env:SETUP_SCRIPT_NAME);" + `
"; pwsh '$([System.IO.Path]::GetRelativePath("$PSScriptRoot/../../..", $env:SETUP_SCRIPT_NAME))';"; "Invoke-Expression $(Get-ScriptPathInjection "$PSScriptRoot/InitialBoot.ps1");";
$orderElement = $newCommand.SelectSingleNode("./ua:Order", $namespace); $orderElement = $newCommand.SelectSingleNode("./ua:Order", $namespace);
$orderElement.InnerText = ([int]($orderElement.InnerText) + 1); $orderElement.InnerText = ([int]($orderElement.InnerText) + 1);
@ -49,9 +61,10 @@ if (Get-Command Initialize-SetupConfig -ErrorAction SilentlyContinue) {
Initialize-SetupConfig $unattendedConfig $namespace; Initialize-SetupConfig $unattendedConfig $namespace;
} }
$unattendedConfigFile = "X:\unattend.xml";
$unattendedConfig.PreserveWhitespace = $true; $unattendedConfig.PreserveWhitespace = $true;
$unattendedConfig.Save("$drive/Autounattend.xml"); $unattendedConfig.Save($unattendedConfigFile);
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?" 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" Read-Host -Prompt "Hit enter to continue or CTRL+C to abort"
& "$drive\setup.exe"; & "$SETUP_DRIVE\setup.exe" /Unattend:$unattendedConfigFile;