onboard-spoke.sh: replace printf with python3 to correctly write rclone remote config with real newlines

This commit is contained in:
Justin Oros
2026-04-19 15:04:39 -07:00
parent eaff38477c
commit 97aff6a741

View File

@@ -125,7 +125,12 @@ if grep -q "\[${SPOKE_NAME}-remote\]" "$RCLONE_CONF" 2>/dev/null; then
warn "Remote [${SPOKE_NAME}-remote] already exists in $RCLONE_CONF, skipping."
else
[ -s "$RCLONE_CONF" ] && tail -c1 "$RCLONE_CONF" | grep -qv $'\n' && echo "" >> "$RCLONE_CONF"
printf '\\n[%s-remote]\\ntype = sftp\\nhost = localhost\\nport = %s\\nkey_file = %s\\nshell_type = unix\\nmd5sum_command = md5sum\\nsha1sum_command = sha1sum\\n' "$SPOKE_NAME" "$TUNNEL_PORT" "$KEY_PATH" >> "$RCLONE_CONF"
python3 - "$RCLONE_CONF" "$SPOKE_NAME" "$TUNNEL_PORT" "$KEY_PATH" <<'PYEOF'
import sys
path, name, port, key = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]
with open(path, 'a') as f:
f.write(f"\n[{name}-remote]\ntype = sftp\nhost = localhost\nport = {port}\nkey_file = {key}\nshell_type = unix\nmd5sum_command = md5sum\nsha1sum_command = sha1sum\n")
PYEOF
info "Remote [${SPOKE_NAME}-remote] added to $RCLONE_CONF."
fi
@@ -135,7 +140,7 @@ ADD_UNION="${ADD_UNION:-n}"
if [[ "${ADD_UNION,,}" == "y" ]]; then
read -rp "Union remote name [shared-union]: " UNION_NAME
UNION_NAME="${UNION_NAME:-shared-union}"
read -rp "Subfolder path on this spoke (e.g. books, leave blank for root): " UNION_PATH
read -rp "Subfolder path on the spoke being onboarded (e.g. books, leave blank for root): " UNION_PATH
echo ""
echo "Upstream access mode for this spoke:"
echo " 0) None - full read/write (default)"