forked from ferrumclaudepilgrim/claude-code-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-sync.sh
More file actions
executable file
·63 lines (54 loc) · 1.91 KB
/
Copy pathcheck-sync.sh
File metadata and controls
executable file
·63 lines (54 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
# check-sync.sh: Verify the sections that install.sh and migrate.sh must keep
# byte-identical have not drifted apart.
#
# install.sh and migrate.sh independently implement the same npm-version
# resolve/download/checksum/patchelf logic and emit the same wrapper script,
# because migrate.sh mirrors install.sh instead of sourcing it. Both files
# mark the shared sections with matching "# SYNC:BEGIN <name>" / "# SYNC:END
# <name>" comments; this script extracts each named block from both files
# and diffs them. Run it after editing either script, and it also runs in CI.
#
# Usage:
# bash scripts/check-sync.sh
set -euo pipefail
here="$(cd "$(dirname "$0")/.." && pwd)"
A="$here/install.sh"
B="$here/migrate.sh"
extract_names() {
grep -oE '# SYNC:BEGIN [A-Za-z0-9_-]+' "$1" | awk '{print $3}'
}
extract_block() {
# extract_block FILE NAME
awk -v name="$2" '
$0 ~ "# SYNC:BEGIN " name { f=1; next }
$0 ~ "# SYNC:END " name { f=0 }
f { print }
' "$1"
}
names_a="$(extract_names "$A" | sort -u)"
names_b="$(extract_names "$B" | sort -u)"
if [ "$names_a" != "$names_b" ]; then
echo "[fail] SYNC block names differ between $(basename "$A") and $(basename "$B")" >&2
echo " $(basename "$A"): $(echo "$names_a" | tr '\n' ' ')" >&2
echo " $(basename "$B"): $(echo "$names_b" | tr '\n' ' ')" >&2
exit 1
fi
if [ -z "$names_a" ]; then
echo "[fail] no SYNC:BEGIN/END markers found in $(basename "$A")" >&2
exit 1
fi
fail=0
while IFS= read -r name; do
[ -z "$name" ] && continue
block_a="$(extract_block "$A" "$name")"
block_b="$(extract_block "$B" "$name")"
if [ "$block_a" != "$block_b" ]; then
echo "[fail] SYNC block '$name' has drifted between $(basename "$A") and $(basename "$B"):" >&2
diff <(printf '%s\n' "$block_a") <(printf '%s\n' "$block_b") >&2 || true
fail=1
else
echo "[ok] SYNC block '$name' matches"
fi
done <<< "$names_a"
exit "$fail"