defiant: Add domeneshop-dyndns
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
./services/wireguard.nix
|
||||
|
||||
# Services
|
||||
./services/dyndns.nix
|
||||
./services/flame.nix
|
||||
./services/gitea.nix
|
||||
./services/hedgedoc.nix
|
||||
|
||||
26
hosts/defiant/services/dyndns.nix
Normal file
26
hosts/defiant/services/dyndns.nix
Normal file
@@ -0,0 +1,26 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
dnsname = "site3.feal.no";
|
||||
in {
|
||||
# Defines DDNS_TOKEN and DDNS_SECRET from https://domene.shop/admin?view=api
|
||||
sops.secrets."domeneshop/env" = { };
|
||||
|
||||
systemd.services.domeneshop-dyndns = {
|
||||
serviceConfig.EnvironmentFile = config.sops.secrets."domeneshop/env".path;
|
||||
startAt = "*/10 * * * *";
|
||||
|
||||
script = ''
|
||||
DNSNAME="${dnsname}"
|
||||
NEW_IP="$(${lib.getExe pkgs.curl} --silent https://ipinfo.io/ip)"
|
||||
OLD_IP="$(${lib.getExe pkgs.getent} hosts "$DNSNAME" | ${lib.getExe pkgs.gawk} '{ print $1 }')"
|
||||
|
||||
if [[ "$NEW_IP" != "$OLD_IP" ]]; then
|
||||
echo "Old IP ($OLD_IP) does not match new IP ($NEW_IP), updating..."
|
||||
${lib.getExe pkgs.curl} --silent "https://$DDNS_TOKEN:$DDNS_SECRET@api.domeneshop.no/v0/dyndns/update?hostname=$DNSNAME&myip=$NEW_IP"
|
||||
else
|
||||
echo "Old IP ($OLD_IP) matches new IP ($NEW_IP), exiting..."
|
||||
fi
|
||||
'';
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user