From 5959879b256e674ba75a15037eb56626f3478bc1 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 16 Sep 2025 08:17:44 +0200 Subject: [PATCH] feat; Create backup of previous installation --- src/install.sh | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/install.sh b/src/install.sh index 818f52f..990293c 100644 --- a/src/install.sh +++ b/src/install.sh @@ -1,23 +1,23 @@ #!/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() { local iso="$1" local method="" - local magic byte + local dir magic byte local boot="$STORAGE/windows.boot" 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 @@ -29,15 +29,24 @@ skipInstall() { 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." + info "Detected that $method was changed, will create a backup of your previous installation." fi + local i=2 + dir="${previous%.*}" + while [[ $i -le 99 ]] && [ -d "$STORAGE/$dir" ] + do + dir="${previous%.*}-$i" + i=$(expr $i + 1) + done + mkdir -p "$STORAGE/$dir" + find "$STORAGE" -maxdepth 1 -type f -name '*' -exec mv -n {} $STORAGE/$dir/ \; return 0 fi rm -f "$STORAGE/$previous" return 1 fi fi + fi [ -f "$boot" ] && hasDisk && return 0 @@ -88,9 +97,11 @@ startInstall() { fi - skipInstall "$BOOT" && return 1 - + TMP="$STORAGE/tmp" rm -rf "$TMP" + + skipInstall "$BOOT" && return 1 + mkdir -p "$TMP" if [ -z "$CUSTOM" ]; then @@ -1076,8 +1087,6 @@ buildImage() { bootWindows() { - rm -rf "$TMP" - if [ -f "$STORAGE/windows.args" ]; then ARGS=$(<"$STORAGE/windows.args") ARGS="${ARGS//[![:print:]]/}" @@ -1145,6 +1154,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