Add util-linux package and update logger invocations.

This commit is contained in:
Root User 2026-03-03 12:20:55 +01:00
parent 59eb7ee53c
commit 9baecf63f8
Signed by: root
GPG key ID: 087F0A95E5766D72

View file

@ -574,6 +574,11 @@ in {
reloadServices = ["traefik.service"];
};
};
environment.systemPackages = with pkgs; [
util-linux
];
# 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 = ''
@ -613,16 +618,16 @@ in {
RAW_IP=$(${pkgs.curl}/bin/curl -s $service)
if [[ $RAW_IP =~ $REGEX_IPV4 ]]; then
CURRENT_IP=$BASH_REMATCH
logger -s "DDNS Updater: Fetched IP $CURRENT_IP"
${pkgs.util-linux}/bin/logger -s "DDNS Updater: Fetched IP $CURRENT_IP"
break
else
logger -s "DDNS Updater: IP service $service failed."
${pkgs.util-linux}/bin/logger -s "DDNS Updater: IP service $service failed."
fi
done
# Exit if IP fetching failed
if [[ -z "$${CURRENT_IP}" ]]; then
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
fi
@ -639,7 +644,7 @@ in {
## Seek for the A record
###########################################
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}" \
-H "X-Auth-Email: $${auth_email}" \
-H "$${auth_header} $${auth_key}" \
@ -649,7 +654,7 @@ in {
## Check if the domain has an A record
###########################################
if [[ $record == *"\\"count\\":0"* ]]; then
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
@ -659,7 +664,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
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
@ -682,7 +687,7 @@ in {
###########################################
case "$update" in
*"\\\"success\\\":false"*)
echo -e "DDNS Updater: $${CURRENT_IP} $${record_name} DDNS failed for $${record_identifier} ($${CURRENT_IP}). DUMPING RESULTS:\n$update" | 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 [[ -n "$${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}\"}"
@ -694,7 +699,7 @@ in {
exit 1;;
*)
msg="$${sitename} Updated: $${record_name}'s new IP Address is $${CURRENT_IP}"
logger "DDNS Updater: $${CURRENT_IP} $${record_name} DDNS updated."
${pkgs.util-linux}/bin/logger "DDNS Updater: $${CURRENT_IP} $${record_name} DDNS updated."
if [[ -n "$${slackuri}" ]]; then
${pkgs.curl}/bin/curl -L -X POST "$${slackuri}" --data-raw "{\"channel\":\"$${slackchannel}\",\"text\":\"$${msg}\"}"
fi