From 800261791e706451175e9064e4a8c0af4aeaac33 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 27 Jul 2024 18:59:47 +0200 Subject: [PATCH] Pass boot script path via env variable --- scripts/Windows/OS/Setup.ps1 | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/scripts/Windows/OS/Setup.ps1 b/scripts/Windows/OS/Setup.ps1 index 1f584671..28578a26 100644 --- a/scripts/Windows/OS/Setup.ps1 +++ b/scripts/Windows/OS/Setup.ps1 @@ -4,9 +4,6 @@ $Global:ErrorActionPreference = "Inquire"; $null = $env:WIN_COMPUTER_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(); $unattendedConfig.PreserveWhitespace = $true; @@ -36,10 +33,25 @@ $oobeSystemSettings = Get-PassSettings "oobeSystem"; $installationCommand = $oobeSystemSettings.SelectSingleNode("./ua:component/ua:FirstLogonCommands/ua:SynchronousCommand[last()]", $namespace); $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 = ` "powershell -Command " + ` - $(Get-Content "$PSScriptRoot/InitialBoot.ps1") + ` - "; pwsh '$([System.IO.Path]::GetRelativePath("$PSScriptRoot/../../..", $env:SETUP_SCRIPT_NAME))';"; + "`$env:INSTALLER_SCRIPT = $(Get-ScriptPathInjection $env:SETUP_SCRIPT_NAME);" + ` + "Invoke-Expression $(Get-ScriptPathInjection "$PSScriptRoot/InitialBoot.ps1");"; $orderElement = $newCommand.SelectSingleNode("./ua:Order", $namespace); $orderElement.InnerText = ([int]($orderElement.InnerText) + 1); @@ -49,9 +61,10 @@ if (Get-Command Initialize-SetupConfig -ErrorAction SilentlyContinue) { Initialize-SetupConfig $unattendedConfig $namespace; } +$unattendedConfigFile = "X:\unattend.xml"; $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?" Read-Host -Prompt "Hit enter to continue or CTRL+C to abort" -& "$drive\setup.exe"; +& "$SETUP_DRIVE\setup.exe" /Unattend:$unattendedConfigFile;