master
rasul 5 years ago
commit a1b0f800da

@ -0,0 +1,76 @@
#!/bin/bash
# function to exit with message and code
die() {
[[ -n "$2" ]] && printf "%s\n" "$2"
[[ -n "$1" ]] && exit "$1" || exit 127
}
url="https://dyn.dns.he.net/nic/update"
help_text="Usage: $0 [OPTIONS] DOMAIN KEYFILE
Update Hurricane Electric Dynamic DNS for DOMAIN with key in KEYFILE.
Requires curl to be installed in \$PATH.
Options:
-4, --ipv4 use IPv4
-6, --ipv6 use IPv6
-u, --url url to use, defaults to $url
-h, --help Display this help.
https://gitlab.com/rascul/he-ddns
"
show_help() {
printf "%s" "$help_text"
}
args=
ipv4=
ipv6=
while (($#)); do
case $1 in
-4)
ipv4=true
;;
-6)
ipv6=true
;;
-u|--url)
if [[ -n "$2" ]]; then
url="$2"
shift
else
die $LINENO "$help_text"
fi
;;
-h|--help)
show_help
exit
;;
*)
args+=("$1")
;;
esac
shift
done
domain="${args[1]}"
key=$(<"${args[2]}") || die $LINENO
if [[ "$ipv4" != "true" ]] && [[ "$ipv6" != "true" ]]; then
echo "Must specify either IPv4 or IPv6"
fi
if [[ "$ipv4" == "true" ]]; then
ip="$(curl -sSL4 https://ifconfig.co/ip)" || die $LINENO
curl -sSL4 "$url" -d "hostname=$domain" -d "password=$key" -d "myip=$ip" || die $LINENO
echo
fi
if [[ "$ipv6" == "true" ]]; then
ip="$(curl -sSL6 https://ifconfig.co/ip)" || die $LINENO
curl -sSL6 "$url" -d "hostname=$domain" -d "password=$key" -d "myip=$ip" || die $LINENO
echo
fi

@ -0,0 +1,10 @@
[Unit]
Description=Update Hurricane Electric Dynamic DNS
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/he-ddns -4 %i /etc/he-ddns/%i
[Install]
WantedBy=multi-user.target

@ -0,0 +1,8 @@
[Unit]
Description=Update Hurricane Electric Dynamic DNS
[Timer]
OnUnitActiveSec=20min
[Install]
WantedBy=timers.target

@ -0,0 +1,10 @@
[Unit]
Description=Update Hurricane Electric Dynamic DNS
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/he-ddns -6 %i /etc/he-ddns/%i
[Install]
WantedBy=multi-user.target

@ -0,0 +1,8 @@
[Unit]
Description=Update Hurricane Electric Dynamic DNS
[Timer]
OnUnitActiveSec=20min
[Install]
WantedBy=timers.target
Loading…
Cancel
Save