Files
backup_script/tools/script/delete_backup
2022-01-02 21:09:28 +08:00

22 lines
1.1 KiB
Plaintext

MODDIR="${0%/*}"
tools_path="$MODDIR/tools"
bin_path="$tools_path/bin"
[[ ! -d $tools_path ]] && echo "$tools_path二進制目錄遺失" && EXIT="true"
[[ ! -d $bin_path ]] && echo "$bin_path關鍵目錄遺失" && EXIT="true"
[[ ! -f $bin_path/bin.sh ]] && echo "$bin_path/bin.sh關鍵腳本遺失" && EXIT="true"
[[ $EXIT == true ]] && exit 1
. "$bin_path/bin.sh"
echoRgb "警告 此腳本將刪除任何未被安裝的應用備份\n -你的備份將一去不復返,10秒內退出腳本還有生還機會" "0" && sleep 10
find "$MODDIR" -maxdepth 2 -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
echoRgb "${REPLY##*/}不存在系統,刪除備份"
rm -rf "$REPLY"
if [[ ${REPLY%/*}/應用列表.txt ]]; then
cat "${REPLY%/*}/應用列表.txt" | sed -e "s/${REPLY##*/} $PackageName//g ; /^$/d" | sort >"${REPLY%/*}/應用列表.tmp" && mv "${REPLY%/*}/應用列表.tmp" "${REPLY%/*}/應用列表.txt"
fi
fi
fi
done