diff --git a/src/install.sh b/src/install.sh index 345b8945..3a1fcbbd 100644 --- a/src/install.sh +++ b/src/install.sh @@ -279,9 +279,15 @@ startInstall() { skipInstall "$BOOT" "$previousBase" && return 1 if [ -z "$previousBase" ] && hasData; then - if ! backupPrevious ""; then - warn "the backup was incomplete, continuing with installation..." + + if enabled "$SHUTDOWN" && [ ! -f "$STORAGE/windows.boot" ]; then + discardPrevious "" || exit 50 + else + if ! backupPrevious ""; then + warn "the backup was incomplete, continuing with installation..." + fi fi + fi if ! makeDir "$TMP"; then @@ -374,7 +380,7 @@ skipUnattended() { # Preserve custom media in place. Downloaded or reused media must be moved # back to persistent storage before the manual fallback is started. - useOriginalImage "$iso" + useOriginalImage "$iso" || return 1 finishInstall "$BOOT" "$aborted" "$boot" && return 0 return 1 @@ -467,6 +473,11 @@ skipInstall() { fi fi + if enabled "$SHUTDOWN" && [ ! -f "$boot" ]; then + discardPrevious "$STORAGE/$previousBase" || exit 50 + return 1 + fi + info "Detected that $method, a backup of your previous installation will be saved..." if ! backupPrevious "$STORAGE/$previousBase"; then @@ -624,7 +635,10 @@ removeImage() { [ -n "$CUSTOM" ] && return 0 - rm -f -- "$iso" 2>/dev/null || warn "failed to remove image \"$iso\"!" + if ! rm -f -- "$iso" 2>/dev/null; then + warn "failed to remove image \"$iso\"!" + return 1 + fi return 0 } @@ -1264,6 +1278,27 @@ reserveSambaPorts() { return 0 } +discardPrevious() { + + local iso="$1" + + if [ -n "$iso" ] && [ -f "$iso" ]; then + if ! rm -f -- "$iso"; then + error "Failed to remove ISO file \"$iso\" !" + return 1 + fi + fi + + if ! find "$STORAGE" -maxdepth 1 -type f \ + \( -iname 'data.*' -or -iname 'windows.*' -or -iname '*.rom' -or -iname '*.vars' \) \ + -not -iname '*.iso' -delete; then + error "Failed to remove unfinished installation files from \"$STORAGE\" !" + return 1 + fi + + return 0 +} + backupPrevious () { local iso="$1" diff --git a/src/mido.sh b/src/mido.sh index 19e83e31..f7940167 100644 --- a/src/mido.sh +++ b/src/mido.sh @@ -1379,10 +1379,7 @@ fallbackEnglish() { # still locate the same image, but use English installation media. LANGUAGE="en" - if ! rm -f -- "$iso"; then - error "Failed to remove ISO file \"$iso\" !" - return 1 - fi + removeImage "$iso" || return 1 downloadImage "$iso" "$version" "$LANGUAGE" }