mirror of
https://codeberg.org/polyteknisk-radiogruppe/the_prg_server_configuration.git
synced 2026-06-13 18:28:55 +02:00
Add util-linux package and update logger invocations.
This commit is contained in:
parent
59eb7ee53c
commit
9baecf63f8
1 changed files with 13 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue