summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorNixUnderflow2020-07-15 05:17:05 +0300
committerNixUnderflow2020-07-15 05:30:33 +0300
commit19afbb99b39209950170080c2a4f8b4ba0cf515c (patch)
tree232e12d3b10699020fb17210fdac912ebff8c4ef
parent882e4ca400cc1e6143cc1ae857d7e0ad91ced80b (diff)
downloadaur-19afbb99b39209950170080c2a4f8b4ba0cf515c.tar.gz
Upgrade: duckdns-ipv6 1.1-1
* Big rewrite * Better support for DuckDNS' automatic address detection
-rw-r--r--.SRCINFO13
-rw-r--r--.gitignore10
-rw-r--r--PKGBUILD38
-rw-r--r--duckdns-ipv6.install3
-rw-r--r--duckdns.conf55
-rw-r--r--duckdns.install29
-rw-r--r--duckdns.service2
-rwxr-xr-xduckdns.sh124
8 files changed, 172 insertions, 102 deletions
diff --git a/.SRCINFO b/.SRCINFO
index da39730043b2..490b60114ccb 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,12 +1,15 @@
pkgbase = duckdns-ipv6
pkgdesc = Automatically update DuckDNS domains, with IPv6 support
- pkgver = 1.0.1
+ pkgver = 1.1
pkgrel = 1
url = https://duckdns.org
- install = duckdns-ipv6.install
+ install = duckdns.install
arch = any
license = GPL3
+ depends = bash
+ depends = curl
depends = jq
+ depends = util-linux
provides = duckdns
conflicts = duckdns
backup = etc/duckdns.d/default
@@ -14,9 +17,9 @@ pkgbase = duckdns-ipv6
source = duckdns.sh
source = duckdns.service
source = duckdns.timer
- sha512sums = e781a69a01a7b590a5435f123d118ef64a111b57440a72e3671f560b4f2afae72f9a28c1766b032c7586fa95ac8b3dc7ea68b861d68571fcd6b3cb09185b7f68
- sha512sums = 33bdf3312e8d0f8b3d34fa9c8cf5efd598daaaaf85f5a93c263ffe934a519ba437ca66d60d28ca303f206a162416a55f54f049e53aca2d51ee9e0f5583cea9a6
- sha512sums = 33aa22ec51e44fa2d9c58e564cee6b7a280850aabb6fe24bf2a429a87d07a8a163d1e6f76505af0be9c5630133349a66613ceece8f1568fbd847c09b7328392d
+ sha512sums = 85424f976426286b4f91b997db0163108f84527663024c05c70f895dcb85a3aa507849e3c3701985957254d88c98b6e9af54dbbc318db677141cf6bb05a2a51c
+ sha512sums = 03469909987fb15bea36208317edac83e675d9452e02222b7cab00dd4f67e7c4b0fdf1027c5d1dbae430de7453bf1d8f033f64942011266b14efc68085e5b652
+ sha512sums = 10783060db994bee4faf03920374840bc57b105304a7aa9b1ebc9161f9a765b985c2ef83906fb6f2c0dbb7b118cde95820e786fd39f78b443af5927e9bb71391
sha512sums = 55fa343bd4be6157b9b909721559a8fe163ad0968d2dcfcb5d9bca2fe268d70b1369dde225adc8d3a31815356d43afc76a43d8cf39d92209a1965d0e1e40f618
pkgname = duckdns-ipv6
diff --git a/.gitignore b/.gitignore
index 3185d8cbe82d..aacdb937722d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,9 +1,9 @@
*
+!.SRCINFO
+!.gitignore
+!PKGBUILD
!duckdns.conf
-!duckdns.sh
+!duckdns.install
!duckdns.service
+!duckdns.sh
!duckdns.timer
-!duckdns-ipv6.install
-!PKGBUILD
-!.gitignore
-!.SRCINFO
diff --git a/PKGBUILD b/PKGBUILD
index 32e1758ea726..0aaa3b7c7521 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,29 +1,31 @@
# Maintainer: Nitroretro <nitroretro@protonmail.com>
+# Maintainer: NixUnderflow <nixunderflow@protonmail.com>
pkgname=duckdns-ipv6
-pkgver=1.0.1
+_pkgname=duckdns
+pkgver=1.1
pkgrel=1
pkgdesc="Automatically update DuckDNS domains, with IPv6 support"
arch=("any")
-url="https://duckdns.org"
+url="https://${_pkgname}.org"
license=("GPL3")
-depends=("jq")
-provides=("duckdns")
-conflicts=("duckdns")
-backup=("etc/duckdns.d/default")
-install="${pkgname}.install"
-source=("duckdns.conf"
- "duckdns.sh"
- "duckdns.service"
- "duckdns.timer")
-sha512sums=('e781a69a01a7b590a5435f123d118ef64a111b57440a72e3671f560b4f2afae72f9a28c1766b032c7586fa95ac8b3dc7ea68b861d68571fcd6b3cb09185b7f68'
- '33bdf3312e8d0f8b3d34fa9c8cf5efd598daaaaf85f5a93c263ffe934a519ba437ca66d60d28ca303f206a162416a55f54f049e53aca2d51ee9e0f5583cea9a6'
- '33aa22ec51e44fa2d9c58e564cee6b7a280850aabb6fe24bf2a429a87d07a8a163d1e6f76505af0be9c5630133349a66613ceece8f1568fbd847c09b7328392d'
+depends=("bash" "curl" "jq" "util-linux")
+provides=("${_pkgname}")
+conflicts=("${_pkgname}")
+backup=("etc/${_pkgname}.d/default")
+install="${_pkgname}.install"
+source=("${_pkgname}.conf"
+ "${_pkgname}.sh"
+ "${_pkgname}.service"
+ "${_pkgname}.timer")
+sha512sums=('85424f976426286b4f91b997db0163108f84527663024c05c70f895dcb85a3aa507849e3c3701985957254d88c98b6e9af54dbbc318db677141cf6bb05a2a51c'
+ '03469909987fb15bea36208317edac83e675d9452e02222b7cab00dd4f67e7c4b0fdf1027c5d1dbae430de7453bf1d8f033f64942011266b14efc68085e5b652'
+ '10783060db994bee4faf03920374840bc57b105304a7aa9b1ebc9161f9a765b985c2ef83906fb6f2c0dbb7b118cde95820e786fd39f78b443af5927e9bb71391'
'55fa343bd4be6157b9b909721559a8fe163ad0968d2dcfcb5d9bca2fe268d70b1369dde225adc8d3a31815356d43afc76a43d8cf39d92209a1965d0e1e40f618')
package() {
- install -Dm600 duckdns.conf "${pkgdir}/etc/duckdns.d/default"
- install -Dm755 duckdns.sh "${pkgdir}/usr/bin/duckdns"
- install -Dm644 duckdns.service "${pkgdir}/usr/lib/systemd/system/duckdns.service"
- install -Dm644 duckdns.timer "${pkgdir}/usr/lib/systemd/system/duckdns.timer"
+ install -Dm600 "${_pkgname}.conf" "${pkgdir}/etc/${_pkgname}.d/default"
+ install -Dm755 "${_pkgname}.sh" "${pkgdir}/usr/bin/${_pkgname}"
+ install -Dm644 "${_pkgname}.service" "${pkgdir}/usr/lib/systemd/system/${_pkgname}.service"
+ install -Dm644 "${_pkgname}.timer" "${pkgdir}/usr/lib/systemd/system/${_pkgname}.timer"
}
diff --git a/duckdns-ipv6.install b/duckdns-ipv6.install
deleted file mode 100644
index 396d8964ab95..000000000000
--- a/duckdns-ipv6.install
+++ /dev/null
@@ -1,3 +0,0 @@
-post_install() {
- echo "Don't forget to edit /etc/duckdns.d/default in order to provide your domain names, token and IP address providers!"
-}
diff --git a/duckdns.conf b/duckdns.conf
index 615b5f6e0bdb..8dd2220a0cb6 100644
--- a/duckdns.conf
+++ b/duckdns.conf
@@ -1,42 +1,49 @@
-####################################################################################
-# This is the configuration file for the duckdns script. #
-# This file is interpreted as POSIX shell. Using POSIX shell syntax is sufficient. #
-####################################################################################
-# You can have multiple configuration files. Simply create another file in /etc/duckdns.d and the script will use it.
-
-## ENABLE
-# You can run the script every 10 minutes by enabling and starting duckdns.timer:
+########################################################################
+# This is the configuration file for the duckdns script. #
+# This file is interpreted as POSIX shell. Using POSIX shell syntax is #
+# sufficient. #
+########################################################################
+
+# You can have multiple configuration files. Simply create another file in
+# /etc/duckdns.d and the script will use it.
+
+# -- Enable the script -- #
+# You can run the script every 10 minutes by enabling and starting
+# duckdns.timer:
#systemctl enable duckdns.timer
#systemctl start duckdns.timer
# You can run the script once on boot-up by enabling duckdns.service:
#systemctl enable duckdns.service
-## CONFIGURATION
-# One domain or comma-separated list of domains. This is only the subdomain part of it, without .duckdns.org.
-# For updating foo.duckdns.org: DOMAINS="foo"
-# For updating both foo.duckdns.org and bar.duckdns.org: DOMAINS="foo,bar"
+# -- Configuration -- #
+# One domain or comma-separated list of domains. This is only the subdomain
+# part of it, without .duckdns.org.
+# For example:
+# * update foo.duckdns.org: DOMAINS="foo"
+# * update both foo.duckdns.org and bar.duckdns.org: DOMAINS="foo,bar"
#DOMAINS="foo"
# Your DuckDNS token.
#TOKEN="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
-### IPv4
-# Use an URL for getting the IPv4 address.
-IPV4_URL="https://api.ipify.org"
+# -- IPv4 -- #
+# Options are sorted by their priority, from highest to lowest.
-# Hardcode the IPv4 address. This option takes precedence over IPV4_URL.
+# Hardcode the IPv4 address.
#IPV4_ADDRESS="127.0.0.1"
-# If neither of the two options are set then DuckDNS will automatically detect the IPv4 address, unless any of the IPv6 options are set.
-# From https://www.duckdns.org/spec.jsp:
-# > ipv6 - OPTIONAL - a valid IPv6 address, if you specify this then the autodetection for ip is not used
+# Use an URL for getting the IPv4 address.
+#IPV4_URL="https://api.ipify.org"
-### IPv6
-# Use an URL for getting the IPv6 address.
-IPV6_URL="https://api6.ipify.org"
+# Use DuckDNS' automatic IPv4 address detection (0 to disable).
+IPV4_AUTO=1
-# Hardcode the IPv6 address. This option takes precedence over IPV6_URL.
+# -- IPv6 -- #
+# Options are sorted by their priority, from highest to lowest.
+
+# Hardcode the IPv6 address.
#IPV6_ADDRESS="::1"
-# If neither of the two options are set then the IPv6 address won't be updated.
+# Use an URL for getting the IPv6 address.
+IPV6_URL="https://api6.ipify.org"
diff --git a/duckdns.install b/duckdns.install
new file mode 100644
index 000000000000..d8a9afebd201
--- /dev/null
+++ b/duckdns.install
@@ -0,0 +1,29 @@
+_pkgname="duckdns"
+
+post_install() {
+ if ! getent group "${_pkgname}" &>/dev/null; then
+ echo ":: Adding ${_pkgname} system group..."
+ groupadd --system "${_pkgname}" 1>/dev/null
+ fi
+
+ if ! getent passwd "${_pkgname}" &>/dev/null; then
+ echo ":: Adding ${_pkgname} system user..."
+ useradd \
+ --system \
+ --gid "${_pkgname}" \
+ --home-dir "/etc/${_pkgname}.d" \
+ "${_pkgname}" 1>/dev/null
+ fi
+
+ chown -R "${_pkgname}:${_pkgname}" "/etc/${_pkgname}.d"
+ echo "Don't forget to edit /etc/${_pkgname}.d/default in order to provide your domain names, token and IP address providers!"
+}
+
+post_upgrade() {
+ chown -R "${_pkgname}:${_pkgname}" "/etc/${_pkgname}.d"
+}
+
+post_remove() {
+ [ -d "/etc/${_pkgname}.d" ] && echo ":: Configuration files in /etc/${_pkgname}.d were preserved."
+ echo ":: The ${_pkgname} user and group were preserved."
+}
diff --git a/duckdns.service b/duckdns.service
index 1d62f822de52..4697ecb57ede 100644
--- a/duckdns.service
+++ b/duckdns.service
@@ -6,6 +6,8 @@ After=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/duckdns
+User=duckdns
+Group=duckdns
[Install]
WantedBy=multi-user.target
diff --git a/duckdns.sh b/duckdns.sh
index 59c0049adeea..98f9291338f9 100755
--- a/duckdns.sh
+++ b/duckdns.sh
@@ -1,60 +1,90 @@
#!/bin/sh -e
-failed=0
+# This program is not affiliated with DuckDNS.
-log() {
- [ "$1" = "err" ] && failed=1
- [ -n "$config_name" ] && message="$config_name: $2" || message="$2"
- logger -t DuckDNS -p "daemon.$1" "$message"
+# duckdns.sh - automatically update DuckDNS domains (with IPv6 support)
+# Copyright (C) 2020 Nitroretro
+# Copyright (C) 2020 NixUnderflow
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Arguments: PATH
+basename() {
+ name=${1%${1##*[!/]}}
+ name=${name##*/}
+ printf "%s\n" "${name:-"/"}"
}
+# Arguments: TEXT
url_encode() {
- jq --null-input --raw-output --arg input "$1" '$input | @uri'
+ jq --null-input --raw-output --arg value "$1" '$value | @uri'
}
-log info "Updating the DuckDNS domains..."
-for config_file in /etc/duckdns.d/*; do
- unset -v DOMAINS TOKEN IPV4_URL IPV4_ADDRESS IPV6_URL IPV6_ADDRESS
- config_name=$(basename "$config_file")
- . "$config_file"
+# Arguments:
+# * MESSAGE
+# * PRIORITY = "info": see logger(1) -> FACILITIES AND LEVELS
+log() {
+ [ -n "$configuration_name" ] && message="${configuration_name}: $1" || message="$1"
+ [ "$2" = "err" ] && exit_code=1
+ logger --tag DuckDNS --priority "daemon.${2:-"info"}" "$message"
+}
- [ -z "$DOMAINS" ] && log err "DOMAINS is not set." && continue
- [ -z "$TOKEN" ] && log err "TOKEN is not set." && continue
+# Arguments: CURL_FAMILY, ADDRESS, URL, AUTO
+determine_address() {
+ [ -n "$2" ] && echo "$2" && return
+ if [ -n "$3" ]; then
+ address="$(curl --silent "$1" "$3")" && echo "$address" && return
+ log "$1: Failed to get address via URL." err
+ fi
+ [ "$4" = 1 ] && echo "" && return
+}
- query_url="https://www.duckdns.org/update?domains=$(url_encode "$DOMAINS")&token=$(url_encode "$TOKEN")"
+update() {
+ [ "$(curl --silent "$1")" = "KO" ] && log "Failed to update." err
+ sent_update=1
+}
- if [ -n "$IPV6_ADDRESS" ]; then
- ipv6="$IPV6_ADDRESS"
- elif [ -n "$IPV6_URL" ]; then
- if ! ipv6=$(curl -s "$IPV6_URL"); then
- log err "Failed to get the IPV6 address using IPV6_URL. Unable to update the IPv6 address."
- unset -v ipv6
- fi
- fi
- [ -n "$ipv6" ] && query_url="${query_url}&ipv6=$(url_encode "$ipv6")"
-
- if [ -n "$IPV4_ADDRESS" ]; then
- ipv4="$IPV4_ADDRESS"
- elif [ -n "$IPV4_URL" ]; then
- if ! ipv4=$(curl -s "$IPV4_URL"); then
- if [ -z "$ipv6" ]; then
- log warn "Failed to get the IPv4 address using IPV4_URL. Falling back to DuckDNS' automatic address detection."
- else
- # DuckDNS doesn't try to automatically detect the IPv4 address if you also specify an IPv6 address.
- log warn "Failed to get the IPv4 address using IPV4_URL. Unable to update the IPv4 address."
- fi
- unset -v ipv4
- fi
- fi
- [ -n "$ipv4" ] && query_url="${query_url}&ip=$(url_encode "$ipv4")"
+main() {
+ exit_code=0
- if [ "$(curl -s "$query_url")" = "OK" ]; then
- log info "Successfully updated the DuckDNS domains."
- else
- log err "Failed to update the DuckDNS domains."
- fi
-done
-unset -v config_name
-log info "Finished updating the DuckDNS domains."
+ for configuration_file in /etc/duckdns.d/*; do
+ unset -v DOMAINS TOKEN IPV4_ADDRESS IPV4_URL IPV4_AUTO IPV6_ADDRESS IPV6_URL
+ sent_update=0
+ # shellcheck source=duckdns.conf
+ . "$configuration_file"
+ configuration_name="$(basename "$configuration_file")"
+
+ [ -z "$DOMAINS" ] && log "DOMAINS is required." err && continue
+ [ -z "$TOKEN" ] && log "TOKEN is required." err && continue
+
+ log "Getting addresses..."
+ ipv4="$(url_encode "$(determine_address --ipv4 "$IPV4_ADDRESS" "$IPV4_URL" "$IPV4_AUTO")")"
+ ipv6="$(url_encode "$(determine_address --ipv6 "$IPV6_ADDRESS" "$IPV6_URL")")"
+
+ log "Updating addresses..."
+ initial_update_url="https://www.duckdns.org/update?domains=$(url_encode "$DOMAINS")&token=$(url_encode "$TOKEN")"
+ update_url="$initial_update_url"
+ [ -z "$ipv4" ] && [ "$IPV4_AUTO" = 1 ] && update "${update_url}&ip=${ipv4}"
+ [ -n "$ipv4" ] && update_url="${update_url}&ip=${ipv4}"
+ [ -n "$ipv6" ] && update_url="${update_url}&ipv6=${ipv6}"
+ [ "$update_url" != "$initial_update_url" ] && update "$update_url"
+ [ "$sent_update" = 0 ] && log "There is no IPv4 or IPv6 address to update." err
+ done
+ unset -v configuration_name
+
+ log "Done updating addresses."
+ exit "$exit_code"
+}
-exit "$failed"
+main "$@"