diff --git a/he-ddns b/he-ddns index c5a73a9..da40549 100755 --- a/he-ddns +++ b/he-ddns @@ -7,15 +7,14 @@ die() { } url="https://dyn.dns.he.net/nic/update" +config="/usr/local/etc/he-ddnsrc" -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. +help_text="Usage: $0 [OPTIONS] +Update Hurricane Electric Dynamic DNS for domains in the configuration file +with associated keys. 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 @@ -26,11 +25,6 @@ show_help() { printf "%s" "$help_text" } -args= -ipv4= -ipv6= -config=/etc/he-ddnsrc - while (($#)); do case $1 in -c|--config) @@ -41,20 +35,6 @@ while (($#)); do 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 @@ -66,21 +46,21 @@ while (($#)); do shift done -domain="${args[1]}" -key=$(<"${args[2]}") || die $LINENO +# shellcheck source=he-ddnsrc +. "$config" || 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 +ipv4="$(curl -sSL4 https://ifconfig.co/ip)" || die $LINENO +for domain in "${!DOMAINS4[@]}"; do + printf "%s :: " "$domain" + key=${DOMAINS4[$domain]} + curl -sSL4 "$url" -d "hostname=$domain" -d "password=$key" -d "myip=$ipv4" || die $LINENO echo -fi +done -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 +ipv6="$(curl -sSL6 https://ifconfig.co/ip)" || die $LINENO +for domain in "${!DOMAINS6[@]}"; do + printf "%s :: " "$domain" + key=${DOMAINS6[$domain]} + curl -sSL6 "$url" -d "hostname=$domain" -d "password=$key" -d "myip=$ipv6" || die $LINENO echo -fi +done