mirror of
https://github.com/dockur/windows.git
synced 2025-10-26 19:05:49 +00:00
feat: Implement backup function
This commit is contained in:
parent
0903fad26b
commit
28580ba276
1 changed files with 47 additions and 12 deletions
|
|
@ -5,6 +5,38 @@ ETFS="boot/etfsboot.com"
|
|||
FB="falling back to manual installation!"
|
||||
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() {
|
||||
|
||||
local iso="$1"
|
||||
|
|
@ -19,6 +51,7 @@ skipInstall() {
|
|||
previous="${previous//[![:print:]]/}"
|
||||
|
||||
if [ -n "$previous" ]; then
|
||||
|
||||
if [[ "${STORAGE,,}/${previous,,}" != "${iso,,}" ]]; then
|
||||
|
||||
if ! hasDisk; then
|
||||
|
|
@ -46,14 +79,9 @@ skipInstall() {
|
|||
|
||||
info "Detected that $method, a backup of your previous installation will be saved..."
|
||||
|
||||
local 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 '*.rom' -or -iname '*.vars' \) -exec mv -n {} "$dir/" \;
|
||||
find "$STORAGE" -maxdepth 1 -type f \( -iname 'data.*' -or -iname 'windows.*' \) -exec mv -n {} "$dir/" \;
|
||||
if ! backup "$STORAGE/$previous" "${previous%.*}"; then
|
||||
error "Backup failed!"
|
||||
fi
|
||||
|
||||
return 1
|
||||
|
||||
|
|
@ -117,6 +145,14 @@ startInstall() {
|
|||
|
||||
skipInstall "$BOOT" && return 1
|
||||
|
||||
if hasDisk; then
|
||||
|
||||
if ! backup "" "backup"; then
|
||||
error "Backup failed!"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
mkdir -p "$TMP"
|
||||
|
||||
if [ -z "$CUSTOM" ]; then
|
||||
|
|
@ -132,9 +168,8 @@ startInstall() {
|
|||
|
||||
rm -f "$BOOT"
|
||||
|
||||
find "$STORAGE" -maxdepth 1 -type f -iname 'data.*' -delete
|
||||
find "$STORAGE" -maxdepth 1 -type f -iname 'windows.*' -not -iname '*.iso' -delete
|
||||
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
|
||||
}
|
||||
|
|
@ -322,7 +357,7 @@ extractESD() {
|
|||
fi
|
||||
|
||||
local esdImageCount
|
||||
esdImageCount=$(wimlib-imagex info "$iso" | iconv -f UTF-16LE -t UTF-8 | awk '/Image Count:/ {print $3}')
|
||||
esdImageCount=$(wimlib-imagex info "$iso" | awk '/Image Count:/ {print $3}')
|
||||
|
||||
if [ -z "$esdImageCount" ]; then
|
||||
error "Cannot read the image count in ESD file!" && return 1
|
||||
|
|
@ -369,7 +404,7 @@ extractESD() {
|
|||
fi
|
||||
|
||||
for (( imageIndex=4; imageIndex<=esdImageCount; imageIndex++ )); do
|
||||
imageEdition=$(wimlib-imagex info "$iso" ${imageIndex} | iconv -f UTF-16LE -t UTF-8 | grep '^Description:' | sed 's/Description:[ \t]*//')
|
||||
imageEdition=$(wimlib-imagex info "$iso" ${imageIndex} | grep '^Description:' | sed 's/Description:[ \t]*//')
|
||||
[[ "${imageEdition,,}" != "${edition,,}" ]] && continue
|
||||
wimlib-imagex export "$iso" ${imageIndex} "$installWimFile" --compress=LZMS --chunk-size 128K --quiet || {
|
||||
retVal=$?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue