Fix broken bash script... again.

This commit is contained in:
Root User 2026-03-03 13:01:52 +01:00
parent 44a32b9c9f
commit 70c82683f6
Signed by: root
GPG key ID: 087F0A95E5766D72

View file

@ -614,7 +614,7 @@ in {
) )
# Try all the ip services for a valid IPv4 address # Try all the ip services for a valid IPv4 address
for service in "$${IP_SERVICES[@]}"; do for service in ''${IP_SERVICES[@]}; do
echo "Testing service: $service" echo "Testing service: $service"
RAW_IP=$(curl -s "$service") RAW_IP=$(curl -s "$service")
RAW_IP=$(echo "$RAW_IP" | tr -d '\n' | tr -d '\r' | xargs) RAW_IP=$(echo "$RAW_IP" | tr -d '\n' | tr -d '\r' | xargs)
@ -624,12 +624,12 @@ in {
${pkgs.util-linux}/bin/logger -s "DDNS Updater: Fetched IP $CURRENT_IP" ${pkgs.util-linux}/bin/logger -s "DDNS Updater: Fetched IP $CURRENT_IP"
break break
else else
${pkgs.util-linux}/bin/logger -s "DDNS Updater: IP service $service failed." ${pkgs.util-linux}/bin/logger -s "DDNS Updater: IP service $service failed. Raw: '$RAW_IP'"
fi fi
done done
# Exit if IP fetching failed # Exit if IP fetching failed
if [[ -z "$${CURRENT_IP}" ]]; then if [[ -z "''${CURRENT_IP}" ]]; then
${pkgs.util-linux}/bin/logger -s "DDNS Updater: Failed to find a valid IP." ${pkgs.util-linux}/bin/logger -s "DDNS Updater: Failed to find a valid IP."
exit 2 exit 2
fi fi
@ -637,7 +637,7 @@ in {
########################################### ###########################################
## Check and set the proper auth header ## Check and set the proper auth header
########################################### ###########################################
if [[ "$${auth_method}" == "global" ]]; then if [[ "''${auth_method}" == "global" ]]; then
auth_header="X-Auth-Key:" auth_header="X-Auth-Key:"
else else
auth_header="Authorization: Bearer" auth_header="Authorization: Bearer"
@ -648,16 +648,16 @@ in {
########################################### ###########################################
${pkgs.util-linux}/bin/logger "DDNS Updater: Check Initiated" ${pkgs.util-linux}/bin/logger "DDNS Updater: Check Initiated"
record=$(${pkgs.curl}/bin/curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$${zone_identifier}/dns_records?type=A&name=$${record_name}" \ record=$(${pkgs.curl}/bin/curl -s -X GET "https://api.cloudflare.com/client/v4/zones/''${zone_identifier}/dns_records?type=A&name=''${record_name}" \
-H "X-Auth-Email: $${auth_email}" \ -H "X-Auth-Email: ''${auth_email}" \
-H "$${auth_header} $${auth_key}" \ -H "''${auth_header} ''${auth_key}" \
-H "Content-Type: application/json") -H "Content-Type: application/json")
########################################### ###########################################
## Check if the domain has an A record ## Check if the domain has an A record
########################################### ###########################################
if [[ $record == *"\\"count\\":0"* ]]; then if [[ $record == *"\\"count\\":0"* ]]; then
${pkgs.util-linux}/bin/logger -s "DDNS Updater: Record does not exist, perhaps create one first? ($${CURRENT_IP} for $${record_name})" ${pkgs.util-linux}/bin/logger -s "DDNS Updater: Record does not exist, perhaps create one first? (''${CURRENT_IP} for ''${record_name})"
exit 1 exit 1
fi fi
@ -667,7 +667,7 @@ in {
old_ip=$(echo "$record" | sed -E 's/.*"content":"(([0-9]{1,3}\\.){3}[0-9]{1,3})".*/\\1/') old_ip=$(echo "$record" | sed -E 's/.*"content":"(([0-9]{1,3}\\.){3}[0-9]{1,3})".*/\\1/')
# Compare if they're the same # Compare if they're the same
if [[ $CURRENT_IP == $old_ip ]]; then if [[ $CURRENT_IP == $old_ip ]]; then
${pkgs.util-linux}/bin/logger "DDNS Updater: IP ($CURRENT_IP) for $${record_name} has not changed." ${pkgs.util-linux}/bin/logger "DDNS Updater: IP ($CURRENT_IP) for ''${record_name} has not changed."
exit 0 exit 0
fi fi
@ -679,35 +679,35 @@ in {
########################################### ###########################################
## Change the IP@Cloudflare using the API ## Change the IP@Cloudflare using the API
########################################### ###########################################
update=$(${pkgs.curl}/bin/curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/$${zone_identifier}/dns_records/$${record_identifier}" \ update=$(${pkgs.curl}/bin/curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/''${zone_identifier}/dns_records/''${record_identifier}" \
-H "X-Auth-Email: $${auth_email}" \ -H "X-Auth-Email: ''${auth_email}" \
-H "$${auth_header} $${auth_key}" \ -H "''${auth_header} ''${auth_key}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
--data "{\"type\":\"A\",\"name\":\"$${record_name}\",\"content\":\"$${CURRENT_IP}\",\"ttl\":$${ttl},\"proxied\":$${proxy}}") --data "{\"type\":\"A\",\"name\":\"''${record_name}\",\"content\":\"''${CURRENT_IP}\",\"ttl\":''${ttl},\"proxied\":''${proxy}}")
########################################### ###########################################
## Report the status (simplified payload construction to avoid nested-quote issues) ## Report the status (simplified payload construction to avoid nested-quote issues)
########################################### ###########################################
case "$update" in case "$update" in
*"\\\"success\\\":false"*) *"\\\"success\\\":false"*)
echo -e "DDNS Updater: $${CURRENT_IP} $${record_name} DDNS failed for $${record_identifier} ($${CURRENT_IP}). DUMPING RESULTS:\n$update" | ${pkgs.util-linux}/bin/logger -s echo -e "DDNS Updater: ''${CURRENT_IP} ''${record_name} DDNS failed for ''${record_identifier} (''${CURRENT_IP}). DUMPING RESULTS:\n$update" | ${pkgs.util-linux}/bin/logger -s
if [[ $slackuri != "" ]]; then if [[ $slackuri != "" ]]; then
msg="$${sitename} DDNS Update Failed: $${record_name}: $${record_identifier} ($${CURRENT_IP})." msg="''${sitename} DDNS Update Failed: ''${record_name}: ''${record_identifier} (''${CURRENT_IP})."
${pkgs.curl}/bin/curl -L -X POST "$${slackuri}" --data-raw "{\"channel\":\"$${slackchannel}\",\"text\":\"$${msg}\"}" ${pkgs.curl}/bin/curl -L -X POST "''${slackuri}" --data-raw "{\"channel\":\"''${slackchannel}\",\"text\":\"''${msg}\"}"
fi fi
if [[ $discorduri != "" ]]; then if [[ $discorduri != "" ]]; then
msg="$${sitename} DDNS Update Failed: $${record_name}: $${record_identifier} ($${CURRENT_IP})." msg="''${sitename} DDNS Update Failed: ''${record_name}: ''${record_identifier} (''${CURRENT_IP})."
${pkgs.curl}/bin/curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data-raw "{\"content\":\"$${msg}\"}" "$${discorduri}" ${pkgs.curl}/bin/curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data-raw "{\"content\":\"''${msg}\"}" "''${discorduri}"
fi fi
exit 1;; exit 1;;
*) *)
msg="$${sitename} Updated: $${record_name}'s new IP Address is $${CURRENT_IP}" msg="''${sitename} Updated: ''${record_name}'s new IP Address is ''${CURRENT_IP}"
${pkgs.util-linux}/bin/logger "DDNS Updater: $${CURRENT_IP} $${record_name} DDNS updated." ${pkgs.util-linux}/bin/logger "DDNS Updater: ''${CURRENT_IP} ''${record_name} DDNS updated."
if [[ $slackuri != "" ]]; then if [[ $slackuri != "" ]]; then
${pkgs.curl}/bin/curl -L -X POST "$${slackuri}" --data-raw "{\"channel\":\"$${slackchannel}\",\"text\":\"$${msg}\"}" ${pkgs.curl}/bin/curl -L -X POST "''${slackuri}" --data-raw "{\"channel\":\"''${slackchannel}\",\"text\":\"''${msg}\"}"
fi fi
if [[ $discorduri != "" ]]; then if [[ $discorduri != "" ]]; then
${pkgs.curl}/bin/curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data-raw "{\"content\":\"$${msg}\"}" "$${discorduri}" ${pkgs.curl}/bin/curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data-raw "{\"content\":\"''${msg}\"}" "''${discorduri}"
fi fi
exit 0;; exit 0;;
esac esac
@ -729,13 +729,13 @@ in {
fi fi
# Map env variables from the env file into auth_key/auth_email used by the upstream script # Map env variables from the env file into auth_key/auth_email used by the upstream script
if [ -n "$${CLOUDFLARE_DNS_API_TOKEN:-}" ]; then if [ -n "''${CLOUDFLARE_DNS_API_TOKEN:-}" ]; then
export auth_key="$${CLOUDFLARE_DNS_API_TOKEN:-}" export auth_key="''${CLOUDFLARE_DNS_API_TOKEN:-}"
elif [ -n "$${CLOUDFLARE_API_TOKEN:-}" ]; then elif [ -n "''${CLOUDFLARE_API_TOKEN:-}" ]; then
export auth_key="$${CLOUDFLARE_API_TOKEN:-}" export auth_key="''${CLOUDFLARE_API_TOKEN:-}"
fi fi
if [ -n "$${CLOUDFLARE_USERNAME:-}" ]; then if [ -n "''${CLOUDFLARE_USERNAME:-}" ]; then
export auth_email="$${CLOUDFLARE_USERNAME:-}" export auth_email="''${CLOUDFLARE_USERNAME:-}"
fi fi
# Ensure zone id is exported for the single-run script # Ensure zone id is exported for the single-run script