Compare commits

..

1 commit

Author SHA1 Message Date
Kroese
5959879b25
feat; Create backup of previous installation 2025-09-16 08:17:44 +02:00
3 changed files with 41 additions and 84 deletions

View file

@ -5,43 +5,11 @@ ETFS="boot/etfsboot.com"
FB="falling back to manual installation!" FB="falling back to manual installation!"
EFISYS="efi/microsoft/boot/efisys_noprompt.bin" 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() { skipInstall() {
local iso="$1" local iso="$1"
local method="" local method=""
local magic byte local dir magic byte
local boot="$STORAGE/windows.boot" local boot="$STORAGE/windows.boot"
local previous="$STORAGE/windows.base" local previous="$STORAGE/windows.base"
@ -51,40 +19,31 @@ skipInstall() {
previous="${previous//[![:print:]]/}" previous="${previous//[![:print:]]/}"
if [ -n "$previous" ]; then if [ -n "$previous" ]; then
if [[ "${STORAGE,,}/${previous,,}" != "${iso,,}" ]]; then if [[ "${STORAGE,,}/${previous,,}" != "${iso,,}" ]]; then
if [ -f "$boot" ] && hasDisk; then
if ! hasDisk; then
rm -f "$STORAGE/$previous"
return 1
fi
if [[ "${iso,,}" == "${STORAGE,,}/windows."* ]]; then if [[ "${iso,,}" == "${STORAGE,,}/windows."* ]]; then
method="your custom .iso file was changed" method="your custom .iso file"
else else
if [[ "${previous,,}" != "windows."* ]]; then if [[ "${previous,,}" != "windows."* ]]; then
method="the VERSION variable was changed" method="the VERSION variable"
else fi
method="your custom .iso file was removed" fi
if [ -n "$method" ]; then
if [ -f "$boot" ]; then info "Detected that $method was changed, will create a backup of your previous installation."
info "Detected that $method, will be ignored." 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 return 0
fi fi
rm -f "$STORAGE/$previous"
fi
fi
info "Detected that $method, a backup of your previous installation will be saved..."
if ! backup "$STORAGE/$previous" "${previous%.*}"; then
error "Backup failed!"
fi
return 1 return 1
fi fi
fi fi
@ -101,10 +60,8 @@ 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
@ -145,14 +102,6 @@ startInstall() {
skipInstall "$BOOT" && return 1 skipInstall "$BOOT" && return 1
if hasDisk; then
if ! backup "" "backup"; then
error "Backup failed!"
fi
fi
mkdir -p "$TMP" mkdir -p "$TMP"
if [ -z "$CUSTOM" ]; then if [ -z "$CUSTOM" ]; then
@ -167,10 +116,6 @@ 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 'data.*' -or -iname 'windows.*' \) -delete
return 0 return 0
} }
@ -192,6 +137,16 @@ 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
@ -357,7 +312,7 @@ extractESD() {
fi fi
local esdImageCount local esdImageCount
esdImageCount=$(wimlib-imagex info "$iso" | awk '/Image Count:/ {print $3}') esdImageCount=$(wimlib-imagex info "$iso" | iconv -f UTF-16LE -t UTF-8 | awk '/Image Count:/ {print $3}')
if [ -z "$esdImageCount" ]; then if [ -z "$esdImageCount" ]; then
error "Cannot read the image count in ESD file!" && return 1 error "Cannot read the image count in ESD file!" && return 1
@ -404,7 +359,7 @@ extractESD() {
fi fi
for (( imageIndex=4; imageIndex<=esdImageCount; imageIndex++ )); do for (( imageIndex=4; imageIndex<=esdImageCount; imageIndex++ )); do
imageEdition=$(wimlib-imagex info "$iso" ${imageIndex} | grep '^Description:' | sed 's/Description:[ \t]*//') imageEdition=$(wimlib-imagex info "$iso" ${imageIndex} | iconv -f UTF-16LE -t UTF-8 | grep '^Description:' | sed 's/Description:[ \t]*//')
[[ "${imageEdition,,}" != "${edition,,}" ]] && continue [[ "${imageEdition,,}" != "${edition,,}" ]] && continue
wimlib-imagex export "$iso" ${imageIndex} "$installWimFile" --compress=LZMS --chunk-size 128K --quiet || { wimlib-imagex export "$iso" ${imageIndex} "$installWimFile" --compress=LZMS --chunk-size 128K --quiet || {
retVal=$? retVal=$?
@ -668,7 +623,8 @@ 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 -or -iname install.esd \) -print -quit) 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)
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
@ -968,7 +924,8 @@ 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 -or -iname boot.esd \) -print -quit) 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)
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

View file

@ -689,7 +689,7 @@ downloadImage() {
if isESD "$version" "$lang"; then if isESD "$version" "$lang"; then
if [[ "$tried" != "n" ]]; then if [[ "$tried" != "n" ]]; then
info "Failed to download $desc, will try a different method now..." info "Failed to download $desc, will try a diferent method now..."
fi fi
tried="y" tried="y"