use a config file which specifies v4 and v6

master
rasul 5 years ago
parent 35ca744bde
commit 28db0876b1

@ -7,15 +7,14 @@ die() {
} }
url="https://dyn.dns.he.net/nic/update" url="https://dyn.dns.he.net/nic/update"
config="/usr/local/etc/he-ddnsrc"
help_text="Usage: $0 [OPTIONS] DOMAIN KEYFILE help_text="Usage: $0 [OPTIONS]
Update Hurricane Electric Dynamic DNS for DOMAIN with key in KEYFILE. Update Hurricane Electric Dynamic DNS for domains in the configuration file
Requires curl to be installed in \$PATH. with associated keys. Requires curl to be installed in \$PATH.
Options: Options:
-c, --config FILE get configuration from FILE instead of $config -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 -u, --url URL update dns at URL instead of $url
-h, --help display this help -h, --help display this help
@ -26,11 +25,6 @@ show_help() {
printf "%s" "$help_text" printf "%s" "$help_text"
} }
args=
ipv4=
ipv6=
config=/etc/he-ddnsrc
while (($#)); do while (($#)); do
case $1 in case $1 in
-c|--config) -c|--config)
@ -41,20 +35,6 @@ while (($#)); do
die $LINENO "$help_text" die $LINENO "$help_text"
fi 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) -h|--help)
show_help show_help
exit exit
@ -66,21 +46,21 @@ while (($#)); do
shift shift
done done
domain="${args[1]}" # shellcheck source=he-ddnsrc
key=$(<"${args[2]}") || die $LINENO . "$config" || die $LINENO
if [[ "$ipv4" != "true" ]] && [[ "$ipv6" != "true" ]]; then
echo "Must specify either IPv4 or IPv6"
fi
if [[ "$ipv4" == "true" ]]; then ipv4="$(curl -sSL4 https://ifconfig.co/ip)" || die $LINENO
ip="$(curl -sSL4 https://ifconfig.co/ip)" || die $LINENO for domain in "${!DOMAINS4[@]}"; do
curl -sSL4 "$url" -d "hostname=$domain" -d "password=$key" -d "myip=$ip" || die $LINENO printf "%s :: " "$domain"
key=${DOMAINS4[$domain]}
curl -sSL4 "$url" -d "hostname=$domain" -d "password=$key" -d "myip=$ipv4" || die $LINENO
echo echo
fi done
if [[ "$ipv6" == "true" ]]; then ipv6="$(curl -sSL6 https://ifconfig.co/ip)" || die $LINENO
ip="$(curl -sSL6 https://ifconfig.co/ip)" || die $LINENO for domain in "${!DOMAINS6[@]}"; do
curl -sSL6 "$url" -d "hostname=$domain" -d "password=$key" -d "myip=$ip" || die $LINENO printf "%s :: " "$domain"
key=${DOMAINS6[$domain]}
curl -sSL6 "$url" -d "hostname=$domain" -d "password=$key" -d "myip=$ipv6" || die $LINENO
echo echo
fi done

Loading…
Cancel
Save