|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# DynuDNS updater client installation on Raspbian |
| 4 | +# |
| 5 | +# Copyleft 2022 by Stefano Guandalini <guandalf _a_t_ protonmail _d_o_t_ com> |
| 6 | +# GPL licensed (see end of file) * Use at your own risk! |
| 7 | +# |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +install() |
| 12 | +{ |
| 13 | + apt-get update |
| 14 | + apt-get install --no-install-recommends -y dnsutils |
| 15 | +} |
| 16 | + |
| 17 | +configure() |
| 18 | +{ |
| 19 | + local updateurl=https://api.dynu.com/nic/update |
| 20 | + local url="${updateurl}?hostname=${DOMAIN}&myipv6=${MYIPV6}&password=${PASSWORD}" |
| 21 | + |
| 22 | + [[ $ACTIVE != "yes" ]] && { |
| 23 | + rm -f /etc/cron.d/dynuDNS |
| 24 | + service cron restart |
| 25 | + echo "dynuDNS client is disabled" |
| 26 | + return 0 |
| 27 | + } |
| 28 | + |
| 29 | + cat > /usr/local/bin/dynudns.sh <<EOF |
| 30 | +#!/bin/bash |
| 31 | +echo "DynuDNS client started" |
| 32 | +echo "${url}" |
| 33 | +registeredIP=\$(dig +short "$DOMAIN"|tail -n1) |
| 34 | +currentIP=\$(wget -q -O - http://checkip.dyndns.org|sed s/[^0-9.]//g) |
| 35 | + [ "\$currentIP" != "\$registeredIP" ] && { |
| 36 | + wget -q -O /dev/null "${url}" |
| 37 | + } |
| 38 | +echo "Registered IP: \$registeredIP | Current IP: \$currentIP" |
| 39 | +EOF |
| 40 | + chmod +744 /usr/local/bin/dynudns.sh |
| 41 | + |
| 42 | + echo "*/${UPDATEINTERVAL} * * * * root /bin/bash /usr/local/bin/dynudns.sh" > /etc/cron.d/dynuDNS |
| 43 | + chmod 644 /etc/cron.d/dynuDNS |
| 44 | + service cron restart |
| 45 | + |
| 46 | + set-nc-domain "$DOMAIN" |
| 47 | + |
| 48 | + echo "DynuDNS client is enabled" |
| 49 | +} |
| 50 | + |
| 51 | +# License |
| 52 | +# |
| 53 | +# This script is free software; you can redistribute it and/or modify it |
| 54 | +# under the terms of the GNU General Public License as published by |
| 55 | +# the Free Software Foundation; either version 2 of the License, or |
| 56 | +# (at your option) any later version. |
| 57 | +# |
| 58 | +# This script is distributed in the hope that it will be useful, |
| 59 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 60 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 61 | +# GNU General Public License for more details. |
| 62 | +# |
| 63 | +# You should have received a copy of the GNU General Public License |
| 64 | +# along with this script; if not, write to the |
| 65 | +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
| 66 | +# Boston, MA 02111-1307 USA |
0 commit comments