docker-windows/src/install.sh

135 lines
2.8 KiB
Bash
Raw Normal View History

2024-01-14 16:39:24 +01:00
#!/usr/bin/env bash
2024-01-14 15:19:58 +01:00
set -Eeuo pipefail
2024-01-17 01:38:23 +01:00
: "${EXTERNAL:="N"}"
2024-01-15 23:45:35 +01:00
: "${ATTENDED:="N"}"
2024-01-14 20:32:24 +01:00
: "${VERSION:="win11x64"}"
2024-01-17 01:38:23 +01:00
ARGUMENTS="-chardev socket,id=chrtpm,path=/dev/shm/emulated_tpm/swtpm-sock $ARGUMENTS"
ARGUMENTS="-tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis,tpmdev=tpm0 $ARGUMENTS"
[[ "${VERSION,,}" == "http"* ]] && EXTERNAL="Y"
MSG="Please wait while Windows is being started..."
if [ ! -f "$STORAGE/custom.iso" ]; then
if [[ "$EXTERNAL" != [Yy1]* ]]; then
if [ ! -f "$STORAGE/$VERSION.iso" ]; then
MSG="Please wait while Windows is being downloaded..."
fi
else
BASE=$(basename "$VERSION")
if [ ! -f "$STORAGE/$BASE" ]; then
MSG="Please wait while '$BASE' is being downloaded..."
fi
fi
fi
2024-01-16 19:58:55 +01:00
# Display wait message
/run/server.sh "Windows" "$MSG" &
2024-01-17 01:38:23 +01:00
BASE="custom.iso"
[ -f "$STORAGE/$BASE" ] && return 0
2024-01-14 15:19:58 +01:00
2024-01-17 01:38:23 +01:00
BASE="Custom.iso"
2024-01-14 16:35:58 +01:00
[ -f "$STORAGE/$BASE" ] && return 0
2024-01-14 15:19:58 +01:00
2024-01-17 01:38:23 +01:00
BASE="custom.ISO"
[ -f "$STORAGE/$BASE" ] && return 0
2024-01-16 23:26:46 +01:00
2024-01-17 01:38:23 +01:00
BASE="CUSTOM.iso"
[ -f "$STORAGE/$BASE" ] && return 0
2024-01-14 15:19:58 +01:00
2024-01-17 01:38:23 +01:00
BASE="CUSTOM.ISO"
[ -f "$STORAGE/$BASE" ] && return 0
2024-01-16 23:26:46 +01:00
2024-01-17 01:38:23 +01:00
if [[ "$EXTERNAL" != [Yy1]* ]]; then
BASE="$VERSION.iso"
2024-01-16 23:26:46 +01:00
else
2024-01-17 01:38:23 +01:00
BASE=$(basename "$VERSION")
2024-01-16 23:26:46 +01:00
2024-01-15 15:15:12 +01:00
fi
2024-01-14 15:19:58 +01:00
2024-01-17 01:38:23 +01:00
[ -f "$STORAGE/$BASE" ] && return 0
TMP="$STORAGE/tmp"
rm -rf "$TMP" && mkdir -p "$TMP"
ISO="$TMP/$BASE"
rm -f "$ISO"
if [[ "$EXTERNAL" != [Yy1]* ]]; then
2024-01-14 15:19:58 +01:00
2024-01-15 15:15:12 +01:00
SCRIPT="$TMP/mido.sh"
2024-01-14 15:19:58 +01:00
2024-01-16 23:26:46 +01:00
rm -f "$SCRIPT"
2024-01-15 15:15:12 +01:00
cp /run/mido.sh "$SCRIPT"
chmod +x "$SCRIPT"
cd "$TMP"
bash "$SCRIPT" "$VERSION"
rm -f "$SCRIPT"
2024-01-16 23:26:46 +01:00
cd /run
2024-01-15 15:15:12 +01:00
2024-01-17 01:38:23 +01:00
else
info "Downloading $BASE as boot image..."
# Check if running with interactive TTY or redirected to docker log
if [ -t 1 ]; then
PROGRESS="--progress=bar:noscroll"
else
PROGRESS="--progress=dot:giga"
fi
{ wget "$VERSION" -O "$ISO" -q --no-check-certificate --show-progress "$PROGRESS"; rc=$?; } || :
(( rc != 0 )) && error "Failed to download $VERSION, reason: $rc" && exit 60
2024-01-14 15:19:58 +01:00
2024-01-15 15:15:12 +01:00
fi
2024-01-17 01:38:23 +01:00
[ ! -f "$ISO" ] && error "Failed to download $VERSION" && exit 61
SIZE=$(stat -c%s "$ISO")
if ((SIZE<10000000)); then
error "Invalid ISO file: Size is smaller than 10 MB" && exit 62
fi
2024-01-15 23:45:35 +01:00
info "Preparing ISO image for installation..."
2024-01-14 15:19:58 +01:00
2024-01-15 15:15:12 +01:00
DIR="$TMP/unpack"
2024-01-16 23:26:46 +01:00
rm -rf "$DIR"
2024-01-17 01:38:23 +01:00
7z x "$ISO" -o"$DIR"
2024-01-15 23:45:35 +01:00
if [[ "$ATTENDED" != [Yy1]* ]]; then
2024-01-17 01:38:23 +01:00
if [[ "$EXTERNAL" != [Yy1]* ]]; then
if [ -f "/run/assets/$VERSION.xml" ]; then
2024-01-15 23:45:35 +01:00
2024-01-17 01:38:23 +01:00
wimlib-imagex update "$DIR/sources/boot.wim" 2 \
--command "add /run/assets/$VERSION.xml /autounattend.xml"
2024-01-15 23:45:35 +01:00
2024-01-17 01:38:23 +01:00
fi
2024-01-15 23:45:35 +01:00
fi
fi
2024-01-17 01:38:23 +01:00
LABEL="${BASE%.*}"
ISO="$TMP/$LABEL.tmp"
rm -f "$ISO"
2024-01-16 23:26:46 +01:00
2024-01-15 23:45:35 +01:00
genisoimage -b boot/etfsboot.com -no-emul-boot -c BOOT.CAT -iso-level 4 -J -l -D -N -joliet-long -relaxed-filenames \
2024-01-16 02:49:50 +01:00
-v -V "$LABEL" -udf -boot-info-table -eltorito-alt-boot -eltorito-boot efi/microsoft/boot/efisys_noprompt.bin \
2024-01-17 01:38:23 +01:00
-no-emul-boot -o "$ISO" -allow-limited-size "$DIR"
mv "$ISO" "$STORAGE/$BASE"
2024-01-14 15:19:58 +01:00
2024-01-15 15:15:12 +01:00
rm -rf "$TMP"
2024-01-14 15:19:58 +01:00
return 0