|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Namecheap DNS updater client installation on Raspbian |
| 4 | +# |
| 5 | +# Copyleft 2020 by ndunks and Huizerd |
| 6 | +# GPL licensed (see end of file) * Use at your own risk! |
| 7 | +# |
| 8 | +# Based on: |
| 9 | +# - https://gist.github.com/ndunks/c756030c0757b667c9a478c97ca5a9b7 |
| 10 | +# - https://www.namecheap.com/support/knowledgebase/article.aspx/29/11/how-do-i-use-a-browser-to-dynamically-update-the-hosts-ip |
| 11 | +# |
| 12 | +# Further steps to be taken: |
| 13 | +# - Buying a Namecheap domain |
| 14 | +# - https://www.namecheap.com/support/knowledgebase/article.aspx/595/11/how-do-i-enable-dynamic-dns-for-a-domain/ |
| 15 | +# - https://www.namecheap.com/support/knowledgebase/article.aspx/43/11/how-do-i-set-up-a-host-for-dynamic-dns |
| 16 | + |
| 17 | + |
| 18 | +install() |
| 19 | +{ |
| 20 | + apt-get update |
| 21 | + apt-get install --no-install-recommends -y dnsutils |
| 22 | +} |
| 23 | + |
| 24 | +configure() |
| 25 | +{ |
| 26 | + local updateurl=https://dynamicdns.park-your-domain.com/update |
| 27 | + local url="${updateurl}?host=${HOST}&domain=${DOMAIN}&password=${PASSWORD}" |
| 28 | + |
| 29 | + [[ $ACTIVE != "yes" ]] && { |
| 30 | + rm -f /etc/cron.d/namecheapDNS |
| 31 | + service cron restart |
| 32 | + echo "Namecheap DNS client is disabled" |
| 33 | + return 0 |
| 34 | + } |
| 35 | + |
| 36 | + cat > /usr/local/bin/namecheapdns.sh <<EOF |
| 37 | +#!/bin/bash |
| 38 | +echo "Namecheap DNS client started" |
| 39 | +registeredIP=\$(dig +short "$FULLDOMAIN"|tail -n1) |
| 40 | +currentIP=\$(wget -q -O - http://checkip.dyndns.org|sed s/[^0-9.]//g) |
| 41 | +echo "${url}&ip=${currentIP}" |
| 42 | + [ "\$currentIP" != "\$registeredIP" ] && { |
| 43 | + wget -q -O /dev/null "${url}&ip=${currentIP}" |
| 44 | + } |
| 45 | +echo "Registered IP: \$registeredIP | Current IP: \$currentIP" |
| 46 | +EOF |
| 47 | + chmod +744 /usr/local/bin/namecheapdns.sh |
| 48 | + |
| 49 | + echo "*/${UPDATEINTERVAL} * * * * root /bin/bash /usr/local/bin/namecheapdns.sh" > /etc/cron.d/namecheapDNS |
| 50 | + chmod 644 /etc/cron.d/namecheapDNS |
| 51 | + service cron restart |
| 52 | + |
| 53 | + cd /var/www/nextcloud |
| 54 | + sudo -u www-data php occ config:system:set trusted_domains 3 --value="$FULLDOMAIN" |
| 55 | + sudo -u www-data php occ config:system:set overwrite.cli.url --value=https://"$FULLDOMAIN"/ |
| 56 | + |
| 57 | + echo "Namecheap DNS client is enabled" |
| 58 | +} |
| 59 | + |
| 60 | +# License |
| 61 | +# |
| 62 | +# This script is free software; you can redistribute it and/or modify it |
| 63 | +# under the terms of the GNU General Public License as published by |
| 64 | +# the Free Software Foundation; either version 2 of the License, or |
| 65 | +# (at your option) any later version. |
| 66 | +# |
| 67 | +# This script is distributed in the hope that it will be useful, |
| 68 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 69 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 70 | +# GNU General Public License for more details. |
| 71 | +# |
| 72 | +# You should have received a copy of the GNU General Public License |
| 73 | +# along with this script; if not, write to the |
| 74 | +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
| 75 | +# Boston, MA 02111-1307 USA |
0 commit comments