2024-07-23 07:14:05 +00:00
|
|
|
#!/bin/env fish
|
|
|
|
begin
|
|
|
|
set -l dir (status dirname)
|
|
|
|
source "$dir/lib/choose-disk.fish"
|
|
|
|
|
2024-07-22 15:47:59 +00:00
|
|
|
set -l setupLabel "winiso-valhalla"
|
2024-07-23 07:14:05 +00:00
|
|
|
set -l buildDir "$(status dirname)/build"
|
2024-07-22 19:00:46 +00:00
|
|
|
set -l cacheDir ~/.cache/winiso-valhalla
|
2024-07-23 07:14:05 +00:00
|
|
|
set -l isoFile "$buildDir/win.iso"
|
|
|
|
set -l mountPath "/media/wininstall"
|
|
|
|
set -l bootPath "/media/boot"
|
|
|
|
set -l dataPath "/media/data"
|
|
|
|
set -l overlayDir (mktemp -d)
|
|
|
|
|
|
|
|
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 dir (status dirname)
|
|
|
|
set -l overlayDir (mktemp -d)
|
|
|
|
set -l editionField "Edition ID"
|
|
|
|
set -l wimFile "$dataPath/sources/install.wim"
|
|
|
|
|
2024-07-22 19:00:46 +00:00
|
|
|
set -l intelNetworkArchive "$cacheDir/intelNetwork.zip"
|
|
|
|
set -l marvellNetworkArchive "$cacheDir/marvellNetwork.zip"
|
|
|
|
set -l gitArchive (realpath -m "$cacheDir/git.msi")
|
|
|
|
set -l pwshArchive "$cacheDir/pwsh.zip"
|
2024-07-23 07:14:05 +00:00
|
|
|
|
|
|
|
mkdir -p "$buildDir"
|
|
|
|
cp -r "$dir/winfs"/* "$overlayDir"
|
|
|
|
|
|
|
|
if [ ! -f "$intelNetworkArchive" ]
|
|
|
|
curl -L "https://dlcdnets.asus.com/pub/ASUS/mb/04LAN/DRV_LAN_Intel_I211_UWD_TP_W10_64_VER12151841_20190306R.zip?model=ROG%20ZENITH%20EXTREME%20ALPHA" -o "$intelNetworkArchive"
|
|
|
|
end
|
|
|
|
|
|
|
|
if [ ! -f "$marvellNetworkArchive" ]
|
|
|
|
curl -L "https://dlcdnets.asus.com/pub/ASUS/mb/04LAN/DRV_LAN_Marvell_TP_TSD_W11_64_V3130_20211118R.zip?model=ROG%20ZENITH%20EXTREME%20ALPHA" -o "$marvellNetworkArchive"
|
|
|
|
end
|
|
|
|
|
|
|
|
if [ ! -f "$gitArchive" ]
|
|
|
|
curl -L "https://github.com/git-for-windows/git/releases/download/v2.41.0.windows.1/PortableGit-2.41.0-64-bit.7z.exe" -o "$gitArchive"
|
|
|
|
end
|
|
|
|
|
|
|
|
if [ ! -f "$pwshArchive" ]
|
|
|
|
curl -L "https://github.com/PowerShell/PowerShell/releases/download/v7.3.7/PowerShell-7.3.7-win-x64.zip" -o "$pwshArchive"
|
|
|
|
end
|
|
|
|
|
|
|
|
mkdir -p "$overlayDir/drivers"
|
|
|
|
|
|
|
|
begin
|
|
|
|
set -l tempDir (mktemp -d)
|
|
|
|
unzip "$intelNetworkArchive" -d "$tempDir"
|
|
|
|
cp -r "$tempDir" "$overlayDir/drivers/IntelNetwork"
|
|
|
|
rm -rf "$tempDir"
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
set -l tempDir (mktemp -d)
|
|
|
|
unzip "$marvellNetworkArchive" -d "$tempDir"
|
|
|
|
cp -r "$tempDir/x64" "$overlayDir/drivers/MarvellNetwork"
|
|
|
|
rm -rf "$tempDir"
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
set -l dir "$overlayDir/git"
|
|
|
|
mkdir -p "$dir"
|
|
|
|
pushd "$dir" > /dev/null
|
|
|
|
7z x "$gitArchive"
|
|
|
|
popd > /dev/null
|
|
|
|
end
|
|
|
|
|
|
|
|
unzip "$pwshArchive" -d "$overlayDir/PowerShell"
|
|
|
|
|
|
|
|
mkdir -p "$(dirname "$isoFile")"
|
|
|
|
sudo mount --mkdir "$WIN11_IMAGE_PATH" "$mountPath"
|
|
|
|
mkwinpeimg --iso --arch amd64 --overlay "$overlayDir" --windows-dir "$mountPath" "$isoFile"
|
|
|
|
sudo umount "$mountPath"
|
|
|
|
rm -rf "$overlayDir"
|
|
|
|
|
|
|
|
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" "$mountPath"
|
|
|
|
sudo cp -r "$mountPath"/* "$bootPath"
|
|
|
|
sudo umount "$mountPath"
|
|
|
|
|
|
|
|
sudo mount "$WIN11_IMAGE_PATH" "$mountPath"
|
|
|
|
sudo cp -r "$mountPath"/* "$dataPath"
|
|
|
|
sudo cp -r "$mountPath/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 "$mountPath"); umount -vf $(string escape "$bootPath"); umount -vf $(string escape "$dataPath"); rm -rf $(string escape "$mountPath") $(string escape "$dataPath");"
|
|
|
|
end
|
|
|
|
end
|