From c87557d537fd13ded8d60a87f61c8e538ef0eb7e Mon Sep 17 00:00:00 2001 From: purpl Date: Fri, 3 Jul 2026 11:29:20 +0800 Subject: [PATCH] fix: correct zip root path and add idempotent build.prop append - Fix ZIPROOT path from 3 to 4 levels up (../../../../) - Add path validation before install - Replace simple cat append with key-based dedup for build.prop (skips existing keys to prevent duplication on re-flash) - Update AGENTS.md and README.md to reflect the changes --- AGENTS.md | 22 +++++++++++++++++----- META-INF/com/google/android/update-binary | 20 +++++++++++++++++--- README.md | 7 ++++--- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index a1d0e40..655781f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -34,7 +34,7 @@ zip root ### Install flow (update-binary) -1. Locate zip root: `dirname $0` → up 3 levels (`../../..`) +1. Locate zip root: `dirname $0` → up 4 levels (`../../../../`) 2. Mount `/system` and `/vendor` 3. **Append** `system/build.prop` → `/system/build.prop` (backup first to `.bak`) 4. Copy `goodix_ts.idc` → `/system/usr/idc/` @@ -43,11 +43,23 @@ zip root ### Critical constraint: build.prop is APPENDED, never replaced -`update-binary` line ~72: `cat "$BUILDPROP_SRC" >> /system/build.prop` +`update-binary` now uses **key-based dedup**: each line is appended only if its +key (`key=` before `=`) does not already exist in the target. -The `>>` is intentional. Using `>` or `package_extract_dir` would clobber the -device's existing properties. Re-flashing duplicates entries — warn the user or -add idempotency if this becomes a problem. +```sh +# 去重追加:逐 key 检查,仅追加不存在的条目 +while IFS= read -r line || [ -n "$line" ]; do + case "$line" in + ''|'#'*) continue;; + esac + key="${line%%=*}" + if ! grep -q "^${key}=" /system/build.prop 2>/dev/null; then + echo "$line" >> /system/build.prop + fi +done < "$BUILDPROP_SRC" +``` + +Re-flashing is now safe — entries are never duplicated. ## Key Files diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary index 003f6e3..3ae0f3b 100644 --- a/META-INF/com/google/android/update-binary +++ b/META-INF/com/google/android/update-binary @@ -33,7 +33,13 @@ abort() { # The script lives at: META-INF/com/google/android/update-binary # Zip root is 3 levels up from the script's directory. SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) -ZIPROOT=$(cd "$SCRIPT_DIR/../../.." && pwd) +# 脚本位于 META-INF/com/google/android/update-binary,向上4级到 zip 根 +ZIPROOT=$(cd "$SCRIPT_DIR/../../../../" && pwd) + +# 验证路径正确 +if [ ! -f "$ZIPROOT/system/build.prop" ]; then + abort "Cannot locate zip root (system/build.prop not found)." +fi ui_print "========================================" ui_print " CB-C6s-STU-GSI-Fixes" @@ -68,8 +74,16 @@ fi cp /system/build.prop /system/build.prop.bak 2>/dev/null chmod 644 /system/build.prop.bak 2>/dev/null -# APPEND — 使用 >> 追加而非覆盖 -cat "$BUILDPROP_SRC" >> /system/build.prop +# 去重追加:逐 key 检查,仅追加不存在的条目 +while IFS= read -r line || [ -n "$line" ]; do + case "$line" in + ''|'#'*) continue;; + esac + key="${line%%=*}" + if ! grep -q "^${key}=" /system/build.prop 2>/dev/null; then + echo "$line" >> /system/build.prop + fi +done < "$BUILDPROP_SRC" chmod 644 /system/build.prop ui_print "build.prop: entries appended. Backup at build.prop.bak" diff --git a/README.md b/README.md index 1c8d039..e8a0719 100644 --- a/README.md +++ b/README.md @@ -76,9 +76,10 @@ During flash, TWRP will show: ## Notes -- The `build.prop` entries are **appended, not replaced**. Re-flashing - the zip multiple times will duplicate the entries — restore from - `/system/build.prop.bak` if needed, or inspect the file first. +- The `build.prop` entries are **appended with dedup** — each property key + (`key=value`) is only added if the key does not already exist in + `/system/build.prop`. Re-flashing the zip multiple times is safe and + will **not** duplicate entries. - The `sensor_config.xml` covers four camera sensor combinations: rear (`hi846`, `gc8034_rear`) and front (`hi846_front`, `gc8034`), each with OTP EEPROM tuning parameters.