From a1b0f800da4d8e90d46a004a008d7f78ebd737eb Mon Sep 17 00:00:00 2001 From: rasul Date: Tue, 2 Jun 2020 16:42:14 -0500 Subject: [PATCH] init --- he-ddns | 76 +++++++++++++++++++++++++++++++++++++++++++++++ he-ddns4@.service | 10 +++++++ he-ddns4@.timer | 8 +++++ he-ddns6@.service | 10 +++++++ he-ddns6@.timer | 8 +++++ 5 files changed, 112 insertions(+) create mode 100755 he-ddns create mode 100644 he-ddns4@.service create mode 100644 he-ddns4@.timer create mode 100644 he-ddns6@.service create mode 100644 he-ddns6@.timer diff --git a/he-ddns b/he-ddns new file mode 100755 index 0000000..0f17f94 --- /dev/null +++ b/he-ddns @@ -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 diff --git a/he-ddns4@.service b/he-ddns4@.service new file mode 100644 index 0000000..8b6a787 --- /dev/null +++ b/he-ddns4@.service @@ -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 diff --git a/he-ddns4@.timer b/he-ddns4@.timer new file mode 100644 index 0000000..0c826ab --- /dev/null +++ b/he-ddns4@.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Update Hurricane Electric Dynamic DNS + +[Timer] +OnUnitActiveSec=20min + +[Install] +WantedBy=timers.target diff --git a/he-ddns6@.service b/he-ddns6@.service new file mode 100644 index 0000000..e70f184 --- /dev/null +++ b/he-ddns6@.service @@ -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 diff --git a/he-ddns6@.timer b/he-ddns6@.timer new file mode 100644 index 0000000..0c826ab --- /dev/null +++ b/he-ddns6@.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Update Hurricane Electric Dynamic DNS + +[Timer] +OnUnitActiveSec=20min + +[Install] +WantedBy=timers.target