This commit is contained in:
Yawasau
2023-10-21 19:54:54 +08:00
parent c65706e4b9
commit b5255fed7a

View File

@@ -66,7 +66,7 @@ else
echo "Magisk busybox Path does not exist" echo "Magisk busybox Path does not exist"
fi fi
export PATH="$PATH" export PATH="$PATH"
backup_version="V15.7.3" backup_version="V15.7.4"
#bin_path="${bin_path/'/storage/emulated/'/'/data/media/'}" #bin_path="${bin_path/'/storage/emulated/'/'/data/media/'}"
filepath="/data/backup_tools" filepath="/data/backup_tools"
busybox="$filepath/busybox" busybox="$filepath/busybox"
@@ -386,6 +386,7 @@ update_script() {
unset NAME unset NAME
} }
update_script update_script
zipFile="$(ls -t /storage/emulated/0/Download/*.zip 2>/dev/null | head -1)"
[[ $(unzip -l "$zipFile" 2>/dev/null | awk '{print $4}' | egrep -wo "^backup_settings.conf$") != "" ]] && update_script [[ $(unzip -l "$zipFile" 2>/dev/null | awk '{print $4}' | egrep -wo "^backup_settings.conf$") != "" ]] && update_script
case $operate in case $operate in
backup|Restore|Restore2|Getlist) backup|Restore|Restore2|Getlist)
@@ -407,6 +408,8 @@ backup|Restore|Restore2|Getlist)
read option read option
fi fi
done done
else
user="0"
fi fi
fi fi
echoRgb "當前操作為用戶$user" echoRgb "當前操作為用戶$user"
@@ -417,10 +420,10 @@ backup|Restore|Restore2|Getlist)
esac esac
if [[ $(getprop ro.build.version.sdk) -lt 30 ]]; then if [[ $(getprop ro.build.version.sdk) -lt 30 ]]; then
alias INSTALL="pm install --user $user -r -t &>/dev/null" alias INSTALL="pm install --user $user -r -t &>/dev/null"
alias create="pm install-create --user $user -t 2>/dev/null" alias create="pm install-create --user $user -t &>/dev/null"
else else
alias INSTALL="pm install -i com.android.vending --user $user -r -t &>/dev/null" alias INSTALL="pm install --user $user -r -t &>/dev/null"
alias create="pm install-create -i com.android.vending --user $user -t 2>/dev/null" alias create="pm install-create --user $user -t &>/dev/null"
fi fi
case $operate in case $operate in
Getlist|Restore2|Restore3|dumpname|check_file) ;; Getlist|Restore2|Restore3|dumpname|check_file) ;;
@@ -634,19 +637,12 @@ partition_info() {
} }
kill_app() { kill_app() {
if [[ $name2 != $Open_apps2 ]]; then if [[ $name2 != $Open_apps2 ]]; then
if [[ $name2 = com.tencent.mobileqq || $name2 = com.tencent.mm ]]; then pm suspend --user "$user" "$name2" 2>/dev/null | sed "s/Package $name2/ -應用:$name1/g ; s/new suspended state: true/暫停狀態:凍結/g"
if [[ $(getprop ro.miui.ui.version.code) != "" ]]; then am force-stop --user "$user" "$name2"
Serve="$(appops get --user "$user" "$name2" 10008 | egrep -o 'ignore|allow')"
appops set --user "$user" "$name2" 10008 ignore
fi
am force-stop --user "$user" "$name2"
fi
fi fi
} }
Set_service() { Set_service() {
if [[ $name2 = com.tencent.mobileqq || $name2 = com.tencent.mm ]]; then pm unsuspend "$name2" 2>/dev/null | sed "s/Package $name2/ -應用:$name1/g ; s/new suspended state: false/暫停狀態:解凍/g"
[[ $(getprop ro.miui.ui.version.code) != "" ]] && appops set --user "$user" "$name2" 10008 "$Serve"
fi
} }
Backup_apk() { Backup_apk() {
#檢測apk狀態進行備份 #檢測apk狀態進行備份
@@ -661,8 +657,6 @@ Backup_apk() {
result=0 result=0
echoRgb "Apk版本無更新 跳過備份" "2" echoRgb "Apk版本無更新 跳過備份" "2"
else else
#停止應用
kill_app
case $name2 in case $name2 in
com.google.android.youtube) com.google.android.youtube)
[[ -d /data/adb/Vanced ]] && nobackup="true" [[ -d /data/adb/Vanced ]] && nobackup="true"
@@ -740,7 +734,6 @@ Backup_apk() {
let osj++ let osj++
echoRgb "$name1不支持備份 需要使用vanced安裝" "0" && rm -rf "$Backup_folder" echoRgb "$name1不支持備份 需要使用vanced安裝" "0" && rm -rf "$Backup_folder"
fi fi
Set_service
fi fi
[[ $name2 = bin.mt.plus && ! -f $Backup/$name1.apk ]] && cp -r "$apk_path" "$Backup/$name1.apk" [[ $name2 = bin.mt.plus && ! -f $Backup/$name1.apk ]] && cp -r "$apk_path" "$Backup/$name1.apk"
} }
@@ -1154,7 +1147,7 @@ backup)
i=1 i=1
#數據目錄 #數據目錄
txt="$MODDIR/appList.txt" txt="$MODDIR/appList.txt"
txt="${txt/'/storage/emulated/'/'/data/media/'}" #txt="${txt/'/storage/emulated/'/'/data/media/'}"
[[ ! -f $txt ]] && echoRgb "請執行\"生成應用列表.sh\"獲取應用列表再來備份" "0" && exit 1 [[ ! -f $txt ]] && echoRgb "請執行\"生成應用列表.sh\"獲取應用列表再來備份" "0" && exit 1
sort -u "$txt" -o "$txt" 2>/dev/null sort -u "$txt" -o "$txt" 2>/dev/null
data="$MODDIR" data="$MODDIR"
@@ -1164,55 +1157,55 @@ backup)
echoRgb "配置詳細:\n -壓縮方式:$Compression_method\n -音量鍵確認:$Lo\n -Toast:$toast_info\n -更新:$update\n -已卸載應用檢查:$delete_folder\n -卸載應用默認操作(true刪除false移動):$default_behavior\n -默認使用usb:$USBdefault\n -備份外部數據:$Backup_obb_data\n -備份user數據:$Backup_user_data\n -自定義目錄備份:$backup_media" echoRgb "配置詳細:\n -壓縮方式:$Compression_method\n -音量鍵確認:$Lo\n -Toast:$toast_info\n -更新:$update\n -已卸載應用檢查:$delete_folder\n -卸載應用默認操作(true刪除false移動):$default_behavior\n -默認使用usb:$USBdefault\n -備份外部數據:$Backup_obb_data\n -備份user數據:$Backup_user_data\n -自定義目錄備份:$backup_media"
D="1" D="1"
C="$(grep -v "#" "$txt" | sed -e '/^$/d' | sed -n '$=')" C="$(grep -v "#" "$txt" | sed -e '/^$/d' | sed -n '$=')"
if [[ $delete_folder = true ]]; then [[ $user = 0 ]] && Apk_info="$(appinfo -sort-i -o pn -pn $system -3 | egrep -v 'ice.message|com.topjohnwu.magisk' | sort -u)" || Apk_info="$(appinfo -sort-i -o pn -pn $system $(pm list packages -3 --user "$user" | cut -f2 -d ':') | egrep -v 'ice.message|com.topjohnwu.magisk' | sort -u)"
if [[ -d $Backup ]]; then [[ $Apk_info = "" ]] && echoRgb "appinfo輸出失敗" "0" && exit 2
if [[ $1 = "" ]]; then Tmplist="$MODDIR/o"
find "$Backup" -maxdepth 1 -type d 2>/dev/null | sort | while read; do rm -rf "$Tmplist"
if [[ -f $REPLY/app_details ]]; then if [[ -d $Backup ]]; then
unset PackageName if [[ $delete_folder = true ]]; then
. "$REPLY/app_details" &>/dev/null find "$Backup" -maxdepth 1 -type d 2>/dev/null | sort | while read; do
if [[ $PackageName != "" && $(pm path --user "$user" "$PackageName" 2>/dev/null | cut -f2 -d ':') = "" ]]; then if [[ -f $REPLY/app_details ]]; then
if [[ $default_behavior = true ]]; then unset PackageName
rm -rf "$REPLY" . "$REPLY/app_details" &>/dev/null
echoRgb "${REPLY##*/}不存在系統 刪除資料夾" "0" if [[ $PackageName != "" && $(echo "$Apk_info" | egrep -w "^$PackageName$") = "" ]]; then
if [[ $default_behavior = true ]]; then
rm -rf "$REPLY"
echoRgb "${REPLY##*/}不存在系統 刪除資料夾" "0"
else
if [[ ! -d $Backup/被卸載的應用 ]]; then
mkdir -p "$Backup/被卸載的應用" && mv "$REPLY" "$Backup/被卸載的應用/"
else else
if [[ ! -d $Backup/被卸載的應用 ]]; then mv "$REPLY" "$Backup/被卸載的應用/"
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/被卸載的應用/恢復備份.sh ]] && cp -r "$script_path/restore" "$Backup/被卸載的應用/恢復備份.sh"
[[ ! -f $Backup/被卸載的應用/重新生成應用列表.sh ]] && cp -r "$script_path/Get_DirName" "$Backup/被卸載的應用/重新生成應用列表.sh"
[[ ! -f $Backup/被卸載的應用/轉換資料夾名稱.sh ]] && cp -r "$script_path/convert" "$Backup/被卸載的應用/轉換資料夾名稱.sh"
[[ ! -f $Backup/被卸載的應用/壓縮檔完整性檢查.sh ]] && cp -r "$script_path/check_file" "$Backup/被卸載的應用/壓縮檔完整性檢查.sh"
[[ ! -f $Backup/被卸載的應用/終止腳本.sh ]] && cp -r "$MODDIR/終止腳本.sh" "$Backup/被卸載的應用/終止腳本.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#主色\nrgb_a=$rgb_a\n#輔色\nrgb_b=$rgb_b\nrgb_c=$rgb_c">"$Backup/backup_settings.conf" && echo "$(sed 's/true/1/g ; s/false/0/g' "$Backup/backup_settings.conf")">"$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
[[ ! -d $Backup/被卸載的應用/tools ]] && cp -r "$tools_path" "$Backup/被卸載的應用" && rm -rf "$Backup/被卸載的應用/tools/bin/zip" "$Backup/被卸載的應用/tools/script"
[[ ! -f $Backup/被卸載的應用/恢復備份.sh ]] && cp -r "$script_path/restore" "$Backup/被卸載的應用/恢復備份.sh"
[[ ! -f $Backup/被卸載的應用/重新生成應用列表.sh ]] && cp -r "$script_path/Get_DirName" "$Backup/被卸載的應用/重新生成應用列表.sh"
[[ ! -f $Backup/被卸載的應用/轉換資料夾名稱.sh ]] && cp -r "$script_path/convert" "$Backup/被卸載的應用/轉換資料夾名稱.sh"
[[ ! -f $Backup/被卸載的應用/壓縮檔完整性檢查.sh ]] && cp -r "$script_path/check_file" "$Backup/被卸載的應用/壓縮檔完整性檢查.sh"
[[ ! -f $Backup/被卸載的應用/終止腳本.sh ]] && cp -r "$MODDIR/終止腳本.sh" "$Backup/被卸載的應用/終止腳本.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#主色\nrgb_a=$rgb_a\n#輔色\nrgb_b=$rgb_b\nrgb_c=$rgb_c">"$Backup/backup_settings.conf" && echo "$(sed 's/true/1/g ; s/false/0/g' "$Backup/backup_settings.conf")">"$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 fi
done fi
fi done
fi fi
fi fi
if [[ $1 = "" ]]; then echoRgb "檢查備份列表中是否存在已經卸載應用" "3"
echoRgb "檢查備份列表中是否存在已經卸載應用" "3" while [[ $D -le $C ]]; do
while [[ $D -le $C ]]; do name1="$(grep -v "#" "$txt" | sed -e '/^$/d' | sed -n "${D}p" | awk '{print $1}')"
name1="$(grep -v "#" "$txt" | sed -e '/^$/d' | sed -n "${D}p" | awk '{print $1}')" name2="$(grep -v "#" "$txt" | sed -e '/^$/d' | sed -n "${D}p" | awk '{print $2}')"
name2="$(grep -v "#" "$txt" | sed -e '/^$/d' | sed -n "${D}p" | awk '{print $2}')" if [[ $(echo "$Apk_info" | egrep -w "^$name2$") = "" ]]; then
if [[ $name2 != "" && $(pm path --user "$user" "$name2" 2>/dev/null | cut -f2 -d ':') = "" ]]; then echoRgb "$name1不存在系統,從列表中刪除" "0"
echoRgb "$name1不存在系統,從列表中刪除" "0" echo "$(sed -e "s/$name1 $name2//g ; /^$/d" "$txt")" >"$Tmplist"
echo "$(sed -e "s/$name1 $name2//g ; /^$/d" "$txt")" >"$txt" fi
fi let D++
let D++ done
done [[ -f $Tmplist ]] && mv "$Tmplist" "$txt"
echo "$(sed -e '/^$/d' "$txt")" >"$txt"
fi
r="$(grep -v "#" "$txt" | sed -e '/^$/d' | sed -n '$=')" r="$(grep -v "#" "$txt" | sed -e '/^$/d' | sed -n '$=')"
[[ $1 != "" ]] && r=1 [[ $1 != "" ]] && r=1
[[ $r = "" ]] && echoRgb "$MODDIR_NAME/appList.txt是空的或是包名被注釋備份個鬼\n -檢查是否注釋亦或者執行$MODDIR_NAME/生成應用列表.sh" "0" && exit 1 [[ $r = "" ]] && echoRgb "$MODDIR_NAME/appList.txt是空的或是包名被注釋備份個鬼\n -檢查是否注釋亦或者執行$MODDIR_NAME/生成應用列表.sh" "0" && exit 1
@@ -1670,8 +1663,8 @@ Getlist)
starttime1="$(date -u "+%s")" starttime1="$(date -u "+%s")"
echoRgb "提示!因為系統自帶app(位於data分區或是可卸載預裝應用)備份恢復可能存在問題\n -所以不會輸出..但是檢測為Xposed類型包名將輸出\n -如果提示不是Xposed但他就是Xposed可能為此應用元數據不符合規範導致" "0" echoRgb "提示!因為系統自帶app(位於data分區或是可卸載預裝應用)備份恢復可能存在問題\n -所以不會輸出..但是檢測為Xposed類型包名將輸出\n -如果提示不是Xposed但他就是Xposed可能為此應用元數據不符合規範導致" "0"
xposed_name="$(appinfo -o pn -xm)" xposed_name="$(appinfo -o pn -xm)"
[[ $user = 0 ]] && Apk_info="$(appinfo -sort-i -d " " -o addXpTag:'Xposed ',ands,pn -pn $system -3 | egrep -v 'ice.message|com.topjohnwu.magisk' | sort -u)" || Apk_info="$(appinfo -sort-i -d " " -o addXpTag:'Xposed 'ands,pn -pn $system $(pm list packages -3 --user "$user" | cut -f2 -d ':') | egrep -v 'ice.message|com.topjohnwu.magisk' | sort -u)" [[ $user = 0 ]] && Apk_info="$(appinfo -sort-i -d " " -o addXpTag:'Xposed: ',ands,pn -pn $system -3 | egrep -v 'ice.message|com.topjohnwu.magisk' | sort -u)" || Apk_info="$(appinfo -sort-i -d " " -o addXpTag:'Xposed 'ands,pn -pn $system $(pm list packages -3 --user "$user" | cut -f2 -d ':') | egrep -v 'ice.message|com.topjohnwu.magisk' | sort -u)"
[[ $Apk_info = "" ]] && echoRgb "appinfo輸出失敗" "0" && exit 2 || Apk_info="$(echo "$Apk_info" | sed 's/Xposed //g')" && Apk_info2="$(echo "$Apk_info" | awk '{print $2}')" [[ $Apk_info = "" ]] && echoRgb "appinfo輸出失敗" "0" && exit 2 || Apk_info="$(echo "$Apk_info" | sed 's/Xposed: //g')" && Apk_info2="$(echo "$Apk_info" | awk '{print $2}')"
Apk_Quantity="$(echo "$Apk_info" | wc -l)" Apk_Quantity="$(echo "$Apk_info" | wc -l)"
LR="1" LR="1"
echoRgb "列出第三方應用......." "2" echoRgb "列出第三方應用......." "2"
@@ -1731,16 +1724,13 @@ Getlist)
while [[ $D -le $C ]]; do while [[ $D -le $C ]]; do
name1="$(grep -v "#" "$nametxt" | sed -e '/^$/d' | sed -n "${D}p" | awk '{print $1}')" name1="$(grep -v "#" "$nametxt" | sed -e '/^$/d' | sed -n "${D}p" | awk '{print $1}')"
name2="$(grep -v "#" "$nametxt" | sed -e '/^$/d' | sed -n "${D}p" | awk '{print $2}')" name2="$(grep -v "#" "$nametxt" | sed -e '/^$/d' | sed -n "${D}p" | awk '{print $2}')"
{
if [[ $(echo "$Apk_info2" | egrep -w "^$name2$") = "" ]]; then if [[ $(echo "$Apk_info2" | egrep -w "^$name2$") = "" ]]; then
echoRgb "$name1 $name2不存在系統,從列表中刪除" "0" echoRgb "$name1 $name2不存在系統,從列表中刪除" "0"
echo "$(sed -e "s/$name1 $name2//g" "$nametxt")" >"$Tmplist" echo "$(sed -e "s/$name1 $name2//g" "$nametxt")" >"$Tmplist"
fi fi
} &
let D++ let D++
done done
[[ -f $Tmplist ]] && sed -e '/^$/d' "$Tmplist" | sort>"$nametxt" && rm -rf "$Tmplist" [[ -f $Tmplist ]] && sed -e '/^$/d' "$Tmplist" | sort>"$nametxt" && rm -rf "$Tmplist"
echo "$(sed -e '/^$/d' "$nametxt" | sort)" >"$nametxt"
fi fi
wait wait
endtime 1 endtime 1