|
@@ -4,6 +4,10 @@ set -Eeuo pipefail
|
|
|
: "${MANUAL:=""}"
|
|
|
: "${VERSION:="win11x64"}"
|
|
|
|
|
|
+if [[ "${VERSION}" == \"*\" || "${VERSION}" == \'*\' ]]; then
|
|
|
+ VERSION="${VERSION:1:-1}"
|
|
|
+fi
|
|
|
+
|
|
|
[[ "${VERSION,,}" == "11" ]] && VERSION="win11x64"
|
|
|
[[ "${VERSION,,}" == "win11" ]] && VERSION="win11x64"
|
|
|
|
|
@@ -41,332 +45,405 @@ CUSTOM="custom.iso"
|
|
|
[ ! -f "$STORAGE/$CUSTOM" ] && CUSTOM="custom.IMG"
|
|
|
[ ! -f "$STORAGE/$CUSTOM" ] && CUSTOM="CUSTOM.IMG"
|
|
|
|
|
|
-MSG="Windows is being started, please wait..."
|
|
|
+TMP="$STORAGE/tmp"
|
|
|
+DIR="$TMP/unpack"
|
|
|
+FB="falling back to manual installation!"
|
|
|
+ETFS="boot/etfsboot.com"
|
|
|
+EFISYS="efi/microsoft/boot/efisys_noprompt.bin"
|
|
|
|
|
|
-if [ -f "$STORAGE/$CUSTOM" ]; then
|
|
|
+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"
|
|
|
|
|
|
- EXTERNAL="Y"
|
|
|
- BASE="$CUSTOM"
|
|
|
+ return 0
|
|
|
+}
|
|
|
|
|
|
-else
|
|
|
+hasDisk() {
|
|
|
|
|
|
- CUSTOM=""
|
|
|
+ [ -b "${DEVICE:-}" ] && return 0
|
|
|
|
|
|
- if [[ "${VERSION,,}" == "http"* ]]; then
|
|
|
- EXTERNAL="Y"
|
|
|
- else
|
|
|
- EXTERNAL="N"
|
|
|
+ if [ -f "$STORAGE/data.img" ] || [ -f "$STORAGE/data.qcow2" ]; then
|
|
|
+ return 0
|
|
|
fi
|
|
|
|
|
|
- if [[ "$EXTERNAL" != [Yy1]* ]]; then
|
|
|
+ return 1
|
|
|
+}
|
|
|
|
|
|
- BASE="$VERSION.iso"
|
|
|
+skipInstall() {
|
|
|
|
|
|
- if [ ! -f "$STORAGE/$BASE" ]; then
|
|
|
- MSG="Windows is being downloaded, please wait..."
|
|
|
- fi
|
|
|
+ if hasDisk && [ -f "$STORAGE/windows.boot" ]; then
|
|
|
+ return 0
|
|
|
+ fi
|
|
|
|
|
|
- else
|
|
|
+ return 1
|
|
|
+}
|
|
|
|
|
|
- BASE=$(basename "${VERSION%%\?*}")
|
|
|
- : "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}"
|
|
|
- BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g')
|
|
|
+finishInstall() {
|
|
|
|
|
|
- if [ ! -f "$STORAGE/$BASE" ]; then
|
|
|
- MSG="Image '$BASE' is being downloaded, please wait..."
|
|
|
- fi
|
|
|
+ local iso="$1"
|
|
|
|
|
|
- fi
|
|
|
+ # Mark ISO as prepared via magic byte
|
|
|
+ printf '\x16' | dd of="$iso" bs=1 seek=0 count=1 conv=notrunc status=none
|
|
|
|
|
|
- [[ "${BASE,,}" == "custom."* ]] && BASE="windows.iso"
|
|
|
+ rm -f "$STORAGE/windows.ver"
|
|
|
+ rm -f "$STORAGE/windows.boot"
|
|
|
+ cp /run/version "$STORAGE/windows.ver"
|
|
|
|
|
|
-fi
|
|
|
+ rm -rf "$TMP"
|
|
|
+ return 0
|
|
|
+}
|
|
|
|
|
|
-html "$MSG"
|
|
|
+startInstall() {
|
|
|
|
|
|
-TMP="$STORAGE/tmp"
|
|
|
-[ -z "$MANUAL" ] && MANUAL="N"
|
|
|
+ local msg="Windows is being started, please wait..."
|
|
|
|
|
|
-if [ -f "$STORAGE/$BASE" ]; then
|
|
|
+ if [ -f "$STORAGE/$CUSTOM" ]; then
|
|
|
|
|
|
- # Check if the ISO was already processed by our script
|
|
|
- MAGIC=$(dd if="$STORAGE/$BASE" seek=0 bs=1 count=1 status=none | tr -d '\000')
|
|
|
- MAGIC="$(printf '%s' "$MAGIC" | od -A n -t x1 -v | tr -d ' \n')"
|
|
|
+ EXTERNAL="Y"
|
|
|
+ BASE="$CUSTOM"
|
|
|
|
|
|
- if [[ "$MAGIC" == "16" ]]; then
|
|
|
+ else
|
|
|
|
|
|
- if [[ "$MANUAL" = [Yy1]* ]]; then
|
|
|
- rm -rf "$TMP"
|
|
|
- return 0
|
|
|
- fi
|
|
|
+ CUSTOM=""
|
|
|
|
|
|
- FOUND="N"
|
|
|
- if [ -f "$STORAGE/data.img" ] || [ -f "$STORAGE/data.qcow2" ]; then
|
|
|
- FOUND="Y"
|
|
|
+ if [[ "${VERSION,,}" == "http"* ]]; then
|
|
|
+ EXTERNAL="Y"
|
|
|
else
|
|
|
- [ -b "${DEVICE:-}" ] && FOUND="Y"
|
|
|
+ EXTERNAL="N"
|
|
|
fi
|
|
|
|
|
|
- if [[ "$FOUND" == "Y" ]]; then
|
|
|
- rm -rf "$TMP"
|
|
|
- return 0
|
|
|
+ if [[ "$EXTERNAL" != [Yy1]* ]]; then
|
|
|
+
|
|
|
+ BASE="$VERSION.iso"
|
|
|
+
|
|
|
+ if ! skipInstall && [ ! -f "$STORAGE/$BASE" ]; then
|
|
|
+ msg="Windows is being downloaded, please wait..."
|
|
|
+ fi
|
|
|
+
|
|
|
+ else
|
|
|
+
|
|
|
+ BASE=$(basename "${VERSION%%\?*}")
|
|
|
+ : "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}"
|
|
|
+ BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g')
|
|
|
+
|
|
|
+ if ! skipInstall && [ ! -f "$STORAGE/$BASE" ]; then
|
|
|
+ msg="Image '$BASE' is being downloaded, please wait..."
|
|
|
+ fi
|
|
|
+
|
|
|
fi
|
|
|
|
|
|
+ [[ "${BASE,,}" == "custom."* ]] && BASE="windows.iso"
|
|
|
+
|
|
|
fi
|
|
|
|
|
|
- EXTERNAL="Y"
|
|
|
- CUSTOM="$BASE"
|
|
|
+ html "$msg"
|
|
|
|
|
|
-fi
|
|
|
+ [ -z "$MANUAL" ] && MANUAL="N"
|
|
|
|
|
|
-mkdir -p "$TMP"
|
|
|
+ if [ -f "$STORAGE/$BASE" ]; then
|
|
|
|
|
|
-if [ ! -f "$STORAGE/$CUSTOM" ]; then
|
|
|
- CUSTOM=""
|
|
|
- ISO="$TMP/$BASE"
|
|
|
-else
|
|
|
- ISO="$STORAGE/$CUSTOM"
|
|
|
-fi
|
|
|
+ # Check if the ISO was already processed by our script
|
|
|
+ local magic=$(dd if="$STORAGE/$BASE" seek=0 bs=1 count=1 status=none | tr -d '\000')
|
|
|
+ magic="$(printf '%s' "$magic" | od -A n -t x1 -v | tr -d ' \n')"
|
|
|
|
|
|
-rm -f "$TMP/$BASE"
|
|
|
+ if [[ "$magic" == "16" ]]; then
|
|
|
|
|
|
-if [ ! -f "$ISO" ]; then
|
|
|
+ if hasDisk || [[ "$MANUAL" = [Yy1]* ]]; then
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
|
|
|
- if [[ "$EXTERNAL" != [Yy1]* ]]; then
|
|
|
+ fi
|
|
|
|
|
|
- cd "$TMP"
|
|
|
- /run/mido.sh "$VERSION"
|
|
|
- cd /run
|
|
|
+ EXTERNAL="Y"
|
|
|
+ CUSTOM="$BASE"
|
|
|
|
|
|
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"
|
|
|
+ if skipInstall; then
|
|
|
+ BASE=""
|
|
|
+ return 1
|
|
|
fi
|
|
|
|
|
|
- { wget "$VERSION" -O "$ISO" -q --no-check-certificate --show-progress "$PROGRESS"; rc=$?; } || :
|
|
|
+ fi
|
|
|
|
|
|
- (( rc != 0 )) && error "Failed to download $VERSION, reason: $rc" && exit 60
|
|
|
+ mkdir -p "$TMP"
|
|
|
|
|
|
+ if [ ! -f "$STORAGE/$CUSTOM" ]; then
|
|
|
+ CUSTOM=""
|
|
|
+ ISO="$TMP/$BASE"
|
|
|
+ else
|
|
|
+ ISO="$STORAGE/$CUSTOM"
|
|
|
fi
|
|
|
|
|
|
- [ ! -f "$ISO" ] && error "Failed to download $VERSION" && exit 61
|
|
|
+ rm -f "$TMP/$BASE"
|
|
|
+ return 0
|
|
|
+}
|
|
|
|
|
|
-fi
|
|
|
+downloadImage() {
|
|
|
|
|
|
-SIZE=$(stat -c%s "$ISO")
|
|
|
-SIZE_GB=$(( (SIZE + 1073741823)/1073741824 ))
|
|
|
+ local iso="$1"
|
|
|
+ local url="$2"
|
|
|
+ local progress
|
|
|
+ rm -f "$iso"
|
|
|
|
|
|
-if ((SIZE<10000000)); then
|
|
|
- error "Invalid ISO file: Size is smaller than 10 MB" && exit 62
|
|
|
-fi
|
|
|
+ if [[ "$EXTERNAL" != [Yy1]* ]]; then
|
|
|
|
|
|
-SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
|
|
-SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
|
|
+ cd "$TMP"
|
|
|
+ /run/mido.sh "$url"
|
|
|
+ cd /run
|
|
|
|
|
|
-if (( SIZE > SPACE )); then
|
|
|
- error "Not enough free space in $STORAGE, have $SPACE_GB GB available but need at least $SIZE_GB GB." && exit 63
|
|
|
-fi
|
|
|
+ [ ! -f "$iso" ] && error "Failed to download $url" && exit 61
|
|
|
+ return 0
|
|
|
|
|
|
-if [ -n "$CUSTOM" ]; then
|
|
|
- MSG="Extracting local ISO image..."
|
|
|
-else
|
|
|
- MSG="Extracting downloaded ISO image..."
|
|
|
-fi
|
|
|
+ fi
|
|
|
|
|
|
-info "$MSG" && html "$MSG"
|
|
|
+ info "Downloading $BASE as boot image..."
|
|
|
|
|
|
-DIR="$TMP/unpack"
|
|
|
-rm -rf "$DIR"
|
|
|
+ # 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
|
|
|
|
|
|
-7z x "$ISO" -o"$DIR" > /dev/null
|
|
|
+ { wget "$url" -O "$iso" -q --no-check-certificate --show-progress "$progress"; rc=$?; } || :
|
|
|
|
|
|
-FB="falling back to manual installation!"
|
|
|
-ETFS="boot/etfsboot.com"
|
|
|
-EFISYS="efi/microsoft/boot/efisys_noprompt.bin"
|
|
|
+ (( rc != 0 )) && error "Failed to download $url, reason: $rc" && exit 60
|
|
|
+ [ ! -f "$iso" ] && error "Failed to download $url" && exit 61
|
|
|
|
|
|
-if [ ! -f "$DIR/$ETFS" ] || [ ! -f "$DIR/$EFISYS" ]; then
|
|
|
+ return 0
|
|
|
+}
|
|
|
|
|
|
- if [ ! -f "$DIR/$ETFS" ]; then
|
|
|
- warn "failed to locate file 'etfsboot.com' in ISO image, $FB"
|
|
|
- else
|
|
|
- warn "failed to locate file 'efisys_noprompt.bin' in ISO image, $FB"
|
|
|
+extractImage() {
|
|
|
+
|
|
|
+ local iso="$1"
|
|
|
+ local dir="$2"
|
|
|
+
|
|
|
+ local msg="Extracting downloaded ISO image..."
|
|
|
+ [ -n "$CUSTOM" ] && msg="Extracting local ISO image..."
|
|
|
+ info "$msg" && html "$msg"
|
|
|
+
|
|
|
+ local size=$(stat -c%s "$iso")
|
|
|
+ local size_gb=$(( (size + 1073741823)/1073741824 ))
|
|
|
+ local space=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
|
|
+ local space_gb=$(( (space + 1073741823)/1073741824 ))
|
|
|
+
|
|
|
+ if ((size<10000000)); then
|
|
|
+ error "Invalid ISO file: Size is smaller than 10 MB" && exit 62
|
|
|
fi
|
|
|
|
|
|
- # Mark ISO as prepared via magic byte
|
|
|
- printf '\x16' | dd of="$ISO" bs=1 seek=0 count=1 conv=notrunc status=none
|
|
|
+ if (( size > space )); then
|
|
|
+ error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && exit 63
|
|
|
+ fi
|
|
|
|
|
|
- [[ "$ISO" != "$STORAGE/$BASE" ]] && mv -f "$ISO" "$STORAGE/$BASE"
|
|
|
+ rm -rf "$dir"
|
|
|
+ 7z x "$iso" -o"$dir" > /dev/null
|
|
|
|
|
|
- rm -f "$STORAGE/windows.ver"
|
|
|
- cp /run/version "$STORAGE/windows.ver"
|
|
|
+ if [ ! -f "$dir/$ETFS" ] || [ ! -f "$dir/$EFISYS" ]; then
|
|
|
+
|
|
|
+ if [ ! -f "$dir/$ETFS" ]; then
|
|
|
+ warn "failed to locate file 'etfsboot.com' in ISO image, $FB"
|
|
|
+ else
|
|
|
+ warn "failed to locate file 'efisys_noprompt.bin' in ISO image, $FB"
|
|
|
+ fi
|
|
|
+
|
|
|
+ return 1
|
|
|
+ fi
|
|
|
+
|
|
|
+ [ -z "$CUSTOM" ] && rm -f "$iso"
|
|
|
|
|
|
- rm -rf "$TMP"
|
|
|
return 0
|
|
|
-fi
|
|
|
+}
|
|
|
|
|
|
-[ -z "$CUSTOM" ] && rm -f "$ISO"
|
|
|
+findVersion() {
|
|
|
|
|
|
-XML=""
|
|
|
+ local name="$1"
|
|
|
+ local detected=""
|
|
|
|
|
|
-if [[ "$MANUAL" != [Yy1]* ]]; then
|
|
|
+ [[ "${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 [[ "$EXTERNAL" != [Yy1]* ]]; then
|
|
|
- [ -z "$CUSTOM" ] && XML="$VERSION.xml"
|
|
|
- fi
|
|
|
+ echo "$detected"
|
|
|
+ return 0
|
|
|
+}
|
|
|
|
|
|
- if [ ! -f "/run/assets/$XML" ]; then
|
|
|
+selectXML() {
|
|
|
|
|
|
- MSG="Detecting Windows version from ISO image..."
|
|
|
- info "$MSG" && html "$MSG"
|
|
|
+ local dir="$1"
|
|
|
|
|
|
- LOC="$DIR/sources/install.wim"
|
|
|
- [ ! -f "$LOC" ] && LOC="$DIR/sources/install.esd"
|
|
|
+ XML=""
|
|
|
+ [[ "$MANUAL" == [Yy1]* ]] && return 0
|
|
|
|
|
|
- if [ -f "$LOC" ]; then
|
|
|
+ if [[ "$EXTERNAL" != [Yy1]* ]] && [ -z "$CUSTOM" ]; then
|
|
|
+ XML="$VERSION.xml"
|
|
|
+ [ -f "/run/assets/$XML" ] && return 0
|
|
|
+ fi
|
|
|
|
|
|
- DETECTED=""
|
|
|
- TAG="DISPLAYNAME"
|
|
|
- RESULT=$(wimlib-imagex info -xml "$LOC" | tr -d '\000')
|
|
|
- NAME=$(sed -n "/$TAG/{s/.*<$TAG>\(.*\)<\/$TAG>.*/\1/;p}" <<< "$RESULT")
|
|
|
+ info "Detecting Windows version from ISO image..."
|
|
|
|
|
|
- [[ "${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"
|
|
|
+ local loc="$dir/sources/install.wim"
|
|
|
+ [ ! -f "$loc" ] && loc="$dir/sources/install.esd"
|
|
|
|
|
|
- if [ -z "$DETECTED" ]; then
|
|
|
+ if [ ! -f "$loc" ]; then
|
|
|
+ warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB"
|
|
|
+ return 0
|
|
|
+ fi
|
|
|
|
|
|
- TAG="PRODUCTNAME"
|
|
|
- NAME2=$(sed -n "/$TAG/{s/.*<$TAG>\(.*\)<\/$TAG>.*/\1/;p}" <<< "$RESULT")
|
|
|
- [ -z "$NAME" ] && NAME="$NAME2"
|
|
|
+ local tag="DISPLAYNAME"
|
|
|
+ local result=$(wimlib-imagex info -xml "$loc" | tr -d '\000')
|
|
|
+ local name=$(sed -n "/$tag/{s/.*<$tag>\(.*\)<\/$tag>.*/\1/;p}" <<< "$result")
|
|
|
+ local detected=$(findVersion "$name")
|
|
|
|
|
|
- [[ "${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"
|
|
|
+ if [ -z "$detected" ]; then
|
|
|
|
|
|
- fi
|
|
|
+ tag="PRODUCTNAME"
|
|
|
+ local name2=$(sed -n "/$tag/{s/.*<$tag>\(.*\)<\/$tag>.*/\1/;p}" <<< "$result")
|
|
|
+ [ -z "$name" ] && name="$name2"
|
|
|
+ detected=$(findVersion "$name2")
|
|
|
|
|
|
- if [ -n "$DETECTED" ]; then
|
|
|
+ fi
|
|
|
|
|
|
- XML="$DETECTED.xml"
|
|
|
+ if [ -n "$detected" ]; then
|
|
|
|
|
|
- if [ -f "/run/assets/$XML" ]; then
|
|
|
- echo "Detected image of type '$DETECTED', which supports automatic installation."
|
|
|
- else
|
|
|
- XML=""
|
|
|
- warn "detected image of type '$DETECTED', but no matching XML file exists, $FB."
|
|
|
- fi
|
|
|
+ if [ -f "/run/assets/$detected.xml" ]; then
|
|
|
+ XML="$detected.xml"
|
|
|
+ echo "Detected image of type '$detected', which supports automatic installation."
|
|
|
+ else
|
|
|
+ warn "detected image of type '$detected', but no matching XML file exists, $FB."
|
|
|
+ fi
|
|
|
+
|
|
|
+ else
|
|
|
|
|
|
+ if [ -z "$name" ]; then
|
|
|
+ warn "failed to detect Windows version from image, $FB"
|
|
|
+ else
|
|
|
+ if [[ "${name,,}" == "windows 7" ]]; then
|
|
|
+ warn "detected Windows 7 image, $FB"
|
|
|
else
|
|
|
- if [ -z "$NAME" ]; then
|
|
|
- warn "failed to detect Windows version from image, $FB"
|
|
|
- else
|
|
|
- if [[ "${NAME,,}" == "windows 7" ]]; then
|
|
|
- warn "detected Windows 7 image, $FB"
|
|
|
- else
|
|
|
- warn "failed to detect Windows version from string '$NAME', $FB"
|
|
|
- fi
|
|
|
- fi
|
|
|
+ warn "failed to detect Windows version from string '$name', $FB"
|
|
|
fi
|
|
|
- else
|
|
|
- warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB"
|
|
|
fi
|
|
|
+
|
|
|
fi
|
|
|
-fi
|
|
|
|
|
|
-ASSET="/run/assets/$XML"
|
|
|
+ return 0
|
|
|
+}
|
|
|
|
|
|
-if [ -f "$ASSET" ]; then
|
|
|
+updateImage() {
|
|
|
|
|
|
- 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/AUTOUNATTEND.XML"
|
|
|
- [ -f "$LOC" ] && mv -f "$ASSET" "$LOC"
|
|
|
+ local dir="$1"
|
|
|
+ local asset="$2"
|
|
|
|
|
|
- LOC="$DIR/sources/boot.wim"
|
|
|
- [ ! -f "$LOC" ] && LOC="$DIR/sources/boot.esd"
|
|
|
+ [ ! -f "$asset" ] && return 0
|
|
|
+ replaceXML "$dir" "$asset"
|
|
|
|
|
|
- if [ -f "$LOC" ]; then
|
|
|
+ local loc="$dir/sources/boot.wim"
|
|
|
+ [ ! -f "$loc" ] && loc="$dir/sources/boot.esd"
|
|
|
|
|
|
- MSG="Adding XML file for automatic installation..."
|
|
|
- info "$MSG" && html "$MSG"
|
|
|
+ if [ ! -f "$loc" ]; then
|
|
|
+ warn "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB"
|
|
|
+ return 0
|
|
|
+ fi
|
|
|
|
|
|
- RESULT=$(wimlib-imagex info -xml "$LOC" | tr -d '\000')
|
|
|
+ info "Adding XML file for automatic installation..."
|
|
|
|
|
|
- if [[ "${RESULT^^}" == *"<IMAGE INDEX=\"2\">"* ]]; then
|
|
|
- INDEX="2"
|
|
|
- else
|
|
|
- INDEX="1"
|
|
|
- fi
|
|
|
+ local index="1"
|
|
|
+ local result=$(wimlib-imagex info -xml "$loc" | tr -d '\000')
|
|
|
|
|
|
- wimlib-imagex update "$LOC" "$INDEX" --command "add $ASSET /autounattend.xml" > /dev/null
|
|
|
+ if [[ "${result^^}" == *"<IMAGE INDEX=\"2\">"* ]]; then
|
|
|
+ index="2"
|
|
|
+ fi
|
|
|
|
|
|
- else
|
|
|
+ wimlib-imagex update "$loc" "$index" --command "add $asset /autounattend.xml" > /dev/null
|
|
|
|
|
|
- ASSET=""
|
|
|
- warn "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB"
|
|
|
+ return 0
|
|
|
+}
|
|
|
+
|
|
|
+buildImage() {
|
|
|
+
|
|
|
+ local dir="$1"
|
|
|
+ local cat="BOOT.CAT"
|
|
|
+ local label="${BASE%.*}"
|
|
|
+ label="${label::30}"
|
|
|
+ local out="$TMP/$label.tmp"
|
|
|
+ rm -f "$out"
|
|
|
+
|
|
|
+ local msg="Generating updated ISO image..."
|
|
|
+ info "$msg" && html "$msg"
|
|
|
|
|
|
+ local size=$(du -h -b --max-depth=0 "$dir" | cut -f1)
|
|
|
+ local size_gb=$(( (size + 1073741823)/1073741824 ))
|
|
|
+ local space=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
|
|
+ local space_gb=$(( (space + 1073741823)/1073741824 ))
|
|
|
+
|
|
|
+ if (( size > space )); then
|
|
|
+ error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && exit 63
|
|
|
fi
|
|
|
-fi
|
|
|
|
|
|
-CAT="BOOT.CAT"
|
|
|
-LABEL="${BASE%.*}"
|
|
|
-LABEL="${LABEL::30}"
|
|
|
-OUT="$TMP/$LABEL.tmp"
|
|
|
-rm -f "$OUT"
|
|
|
+ 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"
|
|
|
+
|
|
|
+ [ -n "$CUSTOM" ] && rm -f "$STORAGE/$CUSTOM"
|
|
|
+
|
|
|
+ if [ -f "$STORAGE/$BASE" ]; then
|
|
|
+ error "File $STORAGE/$BASE does already exist ?!" && exit 64
|
|
|
+ fi
|
|
|
+
|
|
|
+ mv "$out" "$STORAGE/$BASE"
|
|
|
+ return 0
|
|
|
+}
|
|
|
|
|
|
-SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
|
|
-SPACE_GB=$(( (SPACE + 1073741823)/1073741824 ))
|
|
|
+######################################
|
|
|
|
|
|
-if (( SIZE > SPACE )); then
|
|
|
- error "Not enough free space in $STORAGE, have $SPACE_GB GB available but need at least $SIZE_GB GB." && exit 63
|
|
|
+if ! startInstall; then
|
|
|
+ rm -rf "$TMP"
|
|
|
+ return 0
|
|
|
fi
|
|
|
|
|
|
-MSG="Generating the ISO image..."
|
|
|
-info "$MSG" && html "$MSG"
|
|
|
+if [ ! -f "$ISO" ]; then
|
|
|
+ downloadImage "$ISO" "$VERSION"
|
|
|
+fi
|
|
|
|
|
|
-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"
|
|
|
+if ! extractImage "$ISO" "$DIR"; then
|
|
|
|
|
|
-# Mark ISO as prepared via magic byte
|
|
|
-printf '\x16' | dd of="$OUT" bs=1 seek=0 count=1 conv=notrunc status=none
|
|
|
+ if [[ "$ISO" != "$STORAGE/$BASE" ]]; then
|
|
|
+ mv -f "$ISO" "$STORAGE/$BASE"
|
|
|
+ fi
|
|
|
|
|
|
-[ -n "$CUSTOM" ] && rm -f "$STORAGE/$CUSTOM"
|
|
|
+ finishInstall "$STORAGE/$BASE"
|
|
|
+ return 0
|
|
|
|
|
|
-if [ -f "$STORAGE/$BASE" ]; then
|
|
|
- error "File $STORAGE/$BASE does already exist ?!" && exit 64
|
|
|
fi
|
|
|
|
|
|
-mv "$OUT" "$STORAGE/$BASE"
|
|
|
+selectXML "$DIR"
|
|
|
|
|
|
-rm -f "$STORAGE/windows.ver"
|
|
|
-cp /run/version "$STORAGE/windows.ver"
|
|
|
+updateImage "$DIR" "/run/assets/$XML"
|
|
|
|
|
|
-rm -rf "$TMP"
|
|
|
+buildImage "$DIR"
|
|
|
|
|
|
-html "Successfully prepared image for installation..."
|
|
|
+finishInstall "$STORAGE/$BASE"
|
|
|
|
|
|
+html "Successfully prepared image for installation..."
|
|
|
return 0
|