From 6db5e9769e780a115bc965420f3988f990008b25 Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Sat, 18 Apr 2026 21:46:48 -0700 Subject: [PATCH] onboard-spoke.sh: replace grep -A5 union duplicate check with python3 for reliable section parsing --- hub/onboard-spoke.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/hub/onboard-spoke.sh b/hub/onboard-spoke.sh index 7c78231..ef41cea 100755 --- a/hub/onboard-spoke.sh +++ b/hub/onboard-spoke.sh @@ -169,7 +169,24 @@ if [[ "${ADD_UNION,,}" == "y" ]]; then UPSTREAM="${SPOKE_NAME}-remote:${UPSTREAM_TAG}" fi if grep -q "^\[${UNION_NAME}\]" "$RCLONE_CONF" 2>/dev/null; then - if grep -A5 "^\[${UNION_NAME}\]" "$RCLONE_CONF" | grep -qF "${SPOKE_NAME}-remote:"; then + ALREADY=$(python3 - "$RCLONE_CONF" "$UNION_NAME" "${SPOKE_NAME}-remote:" <<'PYEOF' +import sys +path, section, prefix = sys.argv[1], sys.argv[2], sys.argv[3] +with open(path) as f: + lines = f.readlines() +in_section = False +for line in lines: + if line.strip() == f"[{section}]": + in_section = True + elif line.strip().startswith("["): + in_section = False + if in_section and line.startswith("upstreams =") and prefix in line: + print("yes") + raise SystemExit +print("no") +PYEOF +) + if [ "$ALREADY" = "yes" ]; then warn "Upstream for ${SPOKE_NAME}-remote already in union remote [${UNION_NAME}], skipping." else python3 - "$RCLONE_CONF" "$UNION_NAME" "$UPSTREAM" <<'PYEOF'