1
0
forked from finn/tinyboard

onboard-spoke.sh: fix upstream construction for empty path with tag, replace fragile sed range with python3 for reliable union upstream append

This commit is contained in:
Justin Oros
2026-04-18 21:45:02 -07:00
parent 92b74d8f67
commit c75b29a5ea

View File

@@ -163,12 +163,33 @@ if [[ "${ADD_UNION,,}" == "y" ]]; then
3) UPSTREAM_TAG=":writeback" ;;
*) warn "Invalid choice, defaulting to full read/write."; UPSTREAM_TAG="" ;;
esac
if [ -n "$UNION_PATH" ]; then
UPSTREAM="${SPOKE_NAME}-remote:${UNION_PATH}${UPSTREAM_TAG}"
else
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
warn "Upstream for ${SPOKE_NAME}-remote already in union remote [${UNION_NAME}], skipping."
else
sed -i "/^\[${UNION_NAME}\]/,/^\[/{s|^upstreams = \(.*\)|upstreams = \1 ${UPSTREAM}|}" "$RCLONE_CONF"
python3 - "$RCLONE_CONF" "$UNION_NAME" "$UPSTREAM" <<'PYEOF'
import sys
path, section, upstream = sys.argv[1], sys.argv[2], sys.argv[3]
with open(path) as f:
lines = f.readlines()
out = []
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 ="):
line = line.rstrip() + " " + upstream + "\n"
out.append(line)
with open(path, "w") as f:
f.writelines(out)
PYEOF
info "Added '$UPSTREAM' to union remote [${UNION_NAME}]."
fi
else