forked from finn/tinyboard
onboard-spoke.sh: replace grep -A5 union duplicate check with python3 for reliable section parsing
This commit is contained in:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user