| 
									
										
										
										
											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-24 05:38:16 +01:00
										 |  |  | TMP="$STORAGE/tmp" | 
					
						
							|  |  |  | DIR="$TMP/unpack" | 
					
						
							|  |  |  | FB="falling back to manual installation!" | 
					
						
							|  |  |  | ETFS="boot/etfsboot.com" | 
					
						
							|  |  |  | EFISYS="efi/microsoft/boot/efisys_noprompt.bin" | 
					
						
							| 
									
										
										
										
											2024-01-17 03:40:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | hasDisk() { | 
					
						
							| 
									
										
										
										
											2024-01-17 03:40:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  |   [ -b "/disk1" ] && return 0 | 
					
						
							|  |  |  |   [ -b "/dev/disk1" ] && return 0 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   [ -b "${DEVICE:-}" ] && return 0 | 
					
						
							| 
									
										
										
										
											2024-01-17 03:40:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-16 16:22:28 +02:00
										 |  |  |   if [ -s "$STORAGE/data.img" ] || [ -s "$STORAGE/data.qcow2" ]; then | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |     return 0 | 
					
						
							| 
									
										
										
										
											2024-01-22 02:56:28 +01:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-17 03:40:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   return 1 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-01-22 20:44:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | skipInstall() { | 
					
						
							| 
									
										
										
										
											2024-01-22 20:44:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   if hasDisk && [ -f "$STORAGE/windows.boot" ]; then | 
					
						
							|  |  |  |     return 0 | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-19 04:28:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   return 1 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-01-22 20:44:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | startInstall() { | 
					
						
							| 
									
										
										
										
											2024-01-16 19:58:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 05:19:23 +01:00
										 |  |  |   html "Starting Windows..." | 
					
						
							| 
									
										
										
										
											2024-01-22 23:31:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-22 15:50:01 +02:00
										 |  |  |   [ -z "$MANUAL" ] && MANUAL="N" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  |   if [ -n "$CUSTOM" ]; then | 
					
						
							| 
									
										
										
										
											2024-01-14 15:19:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  |     ISO="$CUSTOM" | 
					
						
							| 
									
										
										
										
											2024-01-14 15:19:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2024-01-14 15:19:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  |     local file="${VERSION/\//}.iso" | 
					
						
							| 
									
										
										
										
											2024-01-14 15:19:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  |     if [[ "${VERSION,,}" == "http"* ]]; then | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  |       file=$(basename "${VERSION%%\?*}") | 
					
						
							|  |  |  |       : "${file//+/ }"; printf -v file '%b' "${_//%/\\x}" | 
					
						
							|  |  |  |       file=$(echo "$file" | sed -e 's/[^A-Za-z0-9._-]/_/g') | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2024-05-05 12:01:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 13:00:18 +02:00
										 |  |  |     ISO="$STORAGE/$file" | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  |     ! migrateFiles "$ISO" "$VERSION" && error "Migration failed!" && exit 57 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 11:37:01 +02:00
										 |  |  |   skipInstall && return 1 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  |   if [ -f "$ISO" ] && [ -s "$ISO" ]; then | 
					
						
							| 
									
										
										
										
											2024-01-17 03:40:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |     # Check if the ISO was already processed by our script | 
					
						
							| 
									
										
										
										
											2024-01-29 05:19:23 +01:00
										 |  |  |     local magic="" | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  |     magic=$(dd if="$ISO" seek=0 bs=1 count=1 status=none | tr -d '\000') | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |     magic="$(printf '%s' "$magic" | od -A n -t x1 -v | tr -d ' \n')" | 
					
						
							| 
									
										
										
										
											2024-05-05 11:37:01 +02:00
										 |  |  |     [[ "$magic" == "16" ]] && return 1 | 
					
						
							| 
									
										
										
										
											2024-01-22 20:44:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 12:01:46 +02:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [ -z "$CUSTOM" ]; then | 
					
						
							|  |  |  |     rm -f "$ISO" | 
					
						
							|  |  |  |   else | 
					
						
							| 
									
										
										
										
											2024-05-05 16:57:10 +02:00
										 |  |  |     if [ -n "$ORIGINAL" ]; then | 
					
						
							| 
									
										
										
										
											2024-05-05 11:37:01 +02:00
										 |  |  |       rm -f "$ISO" | 
					
						
							| 
									
										
										
										
											2024-05-05 16:57:10 +02:00
										 |  |  |       ISO="$ORIGINAL" | 
					
						
							| 
									
										
										
										
											2024-05-05 12:01:46 +02:00
										 |  |  |       CUSTOM="$ISO" | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2024-04-22 15:50:01 +02:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-14 15:19:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-13 16:58:04 +02:00
										 |  |  |   rm -rf "$TMP" | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   mkdir -p "$TMP" | 
					
						
							| 
									
										
										
										
											2024-01-22 02:56:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 11:37:01 +02:00
										 |  |  |   if [ -n "$CUSTOM" ]; then | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  |     local size | 
					
						
							|  |  |  |     size="$(stat -c%s "$ISO")" | 
					
						
							|  |  |  |     BOOT="$STORAGE/windows.$size.iso" | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2024-05-05 11:37:01 +02:00
										 |  |  |     BOOT="$ISO" | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  |     ISO=$(basename "$ISO") | 
					
						
							|  |  |  |     ISO="$TMP/$ISO" | 
					
						
							| 
									
										
										
										
											2024-01-22 02:56:28 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 11:37:01 +02:00
										 |  |  |   rm -f "$BOOT" | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   return 0 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-01-22 20:44:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  | finishInstall() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local iso="$1" | 
					
						
							|  |  |  |   local aborted="$2" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [ ! -s "$iso" ] || [ ! -f "$iso" ]; then | 
					
						
							|  |  |  |     error "Failed to find ISO file: $iso" && return 1 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [ -w "$iso" ] && [[ "$aborted" != [Yy1]* ]]; then | 
					
						
							|  |  |  |     # Mark ISO as prepared via magic byte | 
					
						
							|  |  |  |     if ! printf '\x16' | dd of="$iso" bs=1 seek=0 count=1 conv=notrunc status=none; then | 
					
						
							|  |  |  |       error "Failed to set magic byte in ISO file: $iso" && return 1 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   rm -f "$STORAGE/windows.old" | 
					
						
							|  |  |  |   rm -f "$STORAGE/windows.boot" | 
					
						
							|  |  |  |   rm -f "$STORAGE/windows.mode" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   cp /run/version "$STORAGE/windows.ver" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [[ "${PLATFORM,,}" == "x64" ]]; then | 
					
						
							|  |  |  |     if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then | 
					
						
							|  |  |  |       echo "$BOOT_MODE" > "$STORAGE/windows.mode" | 
					
						
							|  |  |  |       if [[ "${MACHINE,,}" != "q35" ]]; then | 
					
						
							|  |  |  |         echo "$MACHINE" > "$STORAGE/windows.old" | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       # Enable secure boot + TPM on manual installs as Win11 requires | 
					
						
							|  |  |  |       if [[ "$MANUAL" == [Yy1]* ]] || [[ "$aborted" == [Yy1]* ]]; then | 
					
						
							|  |  |  |         if [[ "${DETECTED,,}" == "win11"* ]]; then | 
					
						
							|  |  |  |           BOOT_MODE="windows_secure" | 
					
						
							|  |  |  |           echo "$BOOT_MODE" > "$STORAGE/windows.mode" | 
					
						
							|  |  |  |         fi | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   rm -rf "$TMP" | 
					
						
							|  |  |  |   return 0 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | abortInstall() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local iso="$1" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 11:37:01 +02:00
										 |  |  |   [[ "${iso,,}" == *".esd" ]] && exit 60 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 16:57:10 +02:00
										 |  |  |   if [ -n "$CUSTOM" ]; then | 
					
						
							|  |  |  |     BOOT="$iso" | 
					
						
							|  |  |  |     REMOVE="N" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     if [[ "$iso" != "$BOOT" ]]; then | 
					
						
							|  |  |  |       if ! mv -f "$iso" "$BOOT"; then | 
					
						
							|  |  |  |         error "Failed to move ISO file: $iso" && return 1 | 
					
						
							|  |  |  |       fi | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |     fi | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  |   finishInstall "$BOOT" "Y" && return 0 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   return 1 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  | detectCustom() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 21:09:34 +02:00
										 |  |  |   local file="" | 
					
						
							|  |  |  |   local size base | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   CUSTOM="" | 
					
						
							| 
									
										
										
										
											2024-05-05 16:57:10 +02:00
										 |  |  |   ORIGINAL="" | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if [[ "${VERSION,,}" != "http"* ]]; then | 
					
						
							| 
									
										
										
										
											2024-05-04 21:09:34 +02:00
										 |  |  |     base="${VERSION/\/storage\//}" | 
					
						
							|  |  |  |     [[ "$base" == "."* ]] && base="${file:1}" | 
					
						
							|  |  |  |     [[ "$base" == *"/"* ]] && base="" | 
					
						
							|  |  |  |     [ -n "$base" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname "$base" -printf "%f\n" | head -n 1) | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 21:09:34 +02:00
										 |  |  |   [ -z "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname custom.iso -printf "%f\n" | head -n 1) | 
					
						
							|  |  |  |   [ -z "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname custom.img -printf "%f\n" | head -n 1) | 
					
						
							|  |  |  |   [ -n "$file" ] && file="$STORAGE/$file" | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 21:09:34 +02:00
										 |  |  |   base="/custom.iso" | 
					
						
							|  |  |  |   [ -f "$base" ] && [ -s "$base" ] && file="$base" | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 21:09:34 +02:00
										 |  |  |   [ -z "$file" ] && return 0 | 
					
						
							|  |  |  |   [ ! -f "$file" ] && return 0 | 
					
						
							|  |  |  |   [ ! -s "$file" ] && return 0 | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 21:09:34 +02:00
										 |  |  |   size="$(stat -c%s "$file")" | 
					
						
							|  |  |  |   [ -z "$size" ] || [[ "$size" == "0" ]] && return 0 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 21:09:34 +02:00
										 |  |  |   base="$STORAGE/windows.$size.iso" | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 16:57:10 +02:00
										 |  |  |   if [ -f "$base" ] && [ -s "$base" ]; then | 
					
						
							|  |  |  |     CUSTOM="$base" | 
					
						
							|  |  |  |     ORIGINAL="$file" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     REMOVE="N" | 
					
						
							|  |  |  |     CUSTOM="$file" | 
					
						
							|  |  |  |     rm -f "$base" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   return 0 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  | getESD() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local dir="$1" | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   local version="$2" | 
					
						
							| 
									
										
										
										
											2024-05-05 19:01:56 +02:00
										 |  |  |   local editionName | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   local winCatalog size | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   case "${version,,}" in | 
					
						
							| 
									
										
										
										
											2024-05-05 19:01:56 +02:00
										 |  |  |     "win11${PLATFORM,,}" ) | 
					
						
							|  |  |  |       editionName="Professional" | 
					
						
							|  |  |  |       winCatalog="https://go.microsoft.com/fwlink?linkid=2156292" | 
					
						
							|  |  |  |       ;; | 
					
						
							|  |  |  |     "win10${PLATFORM,,}" ) | 
					
						
							|  |  |  |       editionName="Professional" | 
					
						
							|  |  |  |       winCatalog="https://go.microsoft.com/fwlink/?LinkId=841361" | 
					
						
							|  |  |  |       ;; | 
					
						
							|  |  |  |     "win11${PLATFORM,,}-enterprise" ) | 
					
						
							|  |  |  |       editionName="Enterprise" | 
					
						
							|  |  |  |       winCatalog="https://go.microsoft.com/fwlink?linkid=2156292" | 
					
						
							|  |  |  |       ;; | 
					
						
							|  |  |  |     "win10${PLATFORM,,}-enterprise" ) | 
					
						
							|  |  |  |       editionName="Enterprise" | 
					
						
							|  |  |  |       winCatalog="https://go.microsoft.com/fwlink/?LinkId=841361" | 
					
						
							|  |  |  |       ;; | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |     *) error "Invalid VERSION specified, value \"$version\" is not recognized!" && return 1 ;; | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   esac | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local msg="Downloading product information from Microsoft..." | 
					
						
							|  |  |  |   info "$msg" && html "$msg" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   rm -rf "$dir" | 
					
						
							|  |  |  |   mkdir -p "$dir" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local wFile="catalog.cab" | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   local xFile="products.xml" | 
					
						
							|  |  |  |   local eFile="esd_edition.xml" | 
					
						
							|  |  |  |   local fFile="products_filter.xml" | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   { wget "$winCatalog" -O "$dir/$wFile" -q --timeout=10; rc=$?; } || : | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   (( rc != 0 )) && error "Failed to download $winCatalog , reason: $rc" && return 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   cd "$dir" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if ! cabextract "$wFile" > /dev/null; then | 
					
						
							|  |  |  |     cd /run | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |     error "Failed to extract $wFile!" && return 1 | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   cd /run | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   if [ ! -s "$dir/$xFile" ]; then | 
					
						
							|  |  |  |     error "Failed to find $xFile in $wFile!" && return 1 | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local esdLang="en-us" | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   local edQuery='//File[Architecture="'${PLATFORM}'"][Edition="'${editionName}'"]' | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   echo -e '<Catalog>' > "$dir/$fFile" | 
					
						
							|  |  |  |   xmllint --nonet --xpath "${edQuery}" "$dir/$xFile" >> "$dir/$fFile" 2>/dev/null | 
					
						
							|  |  |  |   echo -e '</Catalog>'>> "$dir/$fFile" | 
					
						
							|  |  |  |   xmllint --nonet --xpath '//File[LanguageCode="'${esdLang}'"]' "$dir/$fFile" >"$dir/$eFile" | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   size=$(stat -c%s "$dir/$eFile") | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   if ((size<20)); then | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |     error "Failed to find Windows product in $eFile!" && return 1 | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   local tag="FilePath" | 
					
						
							|  |  |  |   ESD=$(xmllint --nonet --xpath "//$tag" "$dir/$eFile" | sed -E -e "s/<[\/]?$tag>//g") | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   if [ -z "$ESD" ]; then | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |     error "Failed to find ESD URL in $eFile!" && return 1 | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   tag="Sha1" | 
					
						
							|  |  |  |   ESD_SUM=$(xmllint --nonet --xpath "//$tag" "$dir/$eFile" | sed -E -e "s/<[\/]?$tag>//g") | 
					
						
							|  |  |  |   tag="Size" | 
					
						
							|  |  |  |   ESD_SIZE=$(xmllint --nonet --xpath "//$tag" "$dir/$eFile" | sed -E -e "s/<[\/]?$tag>//g") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   rm -rf "$dir" | 
					
						
							|  |  |  |   return 0 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  | verifyFile() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local iso="$1" | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   local size="$2" | 
					
						
							| 
									
										
										
										
											2024-05-05 18:05:13 +02:00
										 |  |  |   local total="$3" | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   local check="$4" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 19:12:58 +02:00
										 |  |  |   if [ -n "$size" ] && [[ "$total" != "$size" ]]; then | 
					
						
							|  |  |  |     [[ "$size" != "0" ]] && warn "The download file has an unexpected size: $total" | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   local hash="" | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   local algo="SHA256" | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   [ -z "$check" ] && return 0 | 
					
						
							| 
									
										
										
										
											2024-05-04 19:12:58 +02:00
										 |  |  |   [[ "$VERIFY" != [Yy1]* ]] && return 0 | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   [[ "${#check}" == "40" ]] && algo="SHA1" | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   local msg="Verifying downloaded ISO..." | 
					
						
							|  |  |  |   info "$msg" && html "$msg" | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   if [[ "${algo,,}" != "sha256" ]]; then | 
					
						
							|  |  |  |     hash=$(sha1sum "$iso" | cut -f1 -d' ') | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     hash=$(sha256sum "$iso" | cut -f1 -d' ') | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if [[ "$hash" == "$check" ]]; then | 
					
						
							| 
									
										
										
										
											2024-05-05 12:39:49 +02:00
										 |  |  |     info "Succesfully verified ISO!" && return 0 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   error "Invalid $algo checksum: $hash , but expected value is: $check ! Please report this at $SUPPORT/issues" | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   rm -f "$iso" | 
					
						
							|  |  |  |   return 1 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 18:01:36 +02:00
										 |  |  | doMido() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local iso="$1" | 
					
						
							|  |  |  |   local version="$2" | 
					
						
							|  |  |  |   local desc="$3" | 
					
						
							|  |  |  |   local rc sum size total | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   rm -f "$iso" | 
					
						
							|  |  |  |   rm -f "$iso.PART" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   size=$(getMido "$version" "size") | 
					
						
							|  |  |  |   sum=$(getMido "$version" "sum") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local msg="Downloading $desc..." | 
					
						
							|  |  |  |   info "$msg" && html "$msg" | 
					
						
							|  |  |  |   /run/progress.sh "$iso.PART" "$size" "Downloading $desc ([P])..." & | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   cd "$TMP" | 
					
						
							|  |  |  |   { /run/mido.sh "${version,,}"; rc=$?; } || : | 
					
						
							|  |  |  |   cd /run | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   fKill "progress.sh" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (( rc == 0 )) && [ -f "$iso" ]; then | 
					
						
							|  |  |  |     total=$(stat -c%s "$iso") | 
					
						
							|  |  |  |     if [ "$total" -gt 100000000 ]; then | 
					
						
							|  |  |  |       ! verifyFile "$iso" "$size" "$total" "$sum" && return 1 | 
					
						
							|  |  |  |       html "Download finished successfully..." && return 0 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   rm -f "$iso" | 
					
						
							|  |  |  |   rm -f "$iso.PART" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return 1 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  | downloadFile() { | 
					
						
							| 
									
										
										
										
											2024-01-29 07:36:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   local iso="$1" | 
					
						
							|  |  |  |   local url="$2" | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   local sum="$3" | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   local size="$4" | 
					
						
							|  |  |  |   local desc="$5" | 
					
						
							|  |  |  |   local rc total progress domain dots | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   rm -f "$iso" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # Check if running with interactive TTY or redirected to docker log | 
					
						
							|  |  |  |   if [ -t 1 ]; then | 
					
						
							|  |  |  |     progress="--progress=bar:noscroll" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     progress="--progress=dot:giga" | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-22 02:56:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 05:19:23 +01:00
										 |  |  |   local msg="Downloading $desc..." | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   html "$msg" | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   domain=$(echo "$url" | awk -F/ '{print $3}') | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   dots=$(echo "$domain" | tr -cd '.' | wc -c) | 
					
						
							|  |  |  |   (( dots > 1 )) && domain=$(expr "$domain" : '.*\.\(.*\..*\)') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [ -n "$domain" ] && [[ "${domain,,}" != *"microsoft.com" ]]; then | 
					
						
							|  |  |  |     msg="Downloading $desc from $domain..." | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   info "$msg" | 
					
						
							|  |  |  |   /run/progress.sh "$iso" "$size" "Downloading $desc ([P])..." & | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   { wget "$url" -O "$iso" -q --timeout=10 --show-progress "$progress"; rc=$?; } || : | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   fKill "progress.sh" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (( rc == 0 )) && [ -f "$iso" ]; then | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |     total=$(stat -c%s "$iso") | 
					
						
							|  |  |  |     if [ "$total" -gt 100000000 ]; then | 
					
						
							| 
									
										
										
										
											2024-05-04 19:12:58 +02:00
										 |  |  |       ! verifyFile "$iso" "$size" "$total" "$sum" && return 1 | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |       html "Download finished successfully..." && return 0 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   error "Failed to download $url , reason: $rc" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   rm -f "$iso" | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   return 1 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | downloadImage() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local iso="$1" | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   local version="$2" | 
					
						
							|  |  |  |   local tried="n" | 
					
						
							| 
									
										
										
										
											2024-05-05 11:37:01 +02:00
										 |  |  |   local url sum size base desc | 
					
						
							| 
									
										
										
										
											2024-01-29 05:19:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   if [[ "${version,,}" == "http"* ]]; then | 
					
						
							| 
									
										
										
										
											2024-05-05 11:37:01 +02:00
										 |  |  |     base=$(basename "$iso") | 
					
						
							|  |  |  |     desc=$(fromFile "$base") | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |     downloadFile "$iso" "$version" "" "" "$desc" && return 0 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |     return 1 | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-17 03:40:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   if ! validVersion "$version"; then | 
					
						
							|  |  |  |     error "Invalid VERSION specified, value \"$version\" is not recognized!" && return 1 | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   desc=$(printVersion "$version" "") | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   if isMido "$version"; then | 
					
						
							|  |  |  |     tried="y" | 
					
						
							|  |  |  |     doMido "$iso" "$version" "$desc" && return 0 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-29 05:19:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |   switchEdition "$version" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   if isESD "$version"; then | 
					
						
							| 
									
										
										
										
											2024-01-29 05:19:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |     if [[ "$tried" != "n" ]]; then | 
					
						
							|  |  |  |       info "Failed to download $desc using Mido, will try a diferent method now..." | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2024-04-13 16:58:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |     tried="y" | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |     if getESD "$TMP/esd" "$version"; then | 
					
						
							| 
									
										
										
										
											2024-05-05 13:06:11 +02:00
										 |  |  |       local prev="$ISO" | 
					
						
							|  |  |  |       ISO="${ISO%.*}.esd" | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |       downloadFile "$ISO" "$ESD" "$ESD_SUM" "$ESD_SIZE" "$desc" && return 0 | 
					
						
							| 
									
										
										
										
											2024-05-05 13:06:11 +02:00
										 |  |  |       ISO="$prev" | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-29 05:19:23 +01:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-19 15:18:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   for ((i=1;i<=MIRRORS;i++)); do | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |     url=$(getLink "$i" "$version") | 
					
						
							| 
									
										
										
										
											2024-01-29 05:19:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |     if [ -n "$url" ]; then | 
					
						
							|  |  |  |       if [[ "$tried" != "n" ]]; then | 
					
						
							|  |  |  |         info "Failed to download $desc, will try another mirror now..." | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  |       tried="y" | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |       size=$(getSize "$i" "$version") | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |       sum=$(getHash "$i" "$version") | 
					
						
							| 
									
										
										
										
											2024-05-04 18:29:05 +02:00
										 |  |  |       downloadFile "$iso" "$url" "$sum" "$size" "$desc" && return 0 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   done | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return 1 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-01-22 20:44:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 12:27:48 +02:00
										 |  |  | removeDownload() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local iso="$1" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   [ ! -f "$iso" ] && return 0 | 
					
						
							|  |  |  |   [ -n "$CUSTOM" ] && return 0 | 
					
						
							| 
									
										
										
										
											2024-05-05 13:00:18 +02:00
										 |  |  |   ! rm -f "$iso" 2> /dev/null && warn "failed to remove $iso !" | 
					
						
							| 
									
										
										
										
											2024-05-05 12:27:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return 0 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  | extractESD() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local iso="$1" | 
					
						
							|  |  |  |   local dir="$2" | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   local version="$3" | 
					
						
							|  |  |  |   local desc="$4" | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   local size size_gb space space_gb desc | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local msg="Extracting $desc bootdisk..." | 
					
						
							|  |  |  |   info "$msg" && html "$msg" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   if [ "$(stat -c%s "$iso")" -lt 100000000 ]; then | 
					
						
							|  |  |  |     error "Invalid ESD file: Size is smaller than 100 MB" && return 1 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   rm -rf "$dir" | 
					
						
							|  |  |  |   mkdir -p "$dir" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   size=16106127360 | 
					
						
							|  |  |  |   size_gb=$(( (size + 1073741823)/1073741824 )) | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   space=$(df --output=avail -B 1 "$dir" | tail -n 1) | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   space_gb=$(( (space + 1073741823)/1073741824 )) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (( size > space )); then | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |     error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && return 1 | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local esdImageCount | 
					
						
							|  |  |  |   esdImageCount=$(wimlib-imagex info "${iso}" | awk '/Image Count:/ {print $3}') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   wimlib-imagex apply "$iso" 1 "${dir}" --quiet 2>/dev/null || { | 
					
						
							|  |  |  |     retVal=$? | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |     error "Extracting $desc bootdisk failed" && return $retVal | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local bootWimFile="${dir}/sources/boot.wim" | 
					
						
							|  |  |  |   local installWimFile="${dir}/sources/install.wim" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local msg="Extracting $desc environment..." | 
					
						
							|  |  |  |   info "$msg" && html "$msg" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   wimlib-imagex export "${iso}" 2 "${bootWimFile}" --compress=LZX --chunk-size 32K --quiet || { | 
					
						
							|  |  |  |     retVal=$? | 
					
						
							|  |  |  |     error "Adding WinPE failed" && return ${retVal} | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local msg="Extracting $desc setup..." | 
					
						
							|  |  |  |   info "$msg" && html "$msg" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   wimlib-imagex export "${iso}" 3 "$bootWimFile" --compress=LZX --chunk-size 32K --boot --quiet || { | 
					
						
							|  |  |  |    retVal=$? | 
					
						
							|  |  |  |    error "Adding Windows Setup failed" && return ${retVal} | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   if [[ "${PLATFORM,,}" == "x64" ]]; then | 
					
						
							|  |  |  |     LABEL="CCCOMA_X64FRE_EN-US_DV9" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     LABEL="CPBA_A64FRE_EN-US_DV9" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   local msg="Extracting $desc image..." | 
					
						
							|  |  |  |   info "$msg" && html "$msg" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local edition imageIndex imageEdition | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   case "${version,,}" in | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |     "win11${PLATFORM,,}" ) edition="11 pro" ;; | 
					
						
							|  |  |  |     "win10${PLATFORM,,}" ) edition="10 pro" ;; | 
					
						
							|  |  |  |     *) error "Invalid VERSION specified, value \"$version\" is not recognized!" && return 1 ;; | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   esac | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (( imageIndex=4; imageIndex<=esdImageCount; imageIndex++ )); do | 
					
						
							|  |  |  |     imageEdition=$(wimlib-imagex info "${iso}" ${imageIndex} | grep '^Description:' | sed 's/Description:[ \t]*//') | 
					
						
							|  |  |  |     [[ "${imageEdition,,}" != *"$edition"* ]] && continue | 
					
						
							|  |  |  |     wimlib-imagex export "${iso}" ${imageIndex} "${installWimFile}" --compress=LZMS --chunk-size 128K --quiet || { | 
					
						
							|  |  |  |       retVal=$? | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |       error "Addition of ${imageIndex} to the $desc image failed" && return $retVal | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     return 0 | 
					
						
							|  |  |  |   done | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   error "Failed to find product in install.wim!" && return 1 | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | extractImage() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local iso="$1" | 
					
						
							|  |  |  |   local dir="$2" | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   local version="$3" | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   local desc="local ISO" | 
					
						
							| 
									
										
										
										
											2024-01-24 05:54:26 +01:00
										 |  |  |   local size size_gb space space_gb | 
					
						
							| 
									
										
										
										
											2024-01-25 00:18:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   if [ -z "$CUSTOM" ]; then | 
					
						
							|  |  |  |     desc="downloaded ISO" | 
					
						
							|  |  |  |     if [[ "$version" != "http"* ]]; then | 
					
						
							|  |  |  |       desc=$(printVersion "$version" "$desc") | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2024-02-04 19:45:32 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   if [[ "${iso,,}" == *".esd" ]]; then | 
					
						
							|  |  |  |     extractESD "$iso" "$dir" "$version" "$desc" && return 0 | 
					
						
							|  |  |  |     return 1 | 
					
						
							| 
									
										
										
										
											2024-01-27 14:52:58 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local msg="Extracting $desc image..." | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   info "$msg" && html "$msg" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   rm -rf "$dir" | 
					
						
							|  |  |  |   mkdir -p "$dir" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:54:26 +01:00
										 |  |  |   size=$(stat -c%s "$iso") | 
					
						
							|  |  |  |   size_gb=$(( (size + 1073741823)/1073741824 )) | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   space=$(df --output=avail -B 1 "$dir" | tail -n 1) | 
					
						
							| 
									
										
										
										
											2024-01-24 05:54:26 +01:00
										 |  |  |   space_gb=$(( (space + 1073741823)/1073741824 )) | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   if ((size<100000000)); then | 
					
						
							|  |  |  |     error "Invalid ISO file: Size is smaller than 100 MB" && return 1 | 
					
						
							| 
									
										
										
										
											2024-01-19 15:18:56 +01:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   if (( size > space )); then | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |     error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && return 1 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-22 02:56:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   rm -rf "$dir" | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if ! 7z x "$iso" -o"$dir" > /dev/null; then | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |     error "Failed to extract ISO file: $iso" && return 1 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   LABEL=$(isoinfo -d -i "$iso" | sed -n 's/Volume id: //p') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return 0 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | setXML() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   [[ "$MANUAL" == [Yy1]* ]] && return 0 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 21:09:34 +02:00
										 |  |  |   local file="/custom.xml" | 
					
						
							|  |  |  |   [ -f "$file" ] && [ -s "$file" ] && XML="$file" && return 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   file="$STORAGE/custom.xml" | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   [ -f "$file" ] && [ -s "$file" ] && XML="$file" && return 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   file="/run/assets/custom.xml" | 
					
						
							|  |  |  |   [ -f "$file" ] && [ -s "$file" ] && XML="$file" && return 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   file="$1" | 
					
						
							|  |  |  |   [ -z "$file" ] && file="/run/assets/$DETECTED.xml" | 
					
						
							|  |  |  |   [ -f "$file" ] && [ -s "$file" ] && XML="$file" && return 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return 1 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | selectVersion() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local tag="$1" | 
					
						
							|  |  |  |   local xml="$2" | 
					
						
							|  |  |  |   local id find name prefer | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   name=$(sed -n "/$tag/{s/.*<$tag>\(.*\)<\/$tag>.*/\1/;p}" <<< "$xml") | 
					
						
							|  |  |  |   [[ "$name" == *"Operating System"* ]] && name="" | 
					
						
							|  |  |  |   [ -z "$name" ] && return 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   id=$(fromName "$name") | 
					
						
							|  |  |  |   [ -z "$id" ] && warn "Unknown ${tag,,}: '$name'" && return 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   prefer="$id-enterprise" | 
					
						
							|  |  |  |   [ -f "/run/assets/$prefer.xml" ] && find=$(printEdition "$prefer" "") || find="" | 
					
						
							|  |  |  |   if [ -n "$find" ] && [[ "${xml,,}" == *"<${tag,,}>${find,,}</${tag,,}>"* ]]; then | 
					
						
							|  |  |  |     echo "$prefer" && return 0 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   prefer="$id-ultimate" | 
					
						
							|  |  |  |   [ -f "/run/assets/$prefer.xml" ] && find=$(printEdition "$prefer" "") || find="" | 
					
						
							|  |  |  |   if [ -n "$find" ] && [[ "${xml,,}" == *"<${tag,,}>${find,,}</${tag,,}>"* ]]; then | 
					
						
							|  |  |  |     echo "$prefer" && return 0 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   prefer="$id" | 
					
						
							|  |  |  |   [ -f "/run/assets/$prefer.xml" ] && find=$(printEdition "$prefer" "") || find="" | 
					
						
							|  |  |  |   if [ -n "$find" ] && [[ "${xml,,}" == *"<${tag,,}>${find,,}</${tag,,}>"* ]]; then | 
					
						
							|  |  |  |     echo "$prefer" && return 0 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   prefer=$(getVersion "$name") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   echo "$prefer" | 
					
						
							|  |  |  |   return 0 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | detectVersion() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local xml="$1" | 
					
						
							|  |  |  |   local id="" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   id=$(selectVersion "DISPLAYNAME" "$xml") | 
					
						
							|  |  |  |   [ -n "$id" ] && [[ "${id,,}" != *"unknown"* ]] && echo "$id" && return 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   id=$(selectVersion "PRODUCTNAME" "$xml") | 
					
						
							|  |  |  |   [ -n "$id" ] && [[ "${id,,}" != *"unknown"* ]] && echo "$id" && return 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   id=$(selectVersion "NAME" "$xml") | 
					
						
							|  |  |  |   [ -n "$id" ] && [[ "${id,,}" != *"unknown"* ]] && echo "$id" && return 0 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-22 20:44:38 +01:00
										 |  |  |   return 0 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-01-15 23:45:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  | detectImage() { | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-01 14:16:54 +01:00
										 |  |  |   local dir="$1" | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   local version="$2" | 
					
						
							|  |  |  |   local desc msg | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   XML="" | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 17:18:24 +02:00
										 |  |  |   if [ -z "$DETECTED" ] && [[ "${version,,}" != "http"* ]]; then | 
					
						
							|  |  |  |     [ -z "$CUSTOM" ] && DETECTED="$version" | 
					
						
							| 
									
										
										
										
											2024-01-26 22:11:12 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [ -n "$DETECTED" ]; then | 
					
						
							| 
									
										
										
										
											2024-01-27 14:52:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |     [[ "${DETECTED,,}" == "winxp"* ]] && return 0 | 
					
						
							| 
									
										
										
										
											2024-02-01 14:16:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |     setXML "" && return 0 | 
					
						
							| 
									
										
										
										
											2024-01-27 14:52:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |     desc=$(printEdition "$DETECTED" "this version") | 
					
						
							|  |  |  |     warn "the answer file for $desc was not found ($DETECTED.xml), $FB." | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |     return 0 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   info "Detecting version from ISO image..." | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   if [ -f "$dir/WIN51" ] || [ -f "$dir/SETUPXP.HTM" ]; then | 
					
						
							|  |  |  |     [ -d "$dir/AMD64" ] && DETECTED="winxpx64" || DETECTED="winxpx86" | 
					
						
							|  |  |  |     desc=$(printEdition "$DETECTED" "Windows XP") | 
					
						
							|  |  |  |     info "Detected: $desc" | 
					
						
							|  |  |  |     return 0 | 
					
						
							| 
									
										
										
										
											2024-02-01 14:16:54 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   local src loc info | 
					
						
							| 
									
										
										
										
											2024-02-16 14:43:03 +01:00
										 |  |  |   src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1) | 
					
						
							| 
									
										
										
										
											2024-02-16 14:38:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if [ ! -d "$src" ]; then | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |     [[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy" | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |     warn "failed to locate 'sources' folder in ISO image, $FB" && return 1 | 
					
						
							| 
									
										
										
										
											2024-02-16 14:38:00 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 14:43:03 +01:00
										 |  |  |   loc=$(find "$src" -maxdepth 1 -type f -iname install.wim | head -n 1) | 
					
						
							| 
									
										
										
										
											2024-04-19 00:00:17 +02:00
										 |  |  |   [ ! -f "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname install.esd | head -n 1) | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-19 00:00:17 +02:00
										 |  |  |   if [ ! -f "$loc" ]; then | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |     [[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy" | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |     warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB" && return 1 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-22 20:44:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   info=$(wimlib-imagex info -xml "$loc" | tr -d '\000') | 
					
						
							|  |  |  |   DETECTED=$(detectVersion "$info") | 
					
						
							| 
									
										
										
										
											2024-01-22 20:44:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |   if [ -z "$DETECTED" ]; then | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |     msg="Failed to determine Windows version from image" | 
					
						
							|  |  |  |     setXML "" && info "${msg}!" && return 0 | 
					
						
							|  |  |  |     warn "${msg}, $FB" && return 0 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   desc=$(printEdition "$DETECTED" "$DETECTED") | 
					
						
							| 
									
										
										
										
											2024-01-22 02:56:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   info "Detected: $desc" | 
					
						
							|  |  |  |   setXML "" && return 0 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   msg="the answer file for $desc was not found ($DETECTED.xml)" | 
					
						
							|  |  |  |   local fallback="/run/assets/${DETECTED%%-*}.xml" | 
					
						
							| 
									
										
										
										
											2024-01-15 23:45:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   setXML "$fallback" && warn "${msg}." && return 0 | 
					
						
							| 
									
										
										
										
											2024-05-05 13:00:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   warn "${msg}, $FB." | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   return 0 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-01-17 03:40:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-01 14:16:54 +01:00
										 |  |  | prepareImage() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local iso="$1" | 
					
						
							|  |  |  |   local dir="$2" | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   local missing | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   case "${DETECTED,,}" in | 
					
						
							|  |  |  |     "winxp"* ) | 
					
						
							|  |  |  |       BOOT_MODE="windows_legacy" | 
					
						
							|  |  |  |       prepareXP "$iso" "$dir" && return 0 | 
					
						
							|  |  |  |       error "Failed to prepare Windows XP ISO!" && return 1 | 
					
						
							|  |  |  |       ;; | 
					
						
							|  |  |  |     "winvista"* | "win7"* | "win2008"* ) | 
					
						
							|  |  |  |       BOOT_MODE="windows_legacy" ;; | 
					
						
							|  |  |  |   esac | 
					
						
							| 
									
										
										
										
											2024-02-01 14:16:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-13 10:20:18 +01:00
										 |  |  |   if [[ "${BOOT_MODE,,}" != "windows_legacy" ]]; then | 
					
						
							| 
									
										
										
										
											2024-02-01 14:16:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |     [ -f "$dir/$ETFS" ] && [ -f "$dir/$EFISYS" ] && return 0 | 
					
						
							| 
									
										
										
										
											2024-02-01 14:16:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |     missing=$(basename "$dir/$EFISYS") | 
					
						
							|  |  |  |     [ ! -f "$dir/$ETFS" ] && missing=$(basename "$dir/$ETFS") | 
					
						
							|  |  |  |     warn "failed to locate file '${missing,,}' in ISO image!" | 
					
						
							| 
									
										
										
										
											2024-02-01 14:16:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |     [[ "${PLATFORM,,}" == "arm64" ]] && return 1 | 
					
						
							|  |  |  |     BOOT_MODE="windows_legacy" | 
					
						
							| 
									
										
										
										
											2024-02-01 14:16:54 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   prepareLegacy "$iso" "$dir" && return 0 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   error "Failed to extract boot image from ISO!" | 
					
						
							|  |  |  |   return 1 | 
					
						
							| 
									
										
										
										
											2024-02-01 14:16:54 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | updateImage() { | 
					
						
							| 
									
										
										
										
											2024-01-17 03:40:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 11:37:01 +02:00
										 |  |  |   local dir="$1" | 
					
						
							|  |  |  |   local asset="$2" | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   local path src loc xml index result | 
					
						
							| 
									
										
										
										
											2024-01-22 20:44:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-19 00:00:17 +02:00
										 |  |  |   [ ! -s "$asset" ] || [ ! -f "$asset" ] && return 0 | 
					
						
							| 
									
										
										
										
											2024-01-17 03:40:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 14:43:03 +01:00
										 |  |  |   path=$(find "$dir" -maxdepth 1 -type f -iname autounattend.xml | head -n 1) | 
					
						
							| 
									
										
										
										
											2024-02-16 14:38:00 +01:00
										 |  |  |   [ -n "$path" ] && cp "$asset" "$path" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 14:43:03 +01:00
										 |  |  |   src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1) | 
					
						
							| 
									
										
										
										
											2024-02-16 14:38:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if [ ! -d "$src" ]; then | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |     [[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy" | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |     warn "failed to locate 'sources' folder in ISO image, $FB" && return 1 | 
					
						
							| 
									
										
										
										
											2024-02-16 14:38:00 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-16 14:43:03 +01:00
										 |  |  |   loc=$(find "$src" -maxdepth 1 -type f -iname boot.wim | head -n 1) | 
					
						
							| 
									
										
										
										
											2024-04-19 00:00:17 +02:00
										 |  |  |   [ ! -f "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname boot.esd | head -n 1) | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-19 00:00:17 +02:00
										 |  |  |   if [ ! -f "$loc" ]; then | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |     [[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy" | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |     warn "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB" && return 1 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   xml=$(basename "$asset") | 
					
						
							|  |  |  |   info "Adding $xml for automatic installation..." | 
					
						
							| 
									
										
										
										
											2024-01-14 15:19:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:54:26 +01:00
										 |  |  |   index="1" | 
					
						
							|  |  |  |   result=$(wimlib-imagex info -xml "$loc" | tr -d '\000') | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   if [[ "${result^^}" == *"<IMAGE INDEX=\"2\">"* ]]; then | 
					
						
							|  |  |  |     index="2" | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |   if ! wimlib-imagex update "$loc" "$index" --command "add $asset /autounattend.xml" > /dev/null; then | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |     warn "failed to add answer file ($xml) to ISO image, $FB" && return 1 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   return 0 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-28 11:03:37 +00:00
										 |  |  | copyOEM() { | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-28 11:03:37 +00:00
										 |  |  |   local dir="$1" | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   local folder="/oem" | 
					
						
							| 
									
										
										
										
											2024-04-28 11:03:37 +00:00
										 |  |  |   local src | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   [ ! -d "$folder" ] && folder="/OEM" | 
					
						
							| 
									
										
										
										
											2024-05-04 21:09:34 +02:00
										 |  |  |   [ ! -d "$folder" ] && folder="$STORAGE/oem" | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   [ ! -d "$folder" ] && folder="$STORAGE/OEM" | 
					
						
							| 
									
										
										
										
											2024-04-28 11:03:37 +00:00
										 |  |  |   [ ! -d "$folder" ] && return 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local msg="Copying OEM folder to image..." | 
					
						
							|  |  |  |   info "$msg" && html "$msg" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [ ! -d "$src" ]; then | 
					
						
							|  |  |  |     error "failed to locate 'sources' folder in ISO image!" && return 1 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   local dest="$src/\$OEM\$/\$1/" | 
					
						
							|  |  |  |   mkdir -p "$dest" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if ! cp -r "$folder" "$dest"; then | 
					
						
							|  |  |  |     error "Failed to copy OEM folder!" && return 1 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return 0 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | buildImage() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 12:27:48 +02:00
										 |  |  |   local dir="$1" | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   local failed="N" | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   local cat="BOOT.CAT" | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |   local log="/run/shm/iso.log" | 
					
						
							| 
									
										
										
										
											2024-05-05 11:48:40 +02:00
										 |  |  |   local base size size_gb space space_gb desc | 
					
						
							| 
									
										
										
										
											2024-01-24 05:54:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 12:27:48 +02:00
										 |  |  |   if [ -f "$BOOT" ]; then | 
					
						
							|  |  |  |     error "File $BOOT does already exist?!" && return 1 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   base=$(basename "$BOOT") | 
					
						
							| 
									
										
										
										
											2024-05-05 11:48:40 +02:00
										 |  |  |   local out="$TMP/${base%.*}.tmp" | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   rm -f "$out" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   desc=$(printVersion "$DETECTED" "ISO") | 
					
						
							| 
									
										
										
										
											2024-01-27 14:52:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   local msg="Building $desc image..." | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   info "$msg" && html "$msg" | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:54:26 +01:00
										 |  |  |   size=$(du -h -b --max-depth=0 "$dir" | cut -f1) | 
					
						
							|  |  |  |   size_gb=$(( (size + 1073741823)/1073741824 )) | 
					
						
							|  |  |  |   space=$(df --output=avail -B 1 "$TMP" | tail -n 1) | 
					
						
							|  |  |  |   space_gb=$(( (space + 1073741823)/1073741824 )) | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (( size > space )); then | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |     error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && return 1 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |   [ -z "$LABEL" ] && LABEL="Windows" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |   if [[ "${BOOT_MODE,,}" != "windows_legacy" ]]; then | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |     if ! genisoimage -o "$out" -b "$ETFS" -no-emul-boot -c "$cat" -iso-level 4 -J -l -D -N -joliet-long -relaxed-filenames -V "${LABEL::30}" \
 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |                      -udf -boot-info-table -eltorito-alt-boot -eltorito-boot "$EFISYS" -no-emul-boot -allow-limited-size -quiet "$dir" 2> "$log"; then | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |       failed="Y" | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-01 14:16:54 +01:00
										 |  |  |     if [[ "${DETECTED,,}" != "winxp"* ]]; then | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |       if ! genisoimage -o "$out" -b "$ETFS" -no-emul-boot -c "$cat" -iso-level 2 -J -l -D -N -joliet-long -relaxed-filenames -V "${LABEL::30}" \
 | 
					
						
							| 
									
										
										
										
											2024-02-01 14:16:54 +01:00
										 |  |  |                        -udf -allow-limited-size -quiet "$dir" 2> "$log"; then | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |         failed="Y" | 
					
						
							| 
									
										
										
										
											2024-02-01 14:16:54 +01:00
										 |  |  |       fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ! genisoimage -o "$out" -b "$ETFS" -no-emul-boot -boot-load-seg 1984 -boot-load-size 4 -c "$cat" -iso-level 2 -J -l -D -N -joliet-long \
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  |                        -relaxed-filenames -V "${LABEL::30}" -quiet "$dir" 2> "$log"; then | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |         failed="Y" | 
					
						
							| 
									
										
										
										
											2024-02-01 14:16:54 +01:00
										 |  |  |       fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2024-01-22 20:44:38 +01:00
										 |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   if [[ "$failed" != "N" ]]; then | 
					
						
							|  |  |  |     [ -s "$log" ] && echo "$(<"$log")" | 
					
						
							|  |  |  |     error "Failed to build image!" && return 1 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |   local error="" | 
					
						
							|  |  |  |   local hide="Warning: creating filesystem that does not conform to ISO-9660." | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-16 16:22:28 +02:00
										 |  |  |   [ -s "$log" ] && error="$(<"$log")" | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |   [[ "$error" != "$hide" ]] && echo "$error" | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  |   mv "$out" "$BOOT" | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  |   return 0 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-01-22 02:56:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-20 01:45:13 +02:00
										 |  |  | bootWindows() { | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   rm -rf "$TMP" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 11:37:01 +02:00
										 |  |  |   if [ ! -f "$ISO" ] || [ ! -s "$ISO" ]; then | 
					
						
							|  |  |  |     ISO="/custom.iso" | 
					
						
							|  |  |  |     [ ! -f "$ISO" ] && ISO="${STORAGE}$ISO" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   BOOT="$ISO" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   [[ "${PLATFORM,,}" == "arm64" ]] && VGA="virtio-gpu" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-27 18:46:09 +02:00
										 |  |  |   if [ -s "$STORAGE/windows.mode" ] && [ -f "$STORAGE/windows.mode" ]; then | 
					
						
							|  |  |  |     BOOT_MODE=$(<"$STORAGE/windows.mode") | 
					
						
							|  |  |  |     if [ -s "$STORAGE/windows.old" ] && [ -f "$STORAGE/windows.old" ]; then | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |       [[ "${PLATFORM,,}" == "x64" ]] && MACHINE=$(<"$STORAGE/windows.old") | 
					
						
							| 
									
										
										
										
											2024-04-27 18:46:09 +02:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2024-04-22 15:50:01 +02:00
										 |  |  |     return 0 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-27 18:46:09 +02:00
										 |  |  |   # Migrations | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |   [[ "${PLATFORM,,}" != "x64" ]] && return 0 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-27 18:46:09 +02:00
										 |  |  |   if [ -f "$STORAGE/windows.old" ]; then | 
					
						
							|  |  |  |     MACHINE=$(<"$STORAGE/windows.old") | 
					
						
							|  |  |  |     [ -z "$MACHINE" ] && MACHINE="q35" | 
					
						
							|  |  |  |     BOOT_MODE="windows_legacy" | 
					
						
							|  |  |  |     echo "$BOOT_MODE" > "$STORAGE/windows.mode" | 
					
						
							| 
									
										
										
										
											2024-04-22 15:50:01 +02:00
										 |  |  |     return 0 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-20 01:45:13 +02:00
										 |  |  |   local creation="1.10" | 
					
						
							|  |  |  |   local minimal="2.14" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if [ -f "$STORAGE/windows.ver" ]; then | 
					
						
							|  |  |  |     creation=$(<"$STORAGE/windows.ver") | 
					
						
							|  |  |  |     [[ "${creation}" != *"."* ]] && creation="$minimal" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # Force secure boot on installs created prior to v2.14 | 
					
						
							|  |  |  |   if (( $(echo "$creation < $minimal" | bc -l) )); then | 
					
						
							|  |  |  |     if [[ "${BOOT_MODE,,}" == "windows" ]]; then | 
					
						
							|  |  |  |       BOOT_MODE="windows_secure" | 
					
						
							| 
									
										
										
										
											2024-04-22 15:50:01 +02:00
										 |  |  |       echo "$BOOT_MODE" > "$STORAGE/windows.mode" | 
					
						
							| 
									
										
										
										
											2024-04-20 01:45:13 +02:00
										 |  |  |       if [ -f "$STORAGE/windows.rom" ] && [ ! -f "$STORAGE/$BOOT_MODE.rom" ]; then | 
					
						
							|  |  |  |         mv "$STORAGE/windows.rom" "$STORAGE/$BOOT_MODE.rom" | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  |       if [ -f "$STORAGE/windows.vars" ] && [ ! -f "$STORAGE/$BOOT_MODE.vars" ]; then | 
					
						
							|  |  |  |         mv "$STORAGE/windows.vars" "$STORAGE/$BOOT_MODE.vars" | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return 0 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ###################################### | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  | ! parseVersion && exit 58 | 
					
						
							|  |  |  | ! detectCustom && exit 59 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-20 01:45:13 +02:00
										 |  |  | if ! startInstall; then | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   bootWindows && return 0 | 
					
						
							|  |  |  |   exit 68 | 
					
						
							| 
									
										
										
										
											2024-01-22 02:56:28 +01:00
										 |  |  | fi | 
					
						
							| 
									
										
										
										
											2024-01-19 04:28:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-19 00:00:17 +02:00
										 |  |  | if [ ! -s "$ISO" ] || [ ! -f "$ISO" ]; then | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |   if ! downloadImage "$ISO" "$VERSION"; then | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  |     rm -f "$ISO" 2> /dev/null || true | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |     exit 61 | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | fi | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 22:57:44 +02:00
										 |  |  | if ! extractImage "$ISO" "$DIR" "$VERSION"; then | 
					
						
							|  |  |  |   rm -f "$ISO" 2> /dev/null || true | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   exit 62 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  | fi | 
					
						
							| 
									
										
										
										
											2024-01-22 02:56:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 13:28:12 +02:00
										 |  |  | if ! detectImage "$DIR" "$VERSION"; then | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   abortInstall "$ISO" && return 0 | 
					
						
							|  |  |  |   exit 60 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  | fi | 
					
						
							| 
									
										
										
										
											2024-01-19 01:25:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  | if ! prepareImage "$ISO" "$DIR"; then | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   abortInstall "$ISO" && return 0 | 
					
						
							|  |  |  |   exit 60 | 
					
						
							| 
									
										
										
										
											2024-01-22 20:44:38 +01:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 11:37:01 +02:00
										 |  |  | if ! updateImage "$DIR" "$XML"; then | 
					
						
							| 
									
										
										
										
											2024-04-24 20:16:43 +02:00
										 |  |  |   abortInstall "$ISO" && return 0 | 
					
						
							|  |  |  |   exit 60 | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  | fi | 
					
						
							| 
									
										
										
										
											2024-01-22 20:44:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 12:27:48 +02:00
										 |  |  | if ! removeDownload "$ISO"; then | 
					
						
							|  |  |  |   exit 64 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-28 11:03:37 +00:00
										 |  |  | if ! copyOEM "$DIR"; then | 
					
						
							|  |  |  |   exit 63 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 12:27:48 +02:00
										 |  |  | if ! buildImage "$DIR"; then | 
					
						
							| 
									
										
										
										
											2024-01-25 16:15:18 +01:00
										 |  |  |   exit 65 | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2024-01-14 15:19:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-05 00:47:44 +02:00
										 |  |  | if ! finishInstall "$BOOT" "N"; then | 
					
						
							| 
									
										
										
										
											2024-04-22 15:50:01 +02:00
										 |  |  |   exit 69 | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2024-01-20 17:03:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 05:38:16 +01:00
										 |  |  | html "Successfully prepared image for installation..." | 
					
						
							| 
									
										
										
										
											2024-01-14 15:19:58 +01:00
										 |  |  | return 0 |