From 2239792fa93664d0ae354a1856f7fc155800bb7a Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Sep 2025 16:17:42 +0200 Subject: [PATCH 1/4] feat: Allow for easier switching between versions (#1398) When the VERSION variable is changed, it will now automaticly clean the /storage folder instead of warning the user to manually do it. --- src/define.sh | 2 +- src/install.sh | 86 ++++++++++++++++++++++++++++++-------------------- 2 files changed, 53 insertions(+), 35 deletions(-) diff --git a/src/define.sh b/src/define.sh index 7bbe4f3..4884f5d 100644 --- a/src/define.sh +++ b/src/define.sh @@ -23,7 +23,7 @@ parseVersion() { if [[ "${VERSION}" == \"*\" || "${VERSION}" == \'*\' ]]; then VERSION="${VERSION:1:-1}" fi - + VERSION=$(expr "$VERSION" : "^\ *\(.*[^ ]\)\ *$") [ -z "$VERSION" ] && VERSION="win11" diff --git a/src/install.sh b/src/install.sh index 818f52f..8f93973 100644 --- a/src/install.sh +++ b/src/install.sh @@ -1,10 +1,8 @@ #!/usr/bin/env bash set -Eeuo pipefail -TMP="$STORAGE/tmp" -DIR="$TMP/unpack" -FB="falling back to manual installation!" ETFS="boot/etfsboot.com" +FB="falling back to manual installation!" EFISYS="efi/microsoft/boot/efisys_noprompt.bin" skipInstall() { @@ -16,28 +14,52 @@ skipInstall() { local previous="$STORAGE/windows.base" if [ -f "$previous" ]; then + previous=$(<"$previous") previous="${previous//[![:print:]]/}" + if [ -n "$previous" ]; then if [[ "${STORAGE,,}/${previous,,}" != "${iso,,}" ]]; then - if [ -f "$boot" ] && hasDisk; then - if [[ "${iso,,}" == "${STORAGE,,}/windows."* ]]; then - method="your custom .iso file" - else - if [[ "${previous,,}" != "windows."* ]]; then - method="the VERSION variable" - fi - fi - if [ -n "$method" ]; then - info "Detected that $method was changed, but ignoring this because Windows is already installed." - info "Please start with an empty /storage folder, if you want to install a different version of Windows." - fi - return 0 + + if ! hasDisk; then + + rm -f "$STORAGE/$previous" + return 1 + fi - rm -f "$STORAGE/$previous" + + if [[ "${iso,,}" == "${STORAGE,,}/windows."* ]]; then + method="your custom .iso file was changed" + else + if [[ "${previous,,}" != "windows."* ]]; then + method="the VERSION variable was changed" + else + method="your custom .iso file was removed" + + if [ -f "$boot" ]; then + info "Detected that $method, will be ignored." + return 0 + fi + + fi + fi + + info "Detected that $method, creating a backup of your previous installation..." + + local dir="$STORAGE/${previous%.*}.old" + + rm -rf "$dir" + mkdir -p "$dir" + + [ -f "$STORAGE/$previous" ] && mv -f "$STORAGE/$previous" "$dir/" + find "$STORAGE" -maxdepth 1 -type f -iname 'windows.*' -exec mv -n {} "$dir/" \; + find "$STORAGE" -maxdepth 1 -type f \( -iname '*.rom' -or -iname '*.vars' \) -exec mv -n {} "$dir/" \; + return 1 + fi fi + fi [ -f "$boot" ] && hasDisk && return 0 @@ -51,8 +73,10 @@ skipInstall() { byte="16" && [[ "$MANUAL" == [Yy1]* ]] && byte="17" if [[ "$magic" != "$byte" ]]; then + info "The ISO will be processed again because the configuration was changed..." return 1 + fi return 0 @@ -88,9 +112,11 @@ startInstall() { fi + TMP="$STORAGE/tmp" + rm -rf "$TMP" + skipInstall "$BOOT" && return 1 - rm -rf "$TMP" mkdir -p "$TMP" if [ -z "$CUSTOM" ]; then @@ -105,6 +131,10 @@ startInstall() { fi rm -f "$BOOT" + + find "$STORAGE" -maxdepth 1 -type f -iname 'windows.*' -not -iname '*.iso' -delete + find "$STORAGE" -maxdepth 1 -type f \( -iname '*.rom' -or -iname '*.vars' \) -delete + return 0 } @@ -126,16 +156,6 @@ finishInstall() { fi fi - rm -f "$STORAGE/windows.old" - rm -f "$STORAGE/windows.vga" - rm -f "$STORAGE/windows.net" - rm -f "$STORAGE/windows.usb" - rm -f "$STORAGE/windows.args" - rm -f "$STORAGE/windows.base" - rm -f "$STORAGE/windows.boot" - rm -f "$STORAGE/windows.mode" - rm -f "$STORAGE/windows.type" - cp -f /run/version "$STORAGE/windows.ver" if [[ "$iso" == "$STORAGE/"* ]]; then @@ -612,8 +632,7 @@ detectImage() { warn "failed to locate 'sources' folder in ISO image, $FB" && return 1 fi - wim=$(find "$src" -maxdepth 1 -type f -iname install.wim -print -quit) - [ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname install.esd -print -quit) + wim=$(find "$src" -maxdepth 1 -type f \( -iname install.wim -or -iname install.esd \) -print -quit) if [ ! -f "$wim" ]; then warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB" && return 1 @@ -913,8 +932,7 @@ updateImage() { error "failed to locate 'sources' folder in ISO image, $FB" && return 1 fi - wim=$(find "$src" -maxdepth 1 -type f -iname boot.wim -print -quit) - [ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname boot.esd -print -quit) + wim=$(find "$src" -maxdepth 1 -type f \( -iname boot.wim -or -iname boot.esd \) -print -quit) if [ ! -f "$wim" ]; then error "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB" && return 1 @@ -1076,8 +1094,6 @@ buildImage() { bootWindows() { - rm -rf "$TMP" - if [ -f "$STORAGE/windows.args" ]; then ARGS=$(<"$STORAGE/windows.args") ARGS="${ARGS//[![:print:]]/}" @@ -1145,6 +1161,8 @@ if [ ! -s "$ISO" ] || [ ! -f "$ISO" ]; then fi fi +DIR="$TMP/unpack" + if ! extractImage "$ISO" "$DIR" "$VERSION"; then rm -f "$ISO" 2> /dev/null || true exit 62 From d08b7aeb27387c41c2e0ba47872c95cd8f41a1b7 Mon Sep 17 00:00:00 2001 From: Sultaniiazov David Date: Wed, 17 Sep 2025 17:18:53 +0300 Subject: [PATCH 2/4] fix: Typo (#1397) --- src/mido.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mido.sh b/src/mido.sh index 4971b11..be21509 100644 --- a/src/mido.sh +++ b/src/mido.sh @@ -689,7 +689,7 @@ downloadImage() { if isESD "$version" "$lang"; then if [[ "$tried" != "n" ]]; then - info "Failed to download $desc, will try a diferent method now..." + info "Failed to download $desc, will try a different method now..." fi tried="y" From 0903fad26b617ac68e469ee88ff5b7898d539434 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Sep 2025 17:24:41 +0200 Subject: [PATCH 3/4] feat: Backup disk image (#1399) --- src/install.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/install.sh b/src/install.sh index 8f93973..3c37693 100644 --- a/src/install.sh +++ b/src/install.sh @@ -44,7 +44,7 @@ skipInstall() { fi fi - info "Detected that $method, creating a backup of your previous installation..." + info "Detected that $method, a backup of your previous installation will be saved..." local dir="$STORAGE/${previous%.*}.old" @@ -52,8 +52,8 @@ skipInstall() { mkdir -p "$dir" [ -f "$STORAGE/$previous" ] && mv -f "$STORAGE/$previous" "$dir/" - find "$STORAGE" -maxdepth 1 -type f -iname 'windows.*' -exec mv -n {} "$dir/" \; find "$STORAGE" -maxdepth 1 -type f \( -iname '*.rom' -or -iname '*.vars' \) -exec mv -n {} "$dir/" \; + find "$STORAGE" -maxdepth 1 -type f \( -iname 'data.*' -or -iname 'windows.*' \) -exec mv -n {} "$dir/" \; return 1 @@ -132,6 +132,7 @@ startInstall() { rm -f "$BOOT" + find "$STORAGE" -maxdepth 1 -type f -iname 'data.*' -delete find "$STORAGE" -maxdepth 1 -type f -iname 'windows.*' -not -iname '*.iso' -delete find "$STORAGE" -maxdepth 1 -type f \( -iname '*.rom' -or -iname '*.vars' \) -delete From 28580ba2762ac6e89bb4046b80c4223e7037446e Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 17 Sep 2025 21:03:54 +0200 Subject: [PATCH 4/4] feat: Implement backup function --- src/install.sh | 59 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/src/install.sh b/src/install.sh index 3c37693..867a4c8 100644 --- a/src/install.sh +++ b/src/install.sh @@ -5,6 +5,38 @@ ETFS="boot/etfsboot.com" FB="falling back to manual installation!" EFISYS="efi/microsoft/boot/efisys_noprompt.bin" +backup () { + + local count=1 + local iso="$1" + local name="$2" + local folder="$name" + local dir="$STORAGE/backups" + + mkdir -p "$dir" + + while [ -d "$STORAGE/$folder" ] + do + count=$[$count +1] + folder="${name}.${count}" + done + + dir+="/$folder" + + rm -rf "$dir" + mkdir -p "$dir" + + [ -f "$iso" ] && mv -f "$iso" "$dir/" + find "$STORAGE" -maxdepth 1 -type f \( -iname '*.rom' -or -iname '*.vars' \) -exec mv -n {} "$dir/" \; + find "$STORAGE" -maxdepth 1 -type f \( -iname 'data.*' -or -iname 'windows.*' \) -exec mv -n {} "$dir/" \; + + if [ -z "$(ls -A "$dir")" ]; then + rm -rf "$dir" + fi + + return 0 +} + skipInstall() { local iso="$1" @@ -19,6 +51,7 @@ skipInstall() { previous="${previous//[![:print:]]/}" if [ -n "$previous" ]; then + if [[ "${STORAGE,,}/${previous,,}" != "${iso,,}" ]]; then if ! hasDisk; then @@ -46,14 +79,9 @@ skipInstall() { info "Detected that $method, a backup of your previous installation will be saved..." - local dir="$STORAGE/${previous%.*}.old" - - rm -rf "$dir" - mkdir -p "$dir" - - [ -f "$STORAGE/$previous" ] && mv -f "$STORAGE/$previous" "$dir/" - find "$STORAGE" -maxdepth 1 -type f \( -iname '*.rom' -or -iname '*.vars' \) -exec mv -n {} "$dir/" \; - find "$STORAGE" -maxdepth 1 -type f \( -iname 'data.*' -or -iname 'windows.*' \) -exec mv -n {} "$dir/" \; + if ! backup "$STORAGE/$previous" "${previous%.*}"; then + error "Backup failed!" + fi return 1 @@ -117,6 +145,14 @@ startInstall() { skipInstall "$BOOT" && return 1 + if hasDisk; then + + if ! backup "" "backup"; then + error "Backup failed!" + fi + + fi + mkdir -p "$TMP" if [ -z "$CUSTOM" ]; then @@ -132,9 +168,8 @@ startInstall() { rm -f "$BOOT" - find "$STORAGE" -maxdepth 1 -type f -iname 'data.*' -delete - find "$STORAGE" -maxdepth 1 -type f -iname 'windows.*' -not -iname '*.iso' -delete find "$STORAGE" -maxdepth 1 -type f \( -iname '*.rom' -or -iname '*.vars' \) -delete + find "$STORAGE" -maxdepth 1 -type f \( -iname 'data.*' -or -iname 'windows.*' \) -delete return 0 } @@ -322,7 +357,7 @@ extractESD() { fi local esdImageCount - esdImageCount=$(wimlib-imagex info "$iso" | iconv -f UTF-16LE -t UTF-8 | awk '/Image Count:/ {print $3}') + esdImageCount=$(wimlib-imagex info "$iso" | awk '/Image Count:/ {print $3}') if [ -z "$esdImageCount" ]; then error "Cannot read the image count in ESD file!" && return 1 @@ -369,7 +404,7 @@ extractESD() { fi for (( imageIndex=4; imageIndex<=esdImageCount; imageIndex++ )); do - imageEdition=$(wimlib-imagex info "$iso" ${imageIndex} | iconv -f UTF-16LE -t UTF-8 | grep '^Description:' | sed 's/Description:[ \t]*//') + 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=$?