1 Commits

Author SHA1 Message Date
sakuradairong
d286c7cacc chore: snapshot backup before rainycy push (20260624-032434)
Auto-committed by MiMo for migration to git.rainycy.top
2026-06-24 03:26:25 +08:00
3 changed files with 103 additions and 38 deletions

16
.codegraph/.gitignore vendored Normal file
View File

@@ -0,0 +1,16 @@
# CodeGraph data files
# These are local to each machine and should not be committed
# Database
*.db
*.db-wal
*.db-shm
# Cache
cache/
# Logs
*.log
# Hook markers
.dirty

9
.gitignore vendored Normal file
View File

@@ -0,0 +1,9 @@
# IDE
.idea/
.vscode/
*.swp
*.swo
# OS
.DS_Store
Thumbs.db

View File

@@ -18,7 +18,7 @@ if [ "$(whoami)" != root ]; then
echo "你是憨批不給Root用你媽 爬"
exit 1
fi
_dex_debug=1
_dex_debug=0
[[ -d /data/cache ]] && set -x 2> /data/cache/debug_output.log
shell_language="zh-TW"
MODDIR_NAME="${MODDIR##*/}"
@@ -277,7 +277,6 @@ if [[ ! -f $conf_path ]]; then
_update_conf
echo "因腳本找不到\n$conf_path\n故重新生成默認列表\n請重新配置後重新執行腳本" && exit 0
fi
[[ ! -f $conf_path ]] && echo "$conf_path遺失" && exit 2
. "$conf_path" &>/dev/null
_update_conf
# 依 remote_type 取對應遠端位址/帳密 (smb_*/webdav_* 由 conf 設定)
@@ -287,14 +286,14 @@ webdav) remote_url="$webdav_url"; remote_user="$webdav_remote_user"; remote_pass
*) remote_url=""; remote_user=""; remote_pass="" ;;
esac
case $Shell_LANG in
1) LANG="CN" ;;
0) LANG="TW" ;;
1) SCRIPT_LANG="CN" ;;
0) SCRIPT_LANG="TW" ;;
*)
_l="$(settings get system system_locales 2>/dev/null | head -1)"
[[ -z $_l || $_l = null ]] && _l="$(getprop persist.sys.locale)"
case $_l in
zh-Hant*|zh_Hant*|zh-TW*|zh-HK*|zh-MO*) LANG="TW" ;;
zh-Hans*|zh_Hans*|zh-CN*|zh-SG*|zh*) LANG="CN" ;;
zh-Hant*|zh_Hant*|zh-TW*|zh-HK*|zh-MO*) SCRIPT_LANG="TW" ;;
zh-Hans*|zh_Hans*|zh-CN*|zh-SG*|zh*) SCRIPT_LANG="CN" ;;
esac
;;
esac
@@ -397,6 +396,11 @@ load_dir_size_map() {
eval "$_vn=\$_sz"
done < "$TMPDIR/.dir_sizes"
}
# 將 $name1 寫入 .changed_apps (去重, 避免重複記錄)
_mark_changed() {
awk -v n="$name1" 'BEGIN{f=0} $0==n{f=1;exit} END{if(!f)print n}' \
"$TMPDIR/.changed_apps" 2>/dev/null >> "$TMPDIR/.changed_apps"
}
# 通用: 把 pkg<TAB>value 表載入成動態變量 <prefix>_<pkg轉義>=value (零 fork 查詢)
# 用法: load_kv_map <檔案> <變量前綴>
load_kv_map() {
@@ -923,7 +927,7 @@ if [[ $(which toybox | grep -Eo "system") != system ]]; then
fi
#下列為自定義函數
alias down="app_process /system/bin com.xayah.dex.HttpUtil get $@"
case $LANG in
case $SCRIPT_LANG in
*CN* | *cn*)
alias ts="app_process /system/bin com.xayah.dex.CCUtil t2s $@" ;;
*)
@@ -979,7 +983,6 @@ get_version() {
# 規範化布林值,將 1/true/yes 等變成 true,其他變成 false
# 用於 conf 讀進來的開關項統一格式
isBoolean() {
unset nsx
nsx="$1"
case $1 in
1|true|True|TRUE)
@@ -3303,8 +3306,8 @@ case $MODDIR in
fi ;;
*) [[ -d $MODDIR/tools ]] && path_hierarchy="$MODDIR" ;;
esac
[[ $LANG = "" ]] && echoRgb "系統無參數語言獲取失敗\n -如果需要更改腳本語言請於$conf_path\n -Shell_LANG=填入對應數字" "0"
case $LANG in
[[ $SCRIPT_LANG = "" ]] && echoRgb "系統無參數語言獲取失敗\n -如果需要更改腳本語言請於$conf_path\n -Shell_LANG=填入對應數字" "0"
case $SCRIPT_LANG in
*TW* | *tw* | *HK*)
Script_target_language="zh-TW" ;;
*CN* | *cn*)
@@ -3479,7 +3482,7 @@ alias Set_true_Permissions="_dex /system/bin com.xayah.dex.HiddenApiUtil grantRu
alias Set_false_Permissions="_dex /system/bin com.xayah.dex.HiddenApiUtil revokeRuntimePermission $USER_ID $@"
alias Set_Ops="_dex /system/bin com.xayah.dex.HiddenApiUtil setOpsMode $USER_ID $@"
alias setDisplay="_dex /system/bin com.xayah.dex.HiddenApiUtil setDisplayPowerMode $@"
find_tools_path="$(find "$path_hierarchy"/* -maxdepth 1 -name "tools" -type d ! -path "$path_hierarchy/tools")"
find_tools_path="$(find "$path_hierarchy"/* -maxdepth 1 -name "tools" -type d ! -path "$path_hierarchy/tools" | grep -v "/Backup_[^/]*/tools$")"
# 備份 WiFi 密碼到指定目錄, 用 classes.dex 讀 system 內的 WifiConfigStore
backup_wifi() {
local wifi_dir="$1"
@@ -3598,6 +3601,17 @@ update_script() {
exit 1 ;;
esac
if unzip -l "$zipFile" 2>/dev/null | grep -q "backup_settings\.conf$"; then
# 在應用備份目錄內執行: 不解壓、不更新,僅給出導引提示
case $MODDIR in
*Backup_*)
if [[ -f $MODDIR/app_details.json ]]; then
local _hint_path="${path_hierarchy:-${MODDIR%/*}}"
echoRgb "偵測到更新包: ${zipFile##*/}" "2"
echoRgb "⚠ 目前在應用備份目錄內,無法在此執行更新" "0"
echoRgb "請到以下目錄執行 start.sh 後即可自動更新:\n -$_hint_path" "3"
return 0
fi ;;
esac
unzip -o "$zipFile" -j "tools/tools.sh" -d "$MODDIR" &>/dev/null
if [[ -f $MODDIR/tools.sh ]]; then
# 版本比對: 12 碼純數字時間戳 (e.g. 202605161200), awk 一次抓取
@@ -3606,19 +3620,12 @@ update_script() {
_cur_ver=$(echo "$backup_version" | tr -d 'a-zA-Z')
if [[ ${_new_ver:-0} -ge ${_cur_ver:-0} ]]; then
shell_language="$(awk -F= '/^shell_language=/ {gsub(/"/, "", $2); print $2}' "$MODDIR/tools.sh")"
case $MODDIR in
*Backup_*)
if [[ -f $MODDIR/app_details.json ]]; then
echoRgb "請在${MODDIR%/*}更新腳本" "0"
rm -rf "$MODDIR/tools.sh"
exit 2
fi ;;
esac
echoRgb "$zipFile更新"
if [[ -d $path_hierarchy/tools ]]; then
mv "$path_hierarchy/tools" "$TMPDIR"
[[ -d $TMPDIR/tools ]] && {
unzip -o "$zipFile" tools/* -d "$path_hierarchy" | sed 's/inflating/釋放/g ; s/creating/創建/g ; s/Archive/解壓縮/g'
chmod -R 0777 "$path_hierarchy/tools" 2>/dev/null
echo_log "解壓縮${zipFile##*/}"
if [[ $result = 0 ]]; then
if [[ $shell_language != $Script_target_language ]]; then
@@ -3634,9 +3641,13 @@ update_script() {
echo_log "$path_hierarchy/backup_settings.conf翻譯"
echo "$find_tools_path" | while read -r; do
if [[ $REPLY != $path_hierarchy/tools ]]; then
rm -rf "$REPLY"
cp -r "$path_hierarchy/tools" "${REPLY%/*}"
update_Restore_settings_conf>"${REPLY%/*}/restore_settings.conf"
# 安全守衛: REPLY 必須是絕對路徑且深度≥2層才操作, 防異常路徑誤刪
local _reply_parent="${REPLY%/*}"
[[ -z $_reply_parent || $_reply_parent = "/" || ${#_reply_parent} -lt 4 ]] && continue
[[ $REPLY != /* ]] && continue
rm -rf "$REPLY" 2>/dev/null
cp -r "$path_hierarchy/tools" "$_reply_parent"
update_Restore_settings_conf>"$_reply_parent/restore_settings.conf"
ts_inplace "${REPLY%/*}/restore_settings.conf"
echo_log "${REPLY%/*}/restore_settings.conf翻譯"
fi
@@ -3649,8 +3660,10 @@ update_script() {
else
update_path="$Output_path/$(get_backup_dirname)"
fi
rm -rf "$update_path/tools"
cp -r "$path_hierarchy/tools" "$update_path"
# FUSE 層 rm -rf 可能因權限問題失敗; 改 cp -rf 直接覆蓋無需先刪
mkdir -p "$update_path/tools" 2>/dev/null
cp -rf "$path_hierarchy/tools/." "$update_path/tools/" 2>/dev/null || cp -r "$path_hierarchy/tools" "$update_path"
chmod -R 0777 "$update_path/tools" 2>/dev/null
echoRgb "$update_path/tools已經更新完成"
fi
else
@@ -3779,20 +3792,35 @@ if [[ $json != "" ]]; then
esac
if [[ $(expr "$(echo "$backup_version" | tr -d "a-zA-Z")" \> "$(echo "$download" | tr -d "a-zA-Z")") -eq 0 ]]; then
echoRgb "發現新版本:$tag"
if [[ $update = true ]]; then
# 在應用備份目錄內: 僅提示去正確目錄,不執行下載
_skip_update_dl=0
case $MODDIR in
*Backup_*)
echo "$MODDIR"
exit
if [[ -f $MODDIR/app_details.json ]]; then
echoRgb "⚠ 目前在應用備份目錄內,無法在此下載更新" "0"
echoRgb "請到以下目錄執行 start.sh 後即可自動更新:\n -${path_hierarchy:-${MODDIR%/*}}" "3"
_skip_update_dl=1
fi ;;
esac
if [[ $_skip_update_dl = 0 && $update = true ]]; then
echoRgb "$(ts "更新日誌:\n$(down "$Language" | jq -r '.body')")"
if ask_yn "是否更新腳本?" "更新" "不更新" choose; then
echoRgb "下載中.....耐心等待 如果下載失敗請掛飛機"
starttime1="$(date -u "+%s")"
down "$zip_url" >"$MODDIR/update.zip" &
_dl_dest="${path_hierarchy:-$MODDIR}"
down "$zip_url" >"$_dl_dest/update.zip" &
wait
endtime 1
[[ ! -f $MODDIR/update.zip ]] && echoRgb "下載失敗" && exit 2
zipFile="$MODDIR/update.zip"
[[ ! -f $_dl_dest/update.zip ]] && echoRgb "下載失敗" && exit 2
zipFile="$_dl_dest/update.zip"
unset _dl_dest
fi
else
elif [[ $_skip_update_dl = 0 ]]; then
echoRgb "$conf_path內update選項為0忽略更新僅提示更新" "0"
fi
unset _skip_update_dl
fi
fi
fi
@@ -4471,7 +4499,7 @@ Backup_apk() {
# 遠端啟用但查無此備份: 不重壓, 直接把現有本地檔標記為待上傳 (流式無本地檔, 不走此路)
if [[ $remote_stream != 1 && -n $remote_type && $_remote_checked = 0 ]]; then
backup_has_changes=1
awk -v n="$name1" 'BEGIN{f=0} $0==n{f=1;exit} END{if(!f)print n}' "$TMPDIR/.changed_apps" 2>/dev/null >> "$TMPDIR/.changed_apps"
_mark_changed
echoRgb "Apk版本無更新 遠端缺檔: 直接上傳本地備份(免重壓)" "2"
else
echoRgb "Apk版本無更新 跳過備份" "2"
@@ -4543,7 +4571,7 @@ Backup_apk() {
# 標記有備份變更
backup_has_changes=1
# 記錄有變更的應用
awk -v n="$name1" 'BEGIN{f=0} $0==n{f=1;exit} END{if(!f)print n}' "$TMPDIR/.changed_apps" 2>/dev/null >> "$TMPDIR/.changed_apps"
_mark_changed
# Chrome 特例
[[ $name2 = com.android.chrome ]] && cleanup_chrome_legacy
else
@@ -4575,7 +4603,7 @@ Backup_ssaid() {
echo "$name1 \"$name2\"" >> "$TMPDIR/.ssaid_apks"
jq_inplace "$app_details" --arg entry "$name1" --arg new_value "$ssaid" '.[$entry].Ssaid |= $new_value'
echo_log "備份ssaid"
[[ $result = 0 ]] && awk -v n="$name1" 'BEGIN{f=0} $0==n{f=1;exit} END{if(!f)print n}' "$TMPDIR/.changed_apps" 2>/dev/null >> "$TMPDIR/.changed_apps"
[[ $result = 0 ]] && _mark_changed
fi
[[ $ssaid = null ]] && ssaid=
}
@@ -4592,7 +4620,7 @@ Backup_Permissions() {
echoRgb "備份權限"
jq_inplace "$app_details" --arg packageName "$name1" --argjson permissions "$Get_Permissions" '.[$packageName].permissions |= $permissions'
echo_log "備份權限"
[[ $result = 0 ]] && awk -v n="$name1" 'BEGIN{f=0} $0==n{f=1;exit} END{if(!f)print n}' "$TMPDIR/.changed_apps" 2>/dev/null >> "$TMPDIR/.changed_apps"
[[ $result = 0 ]] && _mark_changed
else
if [[ $perms_old = *true* || $perms_old = *false* ]]; then
if [[ $perms_old != $Get_Permissions ]]; then
@@ -4602,7 +4630,7 @@ Backup_Permissions() {
-r 2>/dev/null
jq_inplace "$app_details" --arg packageName "$name1" --argjson permissions "$Get_Permissions" '.[$packageName] |= . + {permissions: $permissions}'
echo_log "備份權限"
[[ $result = 0 ]] && awk -v n="$name1" 'BEGIN{f=0} $0==n{f=1;exit} END{if(!f)print n}' "$TMPDIR/.changed_apps" 2>/dev/null >> "$TMPDIR/.changed_apps"
[[ $result = 0 ]] && _mark_changed
fi
fi
fi
@@ -4620,7 +4648,7 @@ Backup_extra() {
jq_inplace "$app_details" --arg entry "$name1" --arg v "$installer" '.[$entry].installer |= $v'
echo_log "備份installer"
[[ $result = 0 ]] && echoRgb "安裝來源:$installer" "2"
[[ $result = 0 ]] && awk -v n="$name1" 'BEGIN{f=0} $0==n{f=1;exit} END{if(!f)print n}' "$TMPDIR/.changed_apps" 2>/dev/null >> "$TMPDIR/.changed_apps"
[[ $result = 0 ]] && _mark_changed
fi
# battery: 後台運行 appops mode (allow/ignore/deny), 原樣記錄與還原
local batt
@@ -4629,7 +4657,7 @@ Backup_extra() {
jq_inplace "$app_details" --arg entry "$name1" --arg v "$batt" '.[$entry].battery_opt |= $v'
echo_log "備份battery_opt"
[[ $result = 0 ]] && echoRgb "後台運行設定:$batt" "2"
[[ $result = 0 ]] && awk -v n="$name1" 'BEGIN{f=0} $0==n{f=1;exit} END{if(!f)print n}' "$TMPDIR/.changed_apps" 2>/dev/null >> "$TMPDIR/.changed_apps"
[[ $result = 0 ]] && _mark_changed
fi
}
#檢測數據位置進行備份
@@ -4716,7 +4744,7 @@ Backup_data() {
[[ $remote_stream = 1 ]] && _local_data_exists2=0
if [[ $remote_stream != 1 && -n $remote_type && $_remote_data_checked = 0 && $Size = $Filesize && $_local_data_exists2 = 1 ]]; then
backup_has_changes=1
case $1 in user|data|obb|user_de) awk -v n="$name1" 'BEGIN{f=0} $0==n{f=1;exit} END{if(!f)print n}' "$TMPDIR/.changed_apps" 2>/dev/null >> "$TMPDIR/.changed_apps" ;; esac
case $1 in user|data|obb|user_de) _mark_changed ;; esac
echoRgb "$1數據無變化 遠端缺檔: 直接上傳本地備份(免重壓)" "2"
return 0
fi
@@ -4815,7 +4843,7 @@ Backup_data() {
# 標記有備份變更
backup_has_changes=1
# 記錄有變更的應用 (排除媒體/自定義路徑備份, 由 REMOTE_UPLOAD_MEDIA 處理)
case $1 in user|data|obb|user_de) awk -v n="$name1" 'BEGIN{f=0} $0==n{f=1;exit} END{if(!f)print n}' "$TMPDIR/.changed_apps" 2>/dev/null >> "$TMPDIR/.changed_apps" ;; esac
case $1 in user|data|obb|user_de) _mark_changed ;; esac
else
rm -rf "$Backup_folder/$1".tar.*
fi
@@ -7044,6 +7072,8 @@ Getlist() {
fi
# 把累積的 append 一次寫進 txt
if [[ -s $appended ]]; then
# 修復: txt 結尾若缺換行符, 直接 append 會與新內容第一行黏成一行 (已知問題根因)
[[ -s $txt ]] && [[ -n "$(tail -c1 "$txt")" ]] && echo >> "$txt"
cat "$appended" >> "$txt"
echoRgb "已經將預裝應用輸出至appList.txt並注釋# 需要備份則去掉#" "0"
[[ -n $tmp ]] && echoRgb "\n -第三方apk數量=\"$Apk_Quantity\"\n -已過濾=\"$rc\"\n -xposed=\"$rd\"\n -黑名單應用=\"$rb\"\n -存在列表中=\"$Q\"\n -已註解略過=\"$Qc\"\n -輸出=\"$i\""
@@ -7055,7 +7085,17 @@ Getlist() {
_new_eff=$(awk '/^[[:space:]]*$/{next} /^[[:space:]]*[#!]/{next} {c++} END{print c+0}' "$appended" 2>/dev/null)
_expect=$(( ${_old_eff:-0} + ${_new_eff:-0} ))
if [[ $_eff_lines -ne $_expect ]]; then
# 診斷: 交叉比對分類桶加總 vs _old_eff
local _bucket_sum=$((${Q:-0} + ${Qc:-0} + ${rb:-0} + ${rc:-0} + ${rd:-0}))
# 偵測可疑黏行 (3+ 欄位 = 兩個 app 的行缺換行符黏在一起, 歷史資料損壞而非本次寫入問題)
local _sticky
echoRgb " ⚠️ 數量核對2異常: 列表有效行=$_eff_lines 但預期(原有$_old_eff+本次新增有效$_new_eff)=$_expect" "0"
echoRgb " [診斷] _old_eff=$_old_eff vs 分類桶加總=$_bucket_sum (Q=$Q Qc=$Qc rb=$rb rc=$rc rd=$rd)" "0" >&2
# 用 wc -l 交叉核對 _old_eff 的 awk 行數統計是否與實際檔案行數一致 (排除環境差異誤判)
local _wc_lines _wc_nonblank
_wc_lines="$(wc -l < "$txt" 2>/dev/null)"
_wc_nonblank="$(grep -vc '^[[:space:]]*$' "$txt" 2>/dev/null)"
echoRgb " [診斷] wc -l 總行數=$_wc_lines, 非空行數=$_wc_nonblank" "0" >&2
_chk_fail=1
else
echoRgb " ✅ 數量核對2: 列表有效行=$_eff_lines (原有$_old_eff+本次新增有效$_new_eff)" "1"