PortValhalla/profiles/DerGeret/Windows/Setup.ps1

86 lines
3.4 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);
2023-07-08 21:56:47 +00:00
$garbage = 0;
foreach ($partition in $partitionCreations) {
$order = [int]$partition.SelectSingleNode("./ua:Order", $namespace).InnerText;
2023-07-08 21:56:47 +00:00
$garbage += [int]$partition.SelectSingleNode("./ua:Size", $namespace).InnerText;
2023-07-08 21:18:57 +00:00
$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");
2023-07-08 21:56:47 +00:00
$size.InnerText = "$((1 * 1024 * 1024) - $garbage)";
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
$partitionModificationContainer = $diskConfig.SelectSingleNode("./ua:ModifyPartitions", $namespace);
2023-07-08 22:02:10 +00:00
$partitionModifications = $partitionModificationContainer.SelectNodes("./ua:ModifyPartition", $namespace);
$newModification = $partitionModifications[1].CloneNode($true);
$newModification.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newIndex";
$newModification.SelectSingleNode("./ua:PartitionID", $namespace).InnerText = "$newIndex";
foreach ($partition in $partitionModifications) {
$partitionID = [int]$partition.SelectSingleNode("./ua:PartitionID", $namespace).InnerText;
2023-07-08 21:54:56 +00:00
$newID = $partitionID;
2023-07-08 21:54:56 +00:00
if ($partitionID -eq 2) {
$newID--;
} else {
if ($partitionID -ge $newIndex) {
$newID++;
}
if ($partitionID -lt 2) {
$newID++;
}
}
if ($partitionID -ne $newID) {
$partition.SelectSingleNode("./ua:PartitionID", $namespace).InnerText = "$newID";
$partition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newID";
}
}
2023-07-03 10:45:26 +00:00
$null = $partitionModificationContainer.AppendChild($newModification);
}
2023-07-03 10:47:54 +00:00
. "$PSScriptRoot/../../../scripts/Windows/OS/Setup.ps1";