mirror of
https://github.com/dockur/windows.git
synced 2025-10-27 03:15:49 +00:00
feat: Download custom ISO
This commit is contained in:
parent
3c066244ae
commit
b4ca5550c7
1 changed files with 85 additions and 31 deletions
110
src/install.sh
110
src/install.sh
|
|
@ -1,41 +1,70 @@
|
|||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
: "${EXTERNAL:="N"}"
|
||||
: "${ATTENDED:="N"}"
|
||||
: "${VERSION:="win11x64"}"
|
||||
|
||||
# Display wait message
|
||||
MSG="Please wait while Windows is being downloaded..."
|
||||
/run/server.sh "Windows" "$MSG" &
|
||||
|
||||
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"
|
||||
|
||||
BASE="$VERSION.iso"
|
||||
[[ "${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
|
||||
|
||||
# Display wait message
|
||||
/run/server.sh "Windows" "$MSG" &
|
||||
|
||||
BASE="custom.iso"
|
||||
[ -f "$STORAGE/$BASE" ] && return 0
|
||||
|
||||
#if [ -f "$STORAGE/data.qcow2" ]; then
|
||||
# error "Cannot download ISO '$VERSION' while there is an existing hard disk file present (data.qcow2)."
|
||||
# error "If you are sure that the disk contains nothing important, delete it manually and restart the container."
|
||||
# exit 68
|
||||
#fi
|
||||
BASE="Custom.iso"
|
||||
[ -f "$STORAGE/$BASE" ] && return 0
|
||||
|
||||
BASE="custom.ISO"
|
||||
[ -f "$STORAGE/$BASE" ] && return 0
|
||||
|
||||
BASE="CUSTOM.iso"
|
||||
[ -f "$STORAGE/$BASE" ] && return 0
|
||||
|
||||
BASE="CUSTOM.ISO"
|
||||
[ -f "$STORAGE/$BASE" ] && return 0
|
||||
|
||||
if [[ "$EXTERNAL" != [Yy1]* ]]; then
|
||||
|
||||
BASE="$VERSION.iso"
|
||||
|
||||
else
|
||||
|
||||
BASE=$(basename "$VERSION")
|
||||
|
||||
fi
|
||||
|
||||
[ -f "$STORAGE/$BASE" ] && return 0
|
||||
|
||||
TMP="$STORAGE/tmp"
|
||||
rm -rf "$TMP" && mkdir -p "$TMP"
|
||||
|
||||
if [ -f "$STORAGE/custom.iso" ]; then
|
||||
ISO="$TMP/$BASE"
|
||||
rm -f "$ISO"
|
||||
|
||||
ATTENDED="Y"
|
||||
LABEL="Custom"
|
||||
cp "$STORAGE/custom.iso" "$TMP/$BASE"
|
||||
|
||||
else
|
||||
|
||||
LABEL="$VERSION"
|
||||
|
||||
fi
|
||||
|
||||
if [ ! -f "$TMP/$BASE" ]; then
|
||||
if [[ "$EXTERNAL" != [Yy1]* ]]; then
|
||||
|
||||
SCRIPT="$TMP/mido.sh"
|
||||
|
||||
|
|
@ -47,8 +76,29 @@ if [ ! -f "$TMP/$BASE" ]; then
|
|||
rm -f "$SCRIPT"
|
||||
cd /run
|
||||
|
||||
[ ! -f "$TMP/$BASE" ] && error "Failed to download '$VERSION' from the Microsoft servers!" && exit 66
|
||||
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
|
||||
|
||||
fi
|
||||
|
||||
[ ! -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
|
||||
|
||||
info "Preparing ISO image for installation..."
|
||||
|
|
@ -56,9 +106,10 @@ info "Preparing ISO image for installation..."
|
|||
DIR="$TMP/unpack"
|
||||
rm -rf "$DIR"
|
||||
|
||||
7z x "$TMP/$BASE" -o"$DIR"
|
||||
7z x "$ISO" -o"$DIR"
|
||||
|
||||
if [[ "$ATTENDED" != [Yy1]* ]]; then
|
||||
if [[ "$EXTERNAL" != [Yy1]* ]]; then
|
||||
if [ -f "/run/assets/$VERSION.xml" ]; then
|
||||
|
||||
wimlib-imagex update "$DIR/sources/boot.wim" 2 \
|
||||
|
|
@ -66,15 +117,18 @@ if [[ "$ATTENDED" != [Yy1]* ]]; then
|
|||
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
OUT="$TMP/$VERSION.tmp"
|
||||
rm -f "$OUT"
|
||||
LABEL="${BASE%.*}"
|
||||
ISO="$TMP/$LABEL.tmp"
|
||||
rm -f "$ISO"
|
||||
|
||||
genisoimage -b boot/etfsboot.com -no-emul-boot -c BOOT.CAT -iso-level 4 -J -l -D -N -joliet-long -relaxed-filenames \
|
||||
-v -V "$LABEL" -udf -boot-info-table -eltorito-alt-boot -eltorito-boot efi/microsoft/boot/efisys_noprompt.bin \
|
||||
-no-emul-boot -o "$OUT" -allow-limited-size "$DIR"
|
||||
-no-emul-boot -o "$ISO" -allow-limited-size "$DIR"
|
||||
|
||||
mv "$ISO" "$STORAGE/$BASE"
|
||||
|
||||
mv "$OUT" "$STORAGE/$BASE"
|
||||
rm -rf "$TMP"
|
||||
|
||||
return 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue