feat: Allow removal of ISO

This commit is contained in:
Kroese 2024-01-24 01:29:16 +01:00 committed by GitHub
parent 0fcac03812
commit c7fd8bae36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -45,6 +45,68 @@ CUSTOM="custom.iso"
[ ! -f "$STORAGE/$CUSTOM" ] && CUSTOM="custom.IMG" [ ! -f "$STORAGE/$CUSTOM" ] && CUSTOM="custom.IMG"
[ ! -f "$STORAGE/$CUSTOM" ] && CUSTOM="CUSTOM.IMG" [ ! -f "$STORAGE/$CUSTOM" ] && CUSTOM="CUSTOM.IMG"
replaceXML() {
local dir="$1"
local asset="$2"
local path="$dir/autounattend.xml"
[ -f "$path" ] && mv -f "$asset" "$path"
path="$dir/Autounattend.xml"
[ -f "$path" ] && mv -f "$asset" "$path"
path="$dir/AutoUnattend.xml"
[ -f "$path" ] && mv -f "$asset" "$path"
path="$dir/autounattend.XML"
[ -f "$path" ] && mv -f "$asset" "$path"
path="$dir/Autounattend.XML"
[ -f "$path" ] && mv -f "$asset" "$path"
path="$dir/AutoUnattend.XML"
[ -f "$path" ] && mv -f "$asset" "$path"
path="$dir/AUTOUNATTEND.xml"
[ -f "$path" ] && mv -f "$asset" "$path"
path="$dir/AUTOUNATTEND.XML"
[ -f "$path" ] && mv -f "$asset" "$path"
return 0
}
hasDisk() {
[ -b "${DEVICE:-}" ] && return 1
if [ -f "$STORAGE/data.img" ] || [ -f "$STORAGE/data.qcow2" ]; then
return 1
fi
return 0
}
skipInstall() {
if hasDisk && [ -f "$STORAGE/windows.boot" ]; then
return 1
fi
return 0
}
TMP="$STORAGE/tmp"
finishInstall() {
local iso="$1"
# Mark ISO as prepared via magic byte
printf '\x16' | dd of="$iso" bs=1 seek=0 count=1 conv=notrunc status=none
rm -f "$STORAGE/windows.ver"
rm -f "$STORAGE/windows.boot"
cp /run/version "$STORAGE/windows.ver"
rm -rf "$TMP"
return 0
}
MSG="Windows is being started, please wait..." MSG="Windows is being started, please wait..."
if [ -f "$STORAGE/$CUSTOM" ]; then if [ -f "$STORAGE/$CUSTOM" ]; then
@ -66,7 +128,7 @@ else
BASE="$VERSION.iso" BASE="$VERSION.iso"
if [ ! -f "$STORAGE/$BASE" ]; then if !skipInstall && [ ! -f "$STORAGE/$BASE" ]; then
MSG="Windows is being downloaded, please wait..." MSG="Windows is being downloaded, please wait..."
fi fi
@ -76,7 +138,7 @@ else
: "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}" : "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}"
BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g') BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g')
if [ ! -f "$STORAGE/$BASE" ]; then if !skipInstall && [ ! -f "$STORAGE/$BASE" ]; then
MSG="Image '$BASE' is being downloaded, please wait..." MSG="Image '$BASE' is being downloaded, please wait..."
fi fi
@ -88,7 +150,6 @@ fi
html "$MSG" html "$MSG"
TMP="$STORAGE/tmp"
[ -z "$MANUAL" ] && MANUAL="N" [ -z "$MANUAL" ] && MANUAL="N"
if [ -f "$STORAGE/$BASE" ]; then if [ -f "$STORAGE/$BASE" ]; then
@ -99,19 +160,7 @@ if [ -f "$STORAGE/$BASE" ]; then
if [[ "$MAGIC" == "16" ]]; then if [[ "$MAGIC" == "16" ]]; then
if [[ "$MANUAL" = [Yy1]* ]]; then if hasDisk || [[ "$MANUAL" = [Yy1]* ]]; then
rm -rf "$TMP"
return 0
fi
FOUND="N"
if [ -f "$STORAGE/data.img" ] || [ -f "$STORAGE/data.qcow2" ]; then
FOUND="Y"
else
[ -b "${DEVICE:-}" ] && FOUND="Y"
fi
if [[ "$FOUND" == "Y" ]]; then
rm -rf "$TMP" rm -rf "$TMP"
return 0 return 0
fi fi
@ -121,6 +170,14 @@ if [ -f "$STORAGE/$BASE" ]; then
EXTERNAL="Y" EXTERNAL="Y"
CUSTOM="$BASE" CUSTOM="$BASE"
else
if skipInstall; then
BASE=""
rm -rf "$TMP"
return 0
fi
fi fi
mkdir -p "$TMP" mkdir -p "$TMP"
@ -202,20 +259,31 @@ if [ ! -f "$DIR/$ETFS" ] || [ ! -f "$DIR/$EFISYS" ]; then
warn "failed to locate file 'efisys_noprompt.bin' in ISO image, $FB" warn "failed to locate file 'efisys_noprompt.bin' in ISO image, $FB"
fi fi
# Mark ISO as prepared via magic byte
printf '\x16' | dd of="$ISO" bs=1 seek=0 count=1 conv=notrunc status=none
[[ "$ISO" != "$STORAGE/$BASE" ]] && mv -f "$ISO" "$STORAGE/$BASE" [[ "$ISO" != "$STORAGE/$BASE" ]] && mv -f "$ISO" "$STORAGE/$BASE"
rm -f "$STORAGE/windows.ver" finishInstall "$STORAGE/$BASE"
cp /run/version "$STORAGE/windows.ver"
rm -rf "$TMP"
return 0 return 0
fi fi
[ -z "$CUSTOM" ] && rm -f "$ISO" [ -z "$CUSTOM" ] && rm -f "$ISO"
findVersion() {
local name="$1"
local detected=""
[[ "${name,,}" == *"windows 11"* ]] && detected="win11x64"
[[ "${name,,}" == *"windows 10"* ]] && detected="win10x64"
[[ "${name,,}" == *"windows 8"* ]] && detected="win81x64"
[[ "${name,,}" == *"server 2022"* ]] && detected="win2022-eval"
[[ "${name,,}" == *"server 2019"* ]] && detected="win2019-eval"
[[ "${name,,}" == *"server 2016"* ]] && detected="win2016-eval"
echo "$detected"
return 0
}
XML="" XML=""
if [[ "$MANUAL" != [Yy1]* ]]; then if [[ "$MANUAL" != [Yy1]* ]]; then
@ -234,30 +302,17 @@ if [[ "$MANUAL" != [Yy1]* ]]; then
if [ -f "$LOC" ]; then if [ -f "$LOC" ]; then
DETECTED=""
TAG="DISPLAYNAME" TAG="DISPLAYNAME"
RESULT=$(wimlib-imagex info -xml "$LOC" | tr -d '\000') RESULT=$(wimlib-imagex info -xml "$LOC" | tr -d '\000')
NAME=$(sed -n "/$TAG/{s/.*<$TAG>\(.*\)<\/$TAG>.*/\1/;p}" <<< "$RESULT") NAME=$(sed -n "/$TAG/{s/.*<$TAG>\(.*\)<\/$TAG>.*/\1/;p}" <<< "$RESULT")
DETECTED=$(findVersion "$NAME")
[[ "${NAME,,}" == *"windows 11"* ]] && DETECTED="win11x64"
[[ "${NAME,,}" == *"windows 10"* ]] && DETECTED="win10x64"
[[ "${NAME,,}" == *"windows 8"* ]] && DETECTED="win81x64"
[[ "${NAME,,}" == *"server 2022"* ]] && DETECTED="win2022-eval"
[[ "${NAME,,}" == *"server 2019"* ]] && DETECTED="win2019-eval"
[[ "${NAME,,}" == *"server 2016"* ]] && DETECTED="win2016-eval"
if [ -z "$DETECTED" ]; then if [ -z "$DETECTED" ]; then
TAG="PRODUCTNAME" TAG="PRODUCTNAME"
NAME2=$(sed -n "/$TAG/{s/.*<$TAG>\(.*\)<\/$TAG>.*/\1/;p}" <<< "$RESULT") NAME2=$(sed -n "/$TAG/{s/.*<$TAG>\(.*\)<\/$TAG>.*/\1/;p}" <<< "$RESULT")
[ -z "$NAME" ] && NAME="$NAME2" [ -z "$NAME" ] && NAME="$NAME2"
DETECTED=$(findVersion "$NAME2")
[[ "${NAME2,,}" == *"windows 11"* ]] && DETECTED="win11x64"
[[ "${NAME2,,}" == *"windows 10"* ]] && DETECTED="win10x64"
[[ "${NAME2,,}" == *"windows 8"* ]] && DETECTED="win81x64"
[[ "${NAME2,,}" == *"server 2022"* ]] && DETECTED="win2022-eval"
[[ "${NAME2,,}" == *"server 2019"* ]] && DETECTED="win2019-eval"
[[ "${NAME2,,}" == *"server 2016"* ]] && DETECTED="win2016-eval"
fi fi
@ -293,22 +348,7 @@ ASSET="/run/assets/$XML"
if [ -f "$ASSET" ]; then if [ -f "$ASSET" ]; then
LOC="$DIR/autounattend.xml" replaceXML "$DIR" "$ASSET"
[ -f "$LOC" ] && mv -f "$ASSET" "$LOC"
LOC="$DIR/Autounattend.xml"
[ -f "$LOC" ] && mv -f "$ASSET" "$LOC"
LOC="$DIR/AutoUnattend.xml"
[ -f "$LOC" ] && mv -f "$ASSET" "$LOC"
LOC="$DIR/autounattend.XML"
[ -f "$LOC" ] && mv -f "$ASSET" "$LOC"
LOC="$DIR/Autounattend.XML"
[ -f "$LOC" ] && mv -f "$ASSET" "$LOC"
LOC="$DIR/AutoUnattend.XML"
[ -f "$LOC" ] && mv -f "$ASSET" "$LOC"
LOC="$DIR/AUTOUNATTEND.xml"
[ -f "$LOC" ] && mv -f "$ASSET" "$LOC"
LOC="$DIR/AUTOUNATTEND.XML"
[ -f "$LOC" ] && mv -f "$ASSET" "$LOC"
LOC="$DIR/sources/boot.wim" LOC="$DIR/sources/boot.wim"
[ ! -f "$LOC" ] && LOC="$DIR/sources/boot.esd" [ ! -f "$LOC" ] && LOC="$DIR/sources/boot.esd"
@ -355,9 +395,6 @@ info "$MSG" && html "$MSG"
genisoimage -b "$ETFS" -no-emul-boot -c "$CAT" -iso-level 4 -J -l -D -N -joliet-long -relaxed-filenames -quiet -V "$LABEL" -udf \ genisoimage -b "$ETFS" -no-emul-boot -c "$CAT" -iso-level 4 -J -l -D -N -joliet-long -relaxed-filenames -quiet -V "$LABEL" -udf \
-boot-info-table -eltorito-alt-boot -eltorito-boot "$EFISYS" -no-emul-boot -o "$OUT" -allow-limited-size "$DIR" -boot-info-table -eltorito-alt-boot -eltorito-boot "$EFISYS" -no-emul-boot -o "$OUT" -allow-limited-size "$DIR"
# Mark ISO as prepared via magic byte
printf '\x16' | dd of="$OUT" bs=1 seek=0 count=1 conv=notrunc status=none
[ -n "$CUSTOM" ] && rm -f "$STORAGE/$CUSTOM" [ -n "$CUSTOM" ] && rm -f "$STORAGE/$CUSTOM"
if [ -f "$STORAGE/$BASE" ]; then if [ -f "$STORAGE/$BASE" ]; then
@ -365,11 +402,7 @@ if [ -f "$STORAGE/$BASE" ]; then
fi fi
mv "$OUT" "$STORAGE/$BASE" mv "$OUT" "$STORAGE/$BASE"
finishInstall "$STORAGE/$BASE"
rm -f "$STORAGE/windows.ver"
cp /run/version "$STORAGE/windows.ver"
rm -rf "$TMP"
html "Successfully prepared image for installation..." html "Successfully prepared image for installation..."