2024-07-24 22:03:35 +00:00
|
|
|
#!/bin/env fish
|
|
|
|
begin
|
2024-09-03 10:08:47 +00:00
|
|
|
set -l varName WIN11_IMAGE_PATH
|
|
|
|
set -l $varName
|
2024-07-24 22:03:35 +00:00
|
|
|
set -l dir (status dirname)
|
|
|
|
source "$dir/lib/choose-disk.fish"
|
2024-09-22 16:52:06 +00:00
|
|
|
source "$dir/lib/confirm.fish"
|
2024-09-03 10:08:47 +00:00
|
|
|
set $varName (bash -c ". $(string escape $dir)/.env; echo \$$varName" 2> /dev/null)
|
2024-07-24 22:03:35 +00:00
|
|
|
|
2024-09-03 10:08:47 +00:00
|
|
|
[ ! -z "$$varName" ]
|
2024-07-24 22:03:35 +00:00
|
|
|
or begin
|
2024-09-03 10:08:47 +00:00
|
|
|
if [ ! -f "$dir/.env" ]
|
|
|
|
cp $dir/.env.template $dir/.env
|
|
|
|
end
|
|
|
|
|
|
|
|
echo "Please epecify the path to the Windows 11 ISO image in your .env file located at:"
|
|
|
|
realpath --relative-to (pwd) (realpath $dir/.env)
|
2024-07-24 22:03:35 +00:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
2024-07-26 12:29:45 +00:00
|
|
|
function mkWinPath
|
|
|
|
sed "s/\//\\\\/g"
|
|
|
|
end
|
|
|
|
|
2024-10-06 19:25:34 +00:00
|
|
|
argparse --name (status filename) -x "iso,usb" iso usb debug -- $argv
|
2024-08-16 13:13:33 +00:00
|
|
|
or exit 1
|
|
|
|
|
2024-10-06 19:25:34 +00:00
|
|
|
set -l mountDir /mnt
|
|
|
|
set -l setupLabel winiso-valhalla
|
|
|
|
set -l projectPath PortValhalla
|
2024-07-31 12:47:42 +00:00
|
|
|
set -l systemDrivePath "sources/\$OEM\$/\$1"
|
2024-10-06 19:25:34 +00:00
|
|
|
set -l pwshPath pwsh
|
2024-07-31 12:47:42 +00:00
|
|
|
set -l localProjectPath "$systemDrivePath/$projectPath"
|
2024-07-24 22:03:35 +00:00
|
|
|
set -l cacheDir ~/.cache/winiso-valhalla
|
|
|
|
set -l winpe "$cacheDir/winpe.iso"
|
2024-08-27 02:30:12 +00:00
|
|
|
set -l winPath "$mountDir/win"
|
|
|
|
set -l winpePath "$mountDir/winpe"
|
|
|
|
set -l valhallaPath "$mountDir/winiso-valhalla"
|
2024-07-24 22:03:35 +00:00
|
|
|
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
|
|
|
|
|
2024-10-06 19:25:34 +00:00
|
|
|
set -l fileDefinitions (
|
|
|
|
# Intel LAN driver
|
|
|
|
) \
|
2024-07-24 22:03:35 +00:00
|
|
|
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 \
|
2024-10-06 19:25:34 +00:00
|
|
|
. (
|
|
|
|
# Marvell LAN driver
|
|
|
|
) \
|
2024-07-24 22:03:35 +00:00
|
|
|
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 \
|
2024-10-06 19:25:34 +00:00
|
|
|
./x64 (
|
|
|
|
# Git
|
|
|
|
) \
|
2024-07-24 22:03:35 +00:00
|
|
|
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 \
|
2024-10-06 19:25:34 +00:00
|
|
|
. (
|
|
|
|
# PowerShell Core
|
|
|
|
) \
|
2024-07-24 22:03:35 +00:00
|
|
|
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" \
|
2024-07-31 12:47:42 +00:00
|
|
|
"$target" \
|
2024-07-24 22:03:35 +00:00
|
|
|
"$winPath"
|
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and mkdir -p (dirname "$file")
|
2024-07-24 22:03:35 +00:00
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and if [ ! -f "$file" ]
|
2024-07-24 22:03:35 +00:00
|
|
|
curl -L "$url" -o "$file"
|
|
|
|
end
|
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and begin
|
2024-07-24 22:03:35 +00:00
|
|
|
set -l tempDir (mktemp -d)
|
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and switch $type
|
2024-07-24 22:03:35 +00:00
|
|
|
case zip
|
|
|
|
unzip "$file" -d "$tempDir"
|
|
|
|
case exe
|
2024-10-06 19:25:34 +00:00
|
|
|
pushd "$tempDir" >/dev/null
|
2024-09-22 22:14:10 +00:00
|
|
|
and 7z x "$file"
|
2024-10-06 19:25:34 +00:00
|
|
|
and popd >/dev/null
|
2024-07-24 22:03:35 +00:00
|
|
|
end
|
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and mkdir -p (dirname "$target")
|
|
|
|
and cp -r "$tempDir/$dir" "$target"
|
|
|
|
and rm -rf "$tempDir"
|
2024-07-24 22:03:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-07-31 12:47:42 +00:00
|
|
|
set -l intel $files[1..5]
|
|
|
|
set -l marvell $files[6..10]
|
|
|
|
set -l git $files[11..15]
|
|
|
|
set -l pwsh $files[16..20]
|
2024-07-24 22:03:35 +00:00
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and cp -r "$dir/winpefs"/* "$winpeOverlay"
|
2024-07-24 22:03:35 +00:00
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and begin
|
2024-07-24 22:03:35 +00:00
|
|
|
set -l startupFile "$winpeOverlay/Windows/System32/startnet.cmd"
|
2024-09-22 22:14:10 +00:00
|
|
|
and mkdir -p (dirname "$startupFile")
|
2024-07-24 22:03:35 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
set -l path
|
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and for sw in git pwsh
|
2024-07-31 12:47:42 +00:00
|
|
|
set -a path $$sw[1][5]
|
2024-07-24 22:03:35 +00:00
|
|
|
end
|
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and 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 \
|
2024-07-31 12:47:42 +00:00
|
|
|
"$git[5]\\bin"
|
2024-07-24 22:03:35 +00:00
|
|
|
) \
|
2024-07-26 12:46:58 +00:00
|
|
|
"set SETUP_LABEL=$setupLabel" \
|
2024-08-16 13:16:28 +00:00
|
|
|
(
|
|
|
|
begin
|
2024-08-16 14:10:09 +00:00
|
|
|
if [ -n "$_flag_debug" ]
|
2024-08-16 13:16:28 +00:00
|
|
|
echo "set DEBUG=1"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
) \
|
2024-07-31 12:47:42 +00:00
|
|
|
"set PWSH_PATH=$(echo "$pwshPath" | mkWinPath)" \
|
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..." \
|
2024-10-06 19:25:34 +00:00
|
|
|
wpeinit \
|
2024-07-24 22:03:35 +00:00
|
|
|
"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"'
|
2024-10-06 19:25:34 +00:00
|
|
|
end | sudo tee "$startupFile" >/dev/null
|
2024-07-24 22:03:35 +00:00
|
|
|
end
|
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and mkdir -p "$(dirname "$winpe")"
|
|
|
|
and sudo mount --mkdir $$varName "$winPath"
|
|
|
|
and mkwinpeimg --iso --arch amd64 --overlay "$winpeOverlay" --windows-dir "$winPath" "$winpe"
|
|
|
|
and sudo mount --mkdir "$winpe" "$winpePath"
|
2024-07-24 22:03:35 +00:00
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and begin
|
2024-07-24 22:03:35 +00:00
|
|
|
echo "$wimFile"
|
|
|
|
end | rsync --files-from=/dev/stdin "$winPath" "$winOverlay"
|
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and begin
|
2024-07-24 22:03:35 +00:00
|
|
|
set -l wimFile "$winOverlay/$wimFile"
|
2024-09-22 22:14:10 +00:00
|
|
|
and chmod u+w (dirname "$wimFile")
|
|
|
|
and chmod u+w "$wimFile"
|
2024-07-24 22:03:35 +00:00
|
|
|
|
2024-10-06 19:25:34 +00:00
|
|
|
and while [ ! (wiminfo "$wimFile" 1 | grep "^$editionField" | cut -d ":" -f2 | string trim) = Professional ]
|
2024-08-06 09:39:34 +00:00
|
|
|
wimdelete --soft "$wimFile" 1
|
2024-07-24 22:03:35 +00:00
|
|
|
end
|
|
|
|
|
2024-10-06 19:25:34 +00:00
|
|
|
and while wiminfo "$wimFile" 2 &>/dev/null
|
2024-08-06 09:39:34 +00:00
|
|
|
wimdelete --soft "$wimFile" 2
|
2024-07-24 22:03:35 +00:00
|
|
|
end
|
2024-07-28 22:10:07 +00:00
|
|
|
|
2024-09-25 17:55:24 +00:00
|
|
|
and wimoptimize "$wimFile" || true
|
2024-09-22 22:14:10 +00:00
|
|
|
and chmod u-w "$wimFile"
|
|
|
|
and chmod u-w (dirname "$wimFile")
|
2024-07-24 22:03:35 +00:00
|
|
|
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"
|
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and while [ ! -d "$rootDir" ]
|
2024-07-26 12:29:45 +00:00
|
|
|
set rootDir (dirname "$rootDir")
|
|
|
|
end
|
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and chmod u+w "$rootDir"
|
|
|
|
and mkdir -p "$projectPath"
|
|
|
|
and cp -r "$pwsh[4]" "$winOverlay/$systemDrivePath/$pwshPath"
|
2024-11-01 12:12:16 +00:00
|
|
|
and fish "$dir/../scripts/lib/copy-repo.fish" "$projectPath"
|
2024-09-22 22:14:10 +00:00
|
|
|
and rm -rf "$projectPath/archiso"
|
2024-07-28 09:26:13 +00:00
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and begin
|
2024-11-01 12:12:16 +00:00
|
|
|
source "$dir/../scripts/lib/settings.fish"
|
2024-07-28 09:26:13 +00:00
|
|
|
|
2024-12-05 15:34:24 +00:00
|
|
|
and for name in (getProfiles | jq '.[]' --raw-output0 | string split0 || true)
|
2024-09-08 15:09:01 +00:00
|
|
|
set -l CONFIG_NAME "$name"
|
|
|
|
set -l file "$projectPath/.config/$name.json"
|
2024-09-22 22:14:10 +00:00
|
|
|
and mkdir -p (dirname $file)
|
2024-10-06 19:25:34 +00:00
|
|
|
and getConfig "valhalla.windows.config" --json >"$file"
|
2024-07-28 09:26:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and chmod -R u-w "$rootDir"
|
2024-07-26 11:32:37 +00:00
|
|
|
end
|
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and sudo mount --mkdir -t overlay overlay -o lowerdir="$winOverlay":"$winpePath":"$winPath",upperdir="$upperDir",workdir="$workDir" "$valhallaPath"
|
2024-07-24 22:03:35 +00:00
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and if [ -z "$_flag_usb" ]
|
2024-07-27 20:04:08 +00:00
|
|
|
set -l isoFile "$(status dirname)/build/winiso-valhalla.iso"
|
2024-09-22 22:14:10 +00:00
|
|
|
and mkdir -p (dirname "$isoFile")
|
2024-07-27 20:04:08 +00:00
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and mkisofs \
|
2024-07-24 22:03:35 +00:00
|
|
|
-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-08-27 02:30:12 +00:00
|
|
|
set -l bootPath "$mountDir/boot"
|
|
|
|
set -l dataPath "$mountDir/data"
|
2024-07-27 20:04:08 +00:00
|
|
|
|
2024-07-25 18:02:47 +00:00
|
|
|
set -a mountPaths \
|
|
|
|
"$bootPath" \
|
|
|
|
"$dataPath"
|
|
|
|
|
2024-09-22 17:52:33 +00:00
|
|
|
chooseDisk winDisk
|
2024-09-22 22:14:10 +00:00
|
|
|
and echo "Proceeding will cause the disk `$winDisk` to be wiped."
|
2024-09-22 16:52:06 +00:00
|
|
|
|
2024-10-06 19:25:34 +00:00
|
|
|
and if ! confirm "Are you sure you want to continue?" n
|
2024-09-22 16:52:06 +00:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and sudo shred -vfzn 0 -s 512 "$winDisk"
|
2024-07-24 22:03:35 +00:00
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and begin
|
2024-07-24 22:03:35 +00:00
|
|
|
printf %s\n \
|
2024-09-22 19:45:50 +00:00
|
|
|
"label: dos" \
|
|
|
|
"size=+2G type=uefi" \
|
|
|
|
"type=07"
|
|
|
|
end | sudo sfdisk "$winDisk"
|
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and sudo partprobe
|
|
|
|
and sudo udevadm trigger
|
2024-07-24 22:03:35 +00:00
|
|
|
|
2024-09-22 22:14:10 +00:00
|
|
|
and begin
|
2024-07-24 22:03:35 +00:00
|
|
|
set -l disks
|
2024-09-22 17:52:33 +00:00
|
|
|
set -l diskPath (find -L /dev/disk/by-diskseq -samefile $winDisk)
|
|
|
|
set -l bootDisk "$diskPath-part1"
|
|
|
|
set -l dataDisk "$diskPath-part2"
|
2024-10-06 19:25:34 +00:00
|
|
|
and sudo mkfs.fat -F 32 -n BOOT "$bootDisk"
|
2024-09-22 22:14:10 +00:00
|
|
|
and sudo mkfs.ntfs -fFL "$setupLabel" "$dataDisk"
|
|
|
|
and sudo mount --mkdir "$bootDisk" "$bootPath"
|
|
|
|
and sudo mount --mkdir "$dataDisk" "$dataPath"
|
|
|
|
and sudo cp -r "$winpePath"/* "$bootPath"
|
|
|
|
|
|
|
|
and sudo cp -r "$valhallaPath"/* "$dataPath"
|
|
|
|
and sudo cp -r "$valhallaPath/efi" "$bootPath"
|
2024-07-24 22:03:35 +00:00
|
|
|
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
|