feat: Use state helper for base image reads (#1839)

This commit is contained in:
Kroese
2026-07-12 21:06:05 +02:00
committed by GitHub
parent 08f058b758
commit 3a0b973c0b
+31 -42
View File
@@ -11,16 +11,10 @@ backup () {
local iso="$1" local iso="$1"
local name="unknown" local name="unknown"
local root="$STORAGE/backups" local root="$STORAGE/backups"
local previous="$STORAGE/windows.base" local previous
if [ -f "$previous" ]; then previous=$(readState "base") || return 1
[ -n "$previous" ] && name="${previous%.*}"
previous=$(<"$previous")
previous="${previous//[![:print:]]/}"
[ -n "$previous" ] && name="${previous%.*}"
fi
if ! makeDir "$root"; then if ! makeDir "$root"; then
error "Failed to create directory \"$root\" !" error "Failed to create directory \"$root\" !"
@@ -59,47 +53,42 @@ skipInstall() {
local method="" local method=""
local magic byte local magic byte
local boot="$STORAGE/windows.boot" local boot="$STORAGE/windows.boot"
local previous="$STORAGE/windows.base" local previous
if [ -f "$previous" ]; then previous=$(readState "base") || return 1
previous=$(<"$previous") if [ -n "$previous" ]; then
previous="${previous//[![:print:]]/}" if [[ "${STORAGE,,}/${previous,,}" != "${iso,,}" ]]; then
if [ -n "$previous" ]; then if ! hasDisk; then
if [[ "${STORAGE,,}/${previous,,}" != "${iso,,}" ]]; then
if ! hasDisk; then
rm -f "$STORAGE/$previous"
return 1
fi
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, a backup of your previous installation will be saved..."
! backup "$STORAGE/$previous" && error "Backup failed!"
rm -f "$STORAGE/$previous"
return 1 return 1
fi fi
fi
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, a backup of your previous installation will be saved..."
! backup "$STORAGE/$previous" && error "Backup failed!"
return 1
fi
fi fi
[ -f "$boot" ] && hasDisk && return 0 [ -f "$boot" ] && hasDisk && return 0