PortValhalla/profiles/DerGeret/Windows/Setup.ps1

73 lines
3.2 KiB
PowerShell
Raw Normal View History

2023-06-21 20:11:38 +00:00
$env:WIN_COMPUTER_NAME = "DerGeret";
$env:SETUP_SCRIPT_NAME = [System.IO.Path]::GetRelativePath("$PSScriptRoot/../../..", "$PSScriptRoot/Restore.ps1");
$Global:SetupConfigPostprocessor = {
param([xml] $config, [System.Xml.XmlNamespaceManager] $namespace)
2023-07-03 10:40:28 +00:00
$setupComponent = $config.SelectSingleNode(
"/ua:unattend/ua:settings[@pass='windowsPE']/ua:component[@name='Microsoft-Windows-Setup']",
$namespace);
2023-07-03 10:40:28 +00:00
$diskConfig = $setupComponent.SelectSingleNode("./ua:DiskConfiguration/ua:Disk", $namespace);
$installationPartition = $setupComponent.SelectSingleNode("./ua:ImageInstall/ua:OSImage/ua:InstallTo/ua:PartitionID", $namespace);
2023-07-03 10:40:28 +00:00
2023-07-08 21:18:57 +00:00
$newIndex = 2;
2023-07-03 10:40:28 +00:00
$installationPartition.InnerText = "$($newIndex + 1)";
$partitionCreationContainer = $diskConfig.SelectSingleNode("./ua:CreatePartitions", $namespace);
$partitionCreations = $partitionCreationContainer.SelectNodes("./ua:CreatePartition", $namespace);
$winPartition = ($partitionCreations | Select-Object -Last 1);
2023-07-08 21:18:57 +00:00
$newPartition = $winPartition.CloneNode($true);
$offset = 0;
foreach ($partition in $partitionCreations) {
$order = [int]$partition.SelectSingleNode("./ua:Order", $namespace).InnerText;
2023-07-08 21:18:57 +00:00
$offset += [int]$partition.SelectSingleNode("./ua:Size", $namespace).InnerText;
$newOrder = $order;
2023-07-08 21:18:57 +00:00
if ($order -eq 2) {
$newOrder--;
} else {
2023-07-08 21:18:57 +00:00
if ($order -ge $newIndex) {
$newOrder++;
}
if ($order -lt 2) {
$newOrder++;
}
}
if ($order -ne $newOrder) {
$partition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newOrder";
}
}
2023-07-08 21:18:57 +00:00
# Add space before Windows installation... wha-!? For Linux, ofc! I use Arch Linux, btw.
$size = $winPartition.OwnerDocument.CreateElement("Size");
$size.InnerText = "$((1 * 1024 * 1024) - $offset)";
2023-07-08 21:49:30 +00:00
$winPartition.RemoveChild($winPartition.SelectSingleNode("./ua:Extend", $namespace));
2023-07-08 21:18:57 +00:00
$winPartition.AppendChild($size);
2023-07-08 21:18:57 +00:00
$newPartition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newIndex";
$null = $partitionCreationContainer.AppendChild($newPartition);
2023-07-03 10:45:26 +00:00
$partitionModifications = $diskConfig.SelectSingleNode("./ua:ModifyPartitions", $namespace);
2023-07-03 11:02:47 +00:00
$newModification = $partitionModifications.SelectNodes("./ua:ModifyPartition", $namespace)[2].CloneNode($true);
$newModification.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newIndex";
$newModification.SelectSingleNode("./ua:PartitionID", $namespace).InnerText = "$newIndex";
for ($i = 0; $i -lt $partitionModifications.ChildNodes.Count; $i++) {
$partition = $partitionModifications.ChildNodes[$i];
$partitionID = [int]$partition.SelectSingleNode("./ua:PartitionID", $namespace).InnerText;
if ($partitionID -ge $newIndex) {
$partition.SelectSingleNode("./ua:PartitionID", $namespace).InnerText = "$($partitionID + 1)";
$partition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$($partitionID + 1)";
}
}
2023-07-03 10:45:26 +00:00
2023-07-03 11:04:27 +00:00
$null = $partitionModifications.AppendChild($newModification);
}
2023-07-03 10:47:54 +00:00
. "$PSScriptRoot/../../../scripts/Windows/OS/Setup.ps1";