You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
he-ddns/he-ddns

87 lines
1.6 KiB

#!/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:
-c, --config FILE get configuration from FILE instead of $config
-4, --ipv4 use IPv4
-6, --ipv6 use IPv6
-u, --url URL update dns at URL instead of $url
-h, --help display this help
https://gitlab.com/rascul/he-ddns
"
show_help() {
printf "%s" "$help_text"
}
args=
ipv4=
ipv6=
config=/etc/he-ddnsrc
while (($#)); do
case $1 in
-c|--config)
if [[ -n "$2" ]]; then
config="$2"
shift
else
die $LINENO "$help_text"
fi
;;
-4|--ipv4)
ipv4=true
;;
-6|--ipv6)
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