diff --git a/nix-system-configs/modules/system/traefik.nix b/nix-system-configs/modules/system/traefik.nix index f7e763b..0d19bc9 100644 --- a/nix-system-configs/modules/system/traefik.nix +++ b/nix-system-configs/modules/system/traefik.nix @@ -614,7 +614,7 @@ in { ) # 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" RAW_IP=$(curl -s "$service") 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" break 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 done # 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." exit 2 fi @@ -637,7 +637,7 @@ in { ########################################### ## Check and set the proper auth header ########################################### - if [[ "$${auth_method}" == "global" ]]; then + if [[ "''${auth_method}" == "global" ]]; then auth_header="X-Auth-Key:" else auth_header="Authorization: Bearer" @@ -648,16 +648,16 @@ in { ########################################### ${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}" \ - -H "X-Auth-Email: $${auth_email}" \ - -H "$${auth_header} $${auth_key}" \ + 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 "''${auth_header} ''${auth_key}" \ -H "Content-Type: application/json") ########################################### ## Check if the domain has an A record ########################################### 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 fi @@ -667,7 +667,7 @@ in { old_ip=$(echo "$record" | sed -E 's/.*"content":"(([0-9]{1,3}\\.){3}[0-9]{1,3})".*/\\1/') # Compare if they're the same 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 fi @@ -679,35 +679,35 @@ in { ########################################### ## 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}" \ - -H "X-Auth-Email: $${auth_email}" \ - -H "$${auth_header} $${auth_key}" \ + 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 "''${auth_header} ''${auth_key}" \ -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) ########################################### case "$update" in *"\\\"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 - 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}\"}" + 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}\"}" fi if [[ $discorduri != "" ]]; then - 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}" + 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}" fi exit 1;; *) - 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." + 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." 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 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 exit 0;; esac @@ -729,13 +729,13 @@ in { fi # Map env variables from the env file into auth_key/auth_email used by the upstream script - if [ -n "$${CLOUDFLARE_DNS_API_TOKEN:-}" ]; then - export auth_key="$${CLOUDFLARE_DNS_API_TOKEN:-}" - elif [ -n "$${CLOUDFLARE_API_TOKEN:-}" ]; then - export auth_key="$${CLOUDFLARE_API_TOKEN:-}" + if [ -n "''${CLOUDFLARE_DNS_API_TOKEN:-}" ]; then + export auth_key="''${CLOUDFLARE_DNS_API_TOKEN:-}" + elif [ -n "''${CLOUDFLARE_API_TOKEN:-}" ]; then + export auth_key="''${CLOUDFLARE_API_TOKEN:-}" fi - if [ -n "$${CLOUDFLARE_USERNAME:-}" ]; then - export auth_email="$${CLOUDFLARE_USERNAME:-}" + if [ -n "''${CLOUDFLARE_USERNAME:-}" ]; then + export auth_email="''${CLOUDFLARE_USERNAME:-}" fi # Ensure zone id is exported for the single-run script