From 711f8b18e29da9b7e8be9387cbc693ff78e6ae58 Mon Sep 17 00:00:00 2001 From: Yawasau <229953100a@gmail.com> Date: Tue, 29 Mar 2022 23:25:10 +0800 Subject: [PATCH] bugfix --- backup_settings.conf | 3 ++ tools/bin/tools.sh | 75 +++++++++++++++++++++++++++++++------------- 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/backup_settings.conf b/backup_settings.conf index e21b2ea..a84aaf8 100644 --- a/backup_settings.conf +++ b/backup_settings.conf @@ -3,6 +3,9 @@ #如果是那下面三項設置就被忽略,改為音量鍵選擇 Lo=0 +#備份時檢查資料夾是否存在已經卸載應用 有則音量鍵選擇刪除或是移動到恢復資料夾/被卸載的應用 +delete_folder=1 + #自定義備份目錄輸出位置 (忽略為空將默認腳本路徑中) Output_path= diff --git a/tools/bin/tools.sh b/tools/bin/tools.sh index 6bf6a20..c0efd0c 100644 --- a/tools/bin/tools.sh +++ b/tools/bin/tools.sh @@ -145,6 +145,7 @@ backup) #效驗選填是否正確 isBoolean "$Lo" "LO" && Lo="$nsx" if [[ $Lo = false ]]; then + isBoolean "$delete_folder" "delete_folder" && delete_folder="$nsx" isBoolean "$update" "update" && update="$nsx" isBoolean "$Splist" "Splist" && Splist="$nsx" isBoolean "$USBdefault" "USBdefault" && USBdefault="$nsx" @@ -152,6 +153,8 @@ backup) isBoolean "$Backup_user_data" "Backup_user_data" && Backup_user_data="$nsx" isBoolean "$backup_media" "backup_media" && backup_media="$nsx" else + echoRgb "檢查目錄是否存在已卸載應用?\n -音量上檢查,下不檢查" + get_version "檢查" "不檢查" && delete_folder="$branch" echoRgb "如果檢測到更新後跳轉瀏覽器下載?\n -音量上跳轉,下不跳轉" get_version "跳轉" "不跳轉" && update="$branch" echoRgb "選擇是否只備份split apk(分割apk檔)\n -如果你不知道這意味什麼請選擇音量下進行混合備份\n -音量上僅備份split apk,音量下混合備份" "2" @@ -169,26 +172,7 @@ backup) txt="$MODDIR/appList.txt" txt="${txt/'/storage/emulated/'/'/data/media/'}" PU="$(ls /dev/block/vold | grep public)" - if [[ ! -f $txt ]]; then - echoRgb "請執行\"Getlist.sh\"獲取應用列表再來備份" "0" && exit 1 - else - D="1" - C="$(cat "$txt" | grep -v "#" | sed -e '/^$/d' | sed -n '$=')" - while [[ $D -le $C ]]; do - name1="$(cat "$txt" | grep -v "#" | sed -e '/^$/d' | sed -n "${D}p" | awk '{print $1}')" - name2="$(cat "$txt" | grep -v "#" | sed -e '/^$/d' | sed -n "${D}p" | awk '{print $2}')" - { - if [[ $name2 != "" && $(pm path "$name2" | cut -f2 -d ':') = "" ]]; then - echoRgb "$name1不存在系統,從列表中刪除" "0" - echo "$(sed -e "s/$name1 $name2//g ; /^$/d" "$txt")" >"$txt" - fi - } & - let D++ - done - echo "$(sed -e '/^$/d' "$txt")" >"$txt" - fi - r="$(cat "$txt" | grep -v "#" | sed -e '/^$/d' | sed -n '$=')" - [[ $r = "" ]] && echoRgb "爬..appList.txt是空的或是包名被注釋了這樣備份個鬼" "0" && exit 1 + [[ ! -f $txt ]] && echoRgb "請執行\"Getlist.sh\"獲取應用列表再來備份" "0" && exit 1 data="$MODDIR" hx="本地" echoRgb "壓縮方式:$Compression_method" "1" @@ -235,6 +219,53 @@ backup) else echoRgb "沒有檢測到隨身碟於本地備份" "0" fi + D="1" + C="$(cat "$txt" | grep -v "#" | sed -e '/^$/d' | sed -n '$=')" + if [[ $delete_folder = true ]]; then + echoRgb "腳本開始前檢查備份目錄中是否存在已經卸載應用" "3" + echoRgb "檢查到已卸載應用操作?\n -音量上刪除資料夾,下移動到其他處" + get_version "刪除" "移動到其他處" && operate="$branch" + find "$Backup" -maxdepth 1 -type d | sort | while read; do + if [[ -f $REPLY/app_details ]]; then + unset PackageName + . "$REPLY/app_details" + if [[ $PackageName != "" && $(pm path "$PackageName" | cut -f2 -d ':') = "" ]]; then + if [[ $operate = true ]]; then + rm -rf "$REPLY" + echoRgb "${REPLY##*/}不存在系統 刪除資料夾" "0" + else + if [[ ! -d $Backup/被卸載的應用 ]]; then + mkdir -p "$Backup/被卸載的應用" && mv "$REPLY" "$Backup/被卸載的應用/" + else + mv "$REPLY" "$Backup/被卸載的應用/" + fi + [[ ! -d $Backup/被卸載的應用/tools ]] && cp -r "$tools_path" "$Backup/被卸載的應用" && rm -rf "$Backup/被卸載的應用/tools/bin/zip" "$Backup/被卸載的應用/tools/script" + [[ ! -f $Backup/被卸載的應用/Restorebackup.sh ]] && cp -r "$script_path/restore" "$Backup/被卸載的應用/Restorebackup.sh" + [[ ! -f $Backup/被卸載的應用/DumpName.sh ]] && cp -r "$script_path/Get_DirName" "$Backup/被卸載的應用/DumpName.sh" + [[ ! -f $Backup/被卸載的應用/backup_settings.conf ]] && echo "#1開啟0關閉\n\n#是否在每次執行恢復腳本時使用音量鍵詢問如下需求\n#如果是那下面兩項項設置就被忽略,改為音量鍵選擇\nLo=$Lo\n\n#備份與恢復遭遇異常或是結束後發送通知(toast與狀態欄提示)\ntoast_info=$toast_info\n\n#腳本檢測更新後進行跳轉瀏覽器或是複製連結?\nupdate=$update\n\n#檢測到更新後的行為(1跳轉瀏覽器 0不跳轉瀏覽器,但是複製連結到剪裁版)\nupdate_behavior=$update_behavior">"$Backup/被卸載的應用/backup_settings.conf" && echo "$(sed 's/true/1/g ; s/false/0/g' "$Backup/backup_settings.conf")">"$Backup/被卸載的應用/backup_settings.conf" + txt2="$Backup/被卸載的應用/appList.txt" + [[ ! -f $txt2 ]] && echo "#不需要恢復還原的應用請在開頭注釋# 比如#xxxxxxxx 酷安">"$txt2" + echo "${REPLY##*/} $PackageName">>"$txt2" + echo "$(sed -e "s/${REPLY##*/} $PackageName//g ; /^$/d" "$Backup/appList.txt")" >"$Backup/appList.txt" + echoRgb "${REPLY##*/}不存在系統 已移動到$Backup/被卸載的應用" "0" + fi + fi + fi + done + fi + echoRgb "檢查備份列表中是否存在已經卸載應用" "3" + while [[ $D -le $C ]]; do + name1="$(cat "$txt" | grep -v "#" | sed -e '/^$/d' | sed -n "${D}p" | awk '{print $1}')" + name2="$(cat "$txt" | grep -v "#" | sed -e '/^$/d' | sed -n "${D}p" | awk '{print $2}')" + if [[ $name2 != "" && $(pm path "$name2" | cut -f2 -d ':') = "" ]]; then + echoRgb "$name1不存在系統,從列表中刪除" "0" + echo "$(sed -e "s/$name1 $name2//g ; /^$/d" "$txt")" >"$txt" + fi + let D++ + done + echo "$(sed -e '/^$/d' "$txt")" >"$txt" + r="$(cat "$txt" | grep -v "#" | sed -e '/^$/d' | sed -n '$=')" + [[ $r = "" ]] && echoRgb "爬..appList.txt是空的或是包名被注釋了這樣備份個鬼" "0" && exit 1 rm -rf "$Backup/STOP" #分區詳細 if [[ $(echo "$Backup" | egrep -o "^/storage/emulated") != "" ]]; then @@ -313,7 +344,7 @@ backup) if [[ $apk_version = "" ]]; then echo "apk_version=\"$apk_version2\"" >>"$app_details" else - echo "$(cat "$app_details" | sed "s/"${apk_version}"/"${apk_version2}"/g")">"$app_details" + echo "$(cat "$app_details" | sed "s/${apk_version}/${apk_version2}/g")">"$app_details" fi [[ $PackageName = "" ]] && echo "PackageName=\"$name2\"" >>"$app_details" [[ $ChineseName = "" ]] && echo "ChineseName=\"$name1\"" >>"$app_details" @@ -384,7 +415,7 @@ backup) [[ $2 != $(cat "$app_details" | awk "/$1path/"'{print $1}' | cut -f2 -d '=' | tail -n1 | sed 's/\"//g') ]] && echo "#$1path=\"$2\"" >>"$app_details" else if [[ $Size != "" ]]; then - echo "$(cat "$app_details" | sed "s/"$Size"/"$(du -ks "$data_path" | awk '{print $1}')"/g")">"$app_details" + echo "$(cat "$app_details" | sed "s/$Size/$(du -ks "$data_path" | awk '{print $1}')/g")">"$app_details" else echo "$1Size=\"$(du -ks "$data_path" | awk '{print $1}')\"" >>"$app_details" fi