Files
cloudhost/seediso/windows11/build-seed.sh
T
GuofangandClaude Sonnet 5.5 72af276309 Add an update-status tool and copy numbered scripts to Desktop\Tools
80-Get-UpdateStatus-Admin.ps1 prints whether the Windows 11 guest is
upgrading or downloading updates (policy, pending markers, services,
processes, BITS jobs, update events, network use); the .bat launcher
elevates and keeps the window open.

The seed ISO and Configure-Windows.ps1 now take every NN-*.bat and
NN-*.ps1, and the first-logon copy goes to Desktop\Tools instead of
Desktop\Installers.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-26 09:27:52 +08:00

64 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
output="${1:-${script_dir}/seed.iso}"
arch="${2:-${VM_IMAGE_ARCH:-$(uname -m)}}"
case "$arch" in
arm64|aarch64) answer_arch=arm64 ;;
x86_64|amd64) answer_arch=amd64 ;;
*) printf 'Error: unsupported architecture: %s\n' "$arch" >&2; exit 1 ;;
esac
# The OpenSSH zip for the target architecture comes from the shared image
# helper, which downloads it when missing.
image_helper="${VM_IMAGE_HELPER:-$script_dir/../../vm-images/download-images.sh}"
openssh_zip="$(VM_IMAGE_ARCH="$answer_arch" "$image_helper" --print-path openssh-win)"
[[ -s "$openssh_zip" ]] || VM_IMAGE_ARCH="$answer_arch" "$image_helper" openssh-win
[[ -s "$openssh_zip" ]] || { printf 'Error: %s was not downloaded.\n' "$openssh_zip" >&2; exit 1; }
# The public key for administrator SSH login: SSH_PUBLIC_KEY_FILE, else the
# first default key of the invoking user. The guest skips it when absent.
ssh_key="${SSH_PUBLIC_KEY_FILE:-}"
if [[ -z "$ssh_key" ]]; then
for candidate in "$HOME"/.ssh/id_ed25519.pub "$HOME"/.ssh/id_ecdsa.pub "$HOME"/.ssh/id_rsa.pub; do
[[ -f "$candidate" ]] && { ssh_key="$candidate"; break; }
done
fi
[[ -z "$ssh_key" || -f "$ssh_key" ]] || { printf 'Error: %s does not exist.\n' "$ssh_key" >&2; exit 1; }
# The answer file's components name the processor architecture, so render a
# copy for the target architecture.
work_dir="$(mktemp -d)"
trap 'rm -rf "$work_dir"' EXIT
sed "s/processorArchitecture=\"amd64\"/processorArchitecture=\"${answer_arch}\"/" \
"$script_dir/Autounattend.xml" >"$work_dir/Autounattend.xml"
seed_files=(
"$work_dir/Autounattend.xml"
"$script_dir/Configure-Windows.ps1"
"$openssh_zip"
)
if [[ -n "$ssh_key" ]]; then
cp -- "$ssh_key" "$work_dir/authorized_keys"
seed_files+=("$work_dir/authorized_keys")
fi
# Numbered scripts: installers (10-Install-Git-Admin.bat, 20-..., in install order)
# and tools (80-Get-UpdateStatus-Admin.bat/.ps1); all land in Desktop\Tools.
shopt -s nullglob
seed_files+=("$script_dir"/[0-9][0-9]-*.bat "$script_dir"/[0-9][0-9]-*.ps1)
shopt -u nullglob
mkdir -p "$(dirname -- "$output")"
if command -v xorriso >/dev/null 2>&1; then
xorriso -as mkisofs -quiet -o "$output" -V CIDATA -J -r "${seed_files[@]}"
elif command -v genisoimage >/dev/null 2>&1; then
genisoimage -quiet -o "$output" -V CIDATA -J -r "${seed_files[@]}"
elif command -v mkisofs >/dev/null 2>&1; then
mkisofs -quiet -o "$output" -V CIDATA -J -r "${seed_files[@]}"
else
printf 'Error: install xorriso, genisoimage, or mkisofs.\n' >&2
exit 1
fi
printf 'Built Windows 11 answer-file ISO: %s\n' "$output"