2024-07-24 22:03:35 +00:00
|
|
|
#!/bin/env fish
|
|
|
|
begin
|
|
|
|
set -l dir (status dirname)
|
|
|
|
source "$dir/lib/choose-disk.fish"
|
|
|
|
|
|
|
|
set -q WIN11_IMAGE_PATH
|
|
|
|
or begin
|
|
|
|
echo "Please specify the Windows 11 ISO in the `WIN11_IMAGE_PATH` variable."
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
2024-07-26 12:29:45 +00:00
|
|
|
function mkWinPath
|
|
|
|
sed "s/\//\\\\/g"
|
|
|
|
end
|
|
|
|
|
2024-07-24 22:03:35 +00:00
|
|
|
set -l setupLabel "winiso-valhalla"
|
2024-07-26 12:29:45 +00:00
|
|
|
set -l projectPath "PortValhalla"
|
|
|
|
set -l localProjectPath "sources/\$OEM\$/\$1/$projectPath"
|
2024-07-24 22:03:35 +00:00
|
|
|
set -l cacheDir ~/.cache/winiso-valhalla
|
|
|
|
set -l winpe "$cacheDir/winpe.iso"
|
|
|
|
set -l winPath "/media/win"
|
|
|
|
set -l winpePath "/media/winpe"
|
|
|
|
set -l valhallaPath "/media/winiso-valhalla"
|
|
|
|
set -l winpeOverlay (mktemp -d)
|
|
|
|
set -l winOverlay (mktemp -d)
|
|
|
|
set -l upperDir (mktemp -d)
|
|
|
|
set -l workDir (mktemp -d)
|
|
|
|
set -l editionField "Edition ID"
|
|
|
|
set -l wimFile "sources/install.wim"
|
|
|
|
|
2024-07-25 18:02:47 +00:00
|
|
|
set -l tempPaths \
|
|
|
|
"$winpeOverlay" \
|
|
|
|
"$winOverlay" \
|
|
|
|
"$upperDir" \
|
|
|
|
"$workDir"
|
|
|
|
|
|
|
|
set -l mountPaths \
|
|
|
|
"$valhallaPath" \
|
|
|
|
"$winPath" \
|
|
|
|
"$winpePath"
|
|
|
|
|
2024-07-24 22:03:35 +00:00
|
|
|
set -l files
|
|
|
|
|
|
|
|
set -l fileDefinitions \
|
|
|
|
drivers/network/intel \
|
|
|
|
"https://dlcdnets.asus.com/pub/ASUS/mb/04LAN/DRV_LAN_Intel_I211_UWD_TP_W10_64_VER12151841_20190306R.zip?model=ROG%20ZENITH%20EXTREME%20ALPHA" \
|
|
|
|
zip \
|
|
|
|
. \
|
|
|
|
\
|
|
|
|
drivers/network/marvell \
|
|
|
|
"https://dlcdnets.asus.com/pub/ASUS/mb/04LAN/DRV_LAN_Marvell_TP_TSD_W11_64_V3130_20211118R.zip?model=ROG%20ZENITH%20EXTREME%20ALPHA" \
|
|
|
|
zip \
|
|
|
|
./x64 \
|
|
|
|
\
|
|
|
|
software/git \
|
|
|
|
"https://github.com/git-for-windows/git/releases/download/v2.41.0.windows.1/PortableGit-2.41.0-64-bit.7z.exe" \
|
|
|
|
exe \
|
|
|
|
. \
|
|
|
|
\
|
|
|
|
software/pwsh \
|
|
|
|
"https://github.com/PowerShell/PowerShell/releases/download/v7.3.7/PowerShell-7.3.7-win-x64.zip" \
|
|
|
|
zip \
|
|
|
|
.
|
|
|
|
|
|
|
|
for i in (seq 1 4 (count $fileDefinitions))
|
|
|
|
set -l entry $fileDefinitions[$i.."$(math "$i" + 3)"]
|
|
|
|
set -l name "$entry[1]"
|
|
|
|
set -l url "$entry[2]"
|
|
|
|
set -l type "$entry[3]"
|
|
|
|
set -l dir "$entry[4]"
|
2024-07-26 12:29:45 +00:00
|
|
|
set -l winPath "X:\\$(echo "$name" | mkWinPath)"
|
2024-07-24 22:03:35 +00:00
|
|
|
set -l file "$cacheDir/$name.$type"
|
|
|
|
set -l target "$winpeOverlay/$name"
|
|
|
|
|
|
|
|
set -a files \
|
|
|
|
"$file" \
|
|
|
|
"$dir" \
|
|
|
|
"$name" \
|
|
|
|
"$winPath"
|
|
|
|
|
|
|
|
mkdir -p (dirname "$file")
|
|
|
|
|
|
|
|
if [ ! -f "$file" ]
|
|
|
|
curl -L "$url" -o "$file"
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
set -l tempDir (mktemp -d)
|
|
|
|
|
|
|
|
switch $type
|
|
|
|
case zip
|
|
|
|
unzip "$file" -d "$tempDir"
|
|
|
|
case exe
|
|
|
|
pushd "$tempDir" > /dev/null
|
|
|
|
7z x "$file"
|
|
|
|
popd > /dev/null
|
|
|
|
end
|
|
|
|
|
|
|
|
mkdir -p (dirname "$target")
|
|
|
|
cp -r "$tempDir/$dir" "$target"
|
|
|
|
rm -rf "$tempDir"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
set -l intel $files[1..4]
|
|
|
|
set -l marvell $files[5..8]
|
|
|
|
set -l git $files[9..12]
|
|
|
|
set -l pwsh $files[13..16]
|
|
|
|
|
2024-07-27 22:28:10 +00:00
|
|
|
cp -r "$dir/winpefs"/* "$winpeOverlay"
|
2024-07-24 22:03:35 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
set -l startupFile "$winpeOverlay/Windows/System32/startnet.cmd"
|
|
|
|
mkdir -p (dirname "$startupFile")
|
|
|
|
|
|
|
|
begin
|
|
|
|
set -l path
|
|
|
|
|
|
|
|
for sw in git pwsh
|
|
|
|
set -a path $$sw[1][4]
|
|
|
|
end
|
|
|
|
|
|
|
|
printf %s\n \
|
2024-07-26 12:29:45 +00:00
|
|
|
"@echo off" (
|
2024-07-24 22:03:35 +00:00
|
|
|
string join ";" \
|
|
|
|
"set PATH=%PATH%" \
|
|
|
|
$path \
|
|
|
|
"$git[4]\\bin"
|
|
|
|
) \
|
2024-07-26 12:46:58 +00:00
|
|
|
"set SETUP_LABEL=$setupLabel" \
|
2024-07-26 12:29:45 +00:00
|
|
|
"set LOCAL_PROJECT_PATH=$(echo "$localProjectPath" | mkWinPath)" \
|
|
|
|
"set REMOTE_PROJECT_PATH=$(echo "$projectPath" | mkWinPath)" \
|
|
|
|
"echo Loading Drivers..." \
|
2024-07-24 22:03:35 +00:00
|
|
|
'pwsh -file "X:\Scripts\Drivers.ps1"' \
|
|
|
|
"echo Configuring Network..." \
|
|
|
|
"wpeinit" \
|
|
|
|
"echo Configuring keyboard layout..." \
|
|
|
|
"wpeutil SetKeyboardLayout 0807:00000807" \
|
|
|
|
"echo Disabling Energy Saving Mode..." \
|
|
|
|
"powercfg /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c" \
|
|
|
|
'start pwsh -NoExit -ExecutionPolicy bypass -file "X:\Scripts\Startup.ps1"'
|
|
|
|
end | sudo tee "$startupFile" > /dev/null
|
|
|
|
end
|
|
|
|
|
|
|
|
mkdir -p "$(dirname "$winpe")"
|
|
|
|
sudo mount --mkdir "$WIN11_IMAGE_PATH" "$winPath"
|
|
|
|
mkwinpeimg --iso --arch amd64 --overlay "$winpeOverlay" --windows-dir "$winPath" "$winpe"
|
|
|
|
sudo mount --mkdir "$winpe" "$winpePath"
|
|
|
|
|
|
|
|
begin
|
|
|
|
echo "$wimFile"
|
|
|
|
end | rsync --files-from=/dev/stdin "$winPath" "$winOverlay"
|
|
|
|
|
|
|
|
begin
|
|
|
|
set -l wimFile "$winOverlay/$wimFile"
|
|
|
|
|
|
|
|
while [ ! (wiminfo "$wimFile" 1 | grep "^$editionField" | cut -d ":" -f2 | string trim) = "Professional" ]
|
|
|
|
sudo wimdelete --soft "$wimFile" 1
|
|
|
|
end
|
|
|
|
|
|
|
|
while wiminfo "$wimFile" 2 &> /dev/null
|
|
|
|
sudo wimdelete --soft "$wimFile" 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-07-26 11:32:37 +00:00
|
|
|
begin
|
2024-07-26 12:29:45 +00:00
|
|
|
set -l projectPath "$winOverlay/$localProjectPath"
|
|
|
|
set -l rootDir "$projectPath"
|
|
|
|
|
|
|
|
while [ ! -d "$rootDir" ]
|
|
|
|
set rootDir (dirname "$rootDir")
|
|
|
|
end
|
|
|
|
|
|
|
|
chmod u+w "$rootDir"
|
2024-07-26 11:32:37 +00:00
|
|
|
mkdir -p "$projectPath"
|
|
|
|
source "$dir/../scripts/copy-repo.fish" "$projectPath"
|
|
|
|
rm -rf "$projectPath/archiso"
|
2024-07-28 09:26:13 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
source "$dir/../scripts/Common/Scripts/config.fish"
|
|
|
|
|
|
|
|
find "$projectPath/profiles" -type f -name "*.nix" | while read -l file
|
|
|
|
set -l CONFIG_MODULE "$file"
|
|
|
|
getConfig "valhalla.windows" --json > "$file.json"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-07-26 12:29:45 +00:00
|
|
|
chmod -R u-w "$rootDir"
|
2024-07-26 11:32:37 +00:00
|
|
|
end
|
|
|
|
|
2024-07-24 22:03:35 +00:00
|
|
|
sudo mount --mkdir -t overlay overlay -o lowerdir="$winOverlay":"$winpePath":"$winPath",upperdir="$upperDir",workdir="$workDir" "$valhallaPath"
|
|
|
|
|
|
|
|
if [ -z "$_flag_usb" ]
|
2024-07-27 20:04:08 +00:00
|
|
|
set -l isoFile "$(status dirname)/build/winiso-valhalla.iso"
|
2024-07-27 20:04:40 +00:00
|
|
|
mkdir -p (dirname "$isoFile")
|
2024-07-27 20:04:08 +00:00
|
|
|
|
2024-07-24 22:03:35 +00:00
|
|
|
mkisofs \
|
|
|
|
-V "$setupLabel" \
|
|
|
|
-no-emul-boot \
|
|
|
|
-b "efi/microsoft/boot/efisys.bin" \
|
|
|
|
-iso-level 4 \
|
|
|
|
-udf \
|
|
|
|
-joliet \
|
|
|
|
-disable-deep-relocation \
|
|
|
|
-omit-version-number \
|
|
|
|
-relaxed-filenames \
|
|
|
|
-output "$isoFile" \
|
|
|
|
"$valhallaPath"
|
|
|
|
else
|
2024-07-27 20:04:08 +00:00
|
|
|
set -l bootPath "/media/boot"
|
|
|
|
set -l dataPath "/media/data"
|
|
|
|
|
2024-07-25 18:02:47 +00:00
|
|
|
set -a mountPaths \
|
|
|
|
"$bootPath" \
|
|
|
|
"$dataPath"
|
|
|
|
|
|
|
|
|
2024-07-24 22:03:35 +00:00
|
|
|
if [ ! -b "$WIN_DISK" ]
|
|
|
|
chooseDisk WIN_DISK
|
|
|
|
end
|
|
|
|
|
|
|
|
sudo shred -vfzn 0 -s 512 "$WIN_DISK"
|
|
|
|
|
|
|
|
begin
|
|
|
|
printf %s\n \
|
|
|
|
o \
|
|
|
|
n \
|
|
|
|
"" \
|
|
|
|
"" \
|
|
|
|
"" \
|
|
|
|
+2G \
|
|
|
|
y \
|
|
|
|
t \
|
|
|
|
c \
|
|
|
|
a \
|
|
|
|
"" \
|
|
|
|
\
|
|
|
|
n \
|
|
|
|
"" \
|
|
|
|
"" \
|
|
|
|
"" \
|
|
|
|
"" \
|
|
|
|
y \
|
|
|
|
t \
|
|
|
|
"" \
|
|
|
|
7 \
|
|
|
|
\
|
|
|
|
w
|
|
|
|
end | sudo fdisk "$WIN_DISK"
|
|
|
|
|
|
|
|
begin
|
|
|
|
set -l disks
|
|
|
|
|
|
|
|
while true
|
|
|
|
set disks (string split -n " " (bash -c "echo $WIN_DISK*"))
|
|
|
|
[ (count $disks) -ge 3 ] && break
|
|
|
|
end
|
|
|
|
|
|
|
|
set -l bootDisk "$disks[2]"
|
|
|
|
set -l dataDisk "$disks[3]"
|
|
|
|
sudo mkfs.fat -F 32 -n "BOOT" "$bootDisk"
|
|
|
|
sudo mkfs.ntfs -fFL "$setupLabel" "$dataDisk"
|
|
|
|
sudo mount --mkdir "$bootDisk" "$bootPath"
|
|
|
|
sudo mount --mkdir "$dataDisk" "$dataPath"
|
|
|
|
sudo cp -r "$winpePath"/* "$bootPath"
|
|
|
|
|
|
|
|
sudo cp -r "$valhallaPath"/* "$dataPath"
|
|
|
|
sudo cp -r "$valhallaPath/efi" "$bootPath"
|
|
|
|
end
|
|
|
|
end
|
2024-07-25 18:02:47 +00:00
|
|
|
|
|
|
|
for path in $mountPaths
|
|
|
|
sudo umount -vf "$path"
|
|
|
|
end
|
|
|
|
|
|
|
|
for path in $mountPaths $tempPaths
|
|
|
|
sudo rm -rf "$path"
|
|
|
|
end
|
2024-07-24 22:03:35 +00:00
|
|
|
end
|