feat: Allow for easier switching between versions

When the VERSION variable is changed, it will now automaticly clean the /storage folder instead of warning the user to manually do it.
This commit is contained in:
Kroese 2025-09-17 16:06:22 +02:00 committed by GitHub
parent ed96c558fe
commit e505eb0030
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -20,30 +20,43 @@ skipInstall() {
if [ -n "$previous" ]; then if [ -n "$previous" ]; then
if [[ "${STORAGE,,}/${previous,,}" != "${iso,,}" ]]; then if [[ "${STORAGE,,}/${previous,,}" != "${iso,,}" ]]; then
if [ -f "$boot" ] && hasDisk; then
if [[ "${iso,,}" == "${STORAGE,,}/windows."* ]]; then if !hasDisk; 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, 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" rm -f "$STORAGE/$previous"
return 1 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, creating a backup of your previous installation..."
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 fi
@ -60,8 +73,10 @@ skipInstall() {
byte="16" && [[ "$MANUAL" == [Yy1]* ]] && byte="17" byte="16" && [[ "$MANUAL" == [Yy1]* ]] && byte="17"
if [[ "$magic" != "$byte" ]]; then if [[ "$magic" != "$byte" ]]; then
info "The ISO will be processed again because the configuration was changed..." info "The ISO will be processed again because the configuration was changed..."
return 1 return 1
fi fi
return 0 return 0
@ -116,6 +131,10 @@ startInstall() {
fi fi
rm -f "$BOOT" rm -f "$BOOT"
find "$STORAGE" -maxdepth 1 -type f -iname '*.rom' -or -iname '*.vars' -delete
find "$STORAGE" -maxdepth 1 -type f -iname 'windows.*' -not -iname '*.iso' -delete
return 0 return 0
} }
@ -137,16 +156,6 @@ finishInstall() {
fi fi
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" cp -f /run/version "$STORAGE/windows.ver"
if [[ "$iso" == "$STORAGE/"* ]]; then if [[ "$iso" == "$STORAGE/"* ]]; then
@ -623,8 +632,7 @@ detectImage() {
warn "failed to locate 'sources' folder in ISO image, $FB" && return 1 warn "failed to locate 'sources' folder in ISO image, $FB" && return 1
fi fi
wim=$(find "$src" -maxdepth 1 -type f -iname install.wim -print -quit) wim=$(find "$src" -maxdepth 1 -type f -iname install.wim -or -iname install.esd -print -quit)
[ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname install.esd -print -quit)
if [ ! -f "$wim" ]; then if [ ! -f "$wim" ]; then
warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB" && return 1 warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB" && return 1
@ -924,8 +932,7 @@ updateImage() {
error "failed to locate 'sources' folder in ISO image, $FB" && return 1 error "failed to locate 'sources' folder in ISO image, $FB" && return 1
fi fi
wim=$(find "$src" -maxdepth 1 -type f -iname boot.wim -print -quit) wim=$(find "$src" -maxdepth 1 -type f -iname boot.wim -or -iname boot.esd -print -quit)
[ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname boot.esd -print -quit)
if [ ! -f "$wim" ]; then if [ ! -f "$wim" ]; then
error "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB" && return 1 error "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB" && return 1