Add a windows11 target that downloads the Windows 11 ISO with headless Chromium

Move the Node.js script and its dependencies into nodejs/ and let
download-images.sh call it for the image architecture.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
GuofangandClaude Sonnet 5.5 committed 2026-10-21 16:45:36 +08:00
1 parent 5e58722aca
commit 592c7294c3
6 files changed
+228 -3

No files matched your search

+49 -3
View File
@@ -130,7 +130,7 @@ force_download=false
usage() {
cat <<EOF
Usage: $(basename "$0") [--force] [all|debian13|almalinux10|fedora44|ubuntu2604|virtio-win|openssh-win] ...
Usage: $(basename "$0") [--force] [all|debian13|almalinux10|fedora44|ubuntu2604|virtio-win|openssh-win|windows11] ...
$(basename "$0") --print-path TARGET [--iso]
Download one or more shared VM images. With no arguments, all targets are
@@ -141,6 +141,10 @@ When aria2c is installed and an image has several mirrors, the image is
downloaded from all of them at once, with one connection per mirror.
Otherwise curl or wget downloads from the mirrors in order.
The windows11 target is not part of "all". It downloads the Windows 11 ISO for
the image architecture with nodejs/get-windows-iso-url.js, which needs Node.js,
\`npm ci\` in nodejs/ and an installed Chromium (see README.md).
--force removes existing files and partial downloads for the selected targets,
then downloads them again from the beginning.
--print-path prints only the absolute image path without downloading it.
@@ -206,7 +210,7 @@ fi
for target in "${targets[@]}"; do
case "$target" in
all|debian13|almalinux10|fedora44|ubuntu2604|virtio-win|openssh-win) ;;
all|debian13|almalinux10|fedora44|ubuntu2604|virtio-win|openssh-win|windows11) ;;
-h|--help) usage; exit 0 ;;
*) printf 'Error: unknown download target: %s\n' "$target" >&2; usage >&2; exit 2 ;;
esac
@@ -297,6 +301,9 @@ download_file() {
local destination="$3"
local checksum_algorithm="${4:-}"
local expected_checksum="${5:-}"
# Signed URLs change on every request; this key identifies the source for
# resuming a partial download instead of the URLs when it is given.
local source_key="${6:-}"
local partial="${destination}.part"
# Records how the partial file was started, so that a partial download is
# only resumed with the same downloader and URLs.
@@ -340,7 +347,7 @@ download_file() {
# aria2c fills a partial file out of order, so it must not be resumed by
# curl or wget, and vice versa.
download_state="$(printf '%s\n' "$downloader" "${urls[@]}")"
download_state="$(printf '%s\n' "$downloader" "${source_key:-${urls[@]}}")"
if [[ -e "$partial" ]]; then
if [[ ! -f "$partial_url" ]] || [[ "$(<"$partial_url")" != "$download_state" ]]; then
printf 'Download source changed; restarting partial download.\n'
@@ -386,6 +393,41 @@ download_file() {
printf 'Downloaded %s:\n%s\n' "$label" "$destination"
}
# The Microsoft download link is temporary, so it is fetched with headless
# Chromium only when no matching ISO exists yet. "all" does not include it.
download_windows_iso() {
local iso
local url
local name
if [[ "$force_download" == true ]]; then
printf 'Forcing a fresh download of the Windows 11 %s ISO.\n' "$windows_arch"
while iso="$(find_windows_image "$install_iso_dir" iso)"; do
rm -f -- "$iso"
done
fi
if iso="$(find_windows_image "$install_iso_dir" iso)"; then
printf 'Windows 11 %s ISO already exists; skipping:\n%s\n' "$windows_arch" "$iso"
return
fi
if ! command -v node >/dev/null 2>&1; then
printf 'Error: node is required to get the Windows 11 ISO URL.\n' >&2
exit 1
fi
url="$(node "${images_dir}/nodejs/get-windows-iso-url.js" --arch "$windows_arch")"
[[ -n "$url" ]] || { printf 'Error: no Windows 11 ISO URL.\n' >&2; exit 1; }
name="${url%%\?*}"
name="${name##*/}"
name="$(printf '%b' "${name//%/\\x}")"
download_file \
"Windows 11 ${windows_arch} ISO" \
"$url" \
"${install_iso_dir}/${name}" \
'' \
'' \
"$name"
}
if wants_target debian13; then
download_file \
'Debian 13 cloud image' \
@@ -435,3 +477,7 @@ if wants_target openssh-win; then
"$openssh_url" \
"$openssh_image"
fi
if [[ " ${targets[*]} " == *" windows11 "* ]]; then
download_windows_iso
fi