mirror of
https://github.com/dockur/windows.git
synced 2026-08-03 20:47:12 +01:00
feat: Improve Windows reinstall detection (#1871)
This commit is contained in:
+32
-13
@@ -7,11 +7,11 @@ EFISYS="efi/microsoft/boot/efisys_noprompt.bin"
|
|||||||
|
|
||||||
backup () {
|
backup () {
|
||||||
|
|
||||||
local count=1
|
|
||||||
local iso="$1"
|
local iso="$1"
|
||||||
|
local count=1
|
||||||
local name="unknown"
|
local name="unknown"
|
||||||
local root="$STORAGE/backups"
|
local root="$STORAGE/backups"
|
||||||
local previous
|
local file previous failed=""
|
||||||
|
|
||||||
previous=$(readState "base") || return 1
|
previous=$(readState "base") || return 1
|
||||||
[ -n "$previous" ] && name="${previous%.*}"
|
[ -n "$previous" ] && name="${previous%.*}"
|
||||||
@@ -24,8 +24,7 @@ backup () {
|
|||||||
local folder="$name"
|
local folder="$name"
|
||||||
local dir="$root/$folder"
|
local dir="$root/$folder"
|
||||||
|
|
||||||
while [ -d "$dir" ]
|
while [ -d "$dir" ]; do
|
||||||
do
|
|
||||||
(( count++ ))
|
(( count++ ))
|
||||||
folder="${name}.${count}"
|
folder="${name}.${count}"
|
||||||
dir="$root/$folder"
|
dir="$root/$folder"
|
||||||
@@ -36,14 +35,29 @@ backup () {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ -f "$iso" ] && mv -f "$iso" "$dir/"
|
if [ -f "$iso" ]; then
|
||||||
find "$STORAGE" -maxdepth 1 -type f -iname 'data.*' -not -iname '*.iso' -exec mv -n {} "$dir/" \;
|
if ! mv -f -- "$iso" "$dir/"; then
|
||||||
find "$STORAGE" -maxdepth 1 -type f -iname 'windows.*' -not -iname '*.iso' -exec mv -n {} "$dir/" \;
|
error "Failed to move \"$iso\" to \"$dir\"."
|
||||||
find "$STORAGE" -maxdepth 1 -type f \( -iname '*.rom' -or -iname '*.vars' \) -exec mv -n {} "$dir/" \;
|
failed="Y"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
while IFS= read -r -d '' file; do
|
||||||
|
if ! mv -n -- "$file" "$dir/"; then
|
||||||
|
error "Failed to move \"$file\" to \"$dir\"."
|
||||||
|
failed="Y"
|
||||||
|
fi
|
||||||
|
done < <(
|
||||||
|
find "$STORAGE" -maxdepth 1 -type f \
|
||||||
|
\( -iname 'data.*' -or -iname 'windows.*' -or -iname '*.rom' -or -iname '*.vars' \) \
|
||||||
|
-not -iname '*.iso' -print0
|
||||||
|
)
|
||||||
|
|
||||||
[ -z "$(ls -A "$dir")" ] && rm -rf "$dir"
|
[ -z "$(ls -A "$dir")" ] && rm -rf "$dir"
|
||||||
[ -z "$(ls -A "$root")" ] && rm -rf "$root"
|
[ -z "$(ls -A "$root")" ] && rm -rf "$root"
|
||||||
|
|
||||||
|
[ -n "$failed" ] && return 1
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +89,7 @@ skipInstall() {
|
|||||||
else
|
else
|
||||||
method="your custom .iso file was removed"
|
method="your custom .iso file was removed"
|
||||||
|
|
||||||
if [ -f "$boot" ]; then
|
if [ -f "$boot" ] && hasData; then
|
||||||
info "Detected that $method, will be ignored."
|
info "Detected that $method, will be ignored."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@@ -84,14 +98,17 @@ skipInstall() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
info "Detected that $method, a backup of your previous installation will be saved..."
|
info "Detected that $method, a backup of your previous installation will be saved..."
|
||||||
! backup "$STORAGE/$previous" && error "Backup failed!"
|
|
||||||
|
if ! backup "$STORAGE/$previous"; then
|
||||||
|
warn "the backup was incomplete, continuing with installation..."
|
||||||
|
fi
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ -f "$boot" ] && hasDisk && return 0
|
[ -f "$boot" ] && hasData && return 0
|
||||||
|
|
||||||
[ ! -f "$iso" ] && return 1
|
[ ! -f "$iso" ] && return 1
|
||||||
[ ! -s "$iso" ] && return 1
|
[ ! -s "$iso" ] && return 1
|
||||||
@@ -147,7 +164,9 @@ startInstall() {
|
|||||||
skipInstall "$BOOT" && return 1
|
skipInstall "$BOOT" && return 1
|
||||||
|
|
||||||
if hasDisk; then
|
if hasDisk; then
|
||||||
! backup "" && error "Backup failed!"
|
if ! backup ""; then
|
||||||
|
warn "the backup was incomplete, continuing with installation..."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! makeDir "$TMP"; then
|
if ! makeDir "$TMP"; then
|
||||||
@@ -317,7 +336,7 @@ findFile() {
|
|||||||
[ ! -d "$dir" ] && dir=$(find "$STORAGE" -maxdepth 1 -type d -iname "$fname" -print -quit)
|
[ ! -d "$dir" ] && dir=$(find "$STORAGE" -maxdepth 1 -type d -iname "$fname" -print -quit)
|
||||||
|
|
||||||
if [ -d "$dir" ]; then
|
if [ -d "$dir" ]; then
|
||||||
if ! hasDisk || [ ! -f "$boot" ]; then
|
if ! hasData || [ ! -f "$boot" ]; then
|
||||||
error "The bind $dir maps to a file that does not exist!" && return 1
|
error "The bind $dir maps to a file that does not exist!" && return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user