180 lines
5.1 KiB
Fish
180 lines
5.1 KiB
Fish
#!/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
|
|
|
|
set -l setupLabel "winiso-valhalla"
|
|
set -l buildDir "$(status dirname)/build"
|
|
set -l cacheDir ~/.cache/winiso-valhalla
|
|
set -l isoFile "$buildDir/win.iso"
|
|
set -l winPath "/media/win"
|
|
set -l bootPath "/media/boot"
|
|
set -l dataPath "/media/data"
|
|
set -l winpeOverlay (mktemp -d)
|
|
set -l editionField "Edition ID"
|
|
set -l wimFile "$dataPath/sources/install.wim"
|
|
|
|
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]"
|
|
set -l downloadPath "$cacheDir/$name.$type"
|
|
|
|
set -a files \
|
|
"$downloadPath" \
|
|
"$dir" \
|
|
"$name"
|
|
|
|
mkdir -p (dirname "$downloadPath")
|
|
|
|
if [ ! -f "$downloadPath" ]
|
|
curl -L "$url" -o "$downloadPath"
|
|
end
|
|
end
|
|
|
|
set -l intel $files[1..3]
|
|
set -l marvell $files[4..6]
|
|
set -l git $files[7..9]
|
|
set -l pwsh $files[10..12]
|
|
|
|
cp -r "$dir/winfs"/* "$winpeOverlay"
|
|
mkdir -p "$winpeOverlay/drivers"
|
|
|
|
begin
|
|
set -l tempDir (mktemp -d)
|
|
unzip "$intel[1]" -d "$tempDir"
|
|
mkdir -p (dirname "$winpeOverlay/$intel[3]")
|
|
cp -r "$tempDir/$intel[2]" "$winpeOverlay/$intel[3]"
|
|
rm -rf "$tempDir"
|
|
end
|
|
|
|
begin
|
|
set -l tempDir (mktemp -d)
|
|
unzip "$marvell[1]" -d "$tempDir"
|
|
mkdir -p (dirname "$winpeOverlay/$marvell[3]")
|
|
cp -r "$tempDir/$marvell[2]" "$winpeOverlay/$marvell[3]"
|
|
rm -rf "$tempDir"
|
|
end
|
|
|
|
begin
|
|
set -l tempDir (mktemp -d)
|
|
pushd "$tempDir" > /dev/null
|
|
7z x "$git[1]"
|
|
popd > /dev/null
|
|
mkdir -p (dirname "$winpeOverlay/$git[3]")
|
|
cp -r "$tempDir/$git[2]" "$winpeOverlay/$git[3]"
|
|
rm -rf "$tempDir"
|
|
end
|
|
|
|
begin
|
|
set -l tempDir (mktemp -d)
|
|
unzip "$pwsh[1]" -d "$tempDir"
|
|
mkdir -p (dirname "$winpeOverlay/$pwsh[3]")
|
|
cp -r "$tempDir/$pwsh[2]" "$winpeOverlay/$pwsh[3]"
|
|
rm -rf "$tempDir"
|
|
end
|
|
|
|
mkdir -p "$(dirname "$isoFile")"
|
|
sudo mount --mkdir "$WIN11_IMAGE_PATH" "$winPath"
|
|
mkwinpeimg --iso --arch amd64 --overlay "$winpeOverlay" --windows-dir "$winPath" "$isoFile"
|
|
sudo umount "$winPath"
|
|
rm -rf "$winpeOverlay"
|
|
|
|
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 mount --mkdir "$isoFile" "$winPath"
|
|
sudo cp -r "$winPath"/* "$bootPath"
|
|
sudo umount "$winPath"
|
|
|
|
sudo mount "$WIN11_IMAGE_PATH" "$winPath"
|
|
sudo cp -r "$winPath"/* "$dataPath"
|
|
sudo cp -r "$winPath/efi" "$bootPath"
|
|
|
|
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
|
|
|
|
sudo -- bash -c "umount -vf $(string escape "$winPath"); umount -vf $(string escape "$bootPath"); umount -vf $(string escape "$dataPath"); rm -rf $(string escape "$winPath") $(string escape "$dataPath");"
|
|
end
|
|
end
|