Make it invoke curl the Nix way.

This commit is contained in:
Root User 2026-03-03 12:00:33 +01:00
parent f3b0eaf58a
commit b950416a42
Signed by: root
GPG key ID: 087F0A95E5766D72

View file

@ -574,7 +574,6 @@ in {
reloadServices = ["traefik.service"];
};
};
# PRG Cloudflare DDNS updater - split into a single-run upstream script and a wrapper that loops records
environment.etc."cloudflare-ddns/update-single.sh" = {
text = ''
@ -611,7 +610,7 @@ in {
# Try all the ip services for a valid IPv4 address
for service in $${IP_SERVICES[@]}; do
RAW_IP=$(curl -s $service)
RAW_IP=$(${pkgs.curl} -s $service)
if [[ $RAW_IP =~ $REGEX_IPV4 ]]; then
CURRENT_IP=$BASH_REMATCH
logger -s "DDNS Updater: Fetched IP $CURRENT_IP"
@ -641,7 +640,7 @@ in {
###########################################
logger "DDNS Updater: Check Initiated"
record=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$${zone_identifier}/dns_records?type=A&name=$${record_name}" \
record=$(${pkgs.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")
@ -672,7 +671,7 @@ in {
###########################################
## Change the IP@Cloudflare using the API
###########################################
update=$(curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/$${zone_identifier}/dns_records/$${record_identifier}" \
update=$(${pkgs.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" \
@ -686,21 +685,21 @@ in {
echo -e "DDNS Updater: $${CURRENT_IP} $${record_name} DDNS failed for $${record_identifier} ($${CURRENT_IP}). DUMPING RESULTS:\n$update" | logger -s
if [[ -n "$${slackuri}" ]]; then
msg="$${sitename} DDNS Update Failed: $${record_name}: $${record_identifier} ($${CURRENT_IP})."
curl -L -X POST "$${slackuri}" --data-raw "{\"channel\":\"$${slackchannel}\",\"text\":\"$${msg}\"}"
${pkgs.curl} -L -X POST "$${slackuri}" --data-raw "{\"channel\":\"$${slackchannel}\",\"text\":\"$${msg}\"}"
fi
if [[ -n "$${discorduri}" ]]; then
msg="$${sitename} DDNS Update Failed: $${record_name}: $${record_identifier} ($${CURRENT_IP})."
curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data-raw "{\"content\":\"$${msg}\"}" "$${discorduri}"
${pkgs.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}"
logger "DDNS Updater: $${CURRENT_IP} $${record_name} DDNS updated."
if [[ -n "$${slackuri}" ]]; then
curl -L -X POST "$${slackuri}" --data-raw "{\"channel\":\"$${slackchannel}\",\"text\":\"$${msg}\"}"
${pkgs.curl} -L -X POST "$${slackuri}" --data-raw "{\"channel\":\"$${slackchannel}\",\"text\":\"$${msg}\"}"
fi
if [[ -n "$${discorduri}" ]]; then
curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data-raw "{\"content\":\"$${msg}\"}" "$${discorduri}"
${pkgs.curl} -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data-raw "{\"content\":\"$${msg}\"}" "$${discorduri}"
fi
exit 0;;
esac