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:
@@ -163,12 +163,33 @@ if [[ "${ADD_UNION,,}" == "y" ]]; then
|
||||
3) UPSTREAM_TAG=":writeback" ;;
|
||||
*) warn "Invalid choice, defaulting to full read/write."; UPSTREAM_TAG="" ;;
|
||||
esac
|
||||
UPSTREAM="${SPOKE_NAME}-remote:${UNION_PATH}${UPSTREAM_TAG}"
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user