mirror of
https://codeberg.org/polyteknisk-radiogruppe/the_prg_server_configuration.git
synced 2026-06-14 10:48:56 +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"];
|
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
|
# PRG Cloudflare DDNS updater - split into a single-run upstream script and a wrapper that loops records
|
||||||
environment.etc."cloudflare-ddns/update-single.sh" = {
|
environment.etc."cloudflare-ddns/update-single.sh" = {
|
||||||
text = ''
|
text = ''
|
||||||
|
|
@ -613,16 +618,16 @@ in {
|
||||||
RAW_IP=$(${pkgs.curl}/bin/curl -s $service)
|
RAW_IP=$(${pkgs.curl}/bin/curl -s $service)
|
||||||
if [[ $RAW_IP =~ $REGEX_IPV4 ]]; then
|
if [[ $RAW_IP =~ $REGEX_IPV4 ]]; then
|
||||||
CURRENT_IP=$BASH_REMATCH
|
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
|
break
|
||||||
else
|
else
|
||||||
logger -s "DDNS Updater: IP service $service failed."
|
${pkgs.util-linux}/bin/logger -s "DDNS Updater: IP service $service failed."
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Exit if IP fetching failed
|
# Exit if IP fetching failed
|
||||||
if [[ -z "$${CURRENT_IP}" ]]; then
|
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
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -639,7 +644,7 @@ in {
|
||||||
## Seek for the A record
|
## 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}" \
|
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}" \
|
||||||
|
|
@ -649,7 +654,7 @@ in {
|
||||||
## 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
|
||||||
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
|
||||||
|
|
||||||
|
|
@ -659,7 +664,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
|
||||||
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
|
||||||
|
|
||||||
|
|
@ -682,7 +687,7 @@ in {
|
||||||
###########################################
|
###########################################
|
||||||
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" | 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
|
if [[ -n "$${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}\"}"
|
||||||
|
|
@ -694,7 +699,7 @@ in {
|
||||||
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}"
|
||||||
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
|
if [[ -n "$${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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue