Skip to content

Commit 4ddec3c

Browse files
Pantnacho
authored andcommitted
Add FreeDNS client installation for Raspbian
1 parent 0337388 commit 4ddec3c

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

etc/nextcloudpi-config.d/freeDNS.sh

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/bash
2+
3+
# FreeDNS updater client installation on Raspbian
4+
#
5+
# Copyleft 2017 by Panteleimon Sarantos <pantelis.fedora _a_t_ gmail _d_o_t_ com>
6+
# GPL licensed (see end of file) * Use at your own risk!
7+
#
8+
# Usage:
9+
#
10+
# ./installer.sh freedns.sh
11+
#
12+
# See installer.sh instructions for details
13+
#
14+
#
15+
#
16+
17+
ACTIVE_=yes
18+
UPDATEURL_=https://freedns.afraid.org/dynamic/update.php
19+
UPDATEHASH_=abcdefghijklmnopqrstuvwxyzABCDEFGHIJK1234567
20+
DOMAIN_=nextcloud.example.com
21+
UPDATEINTERVAL_=30
22+
DESCRIPTION="DDNS FreeDNS client (need account)"
23+
URL="${UPDATEURL_}?${UPDATEHASH_}"
24+
25+
show_info()
26+
{
27+
whiptail --yesno \
28+
--backtitle "NextCloudPi configuration" \
29+
--title --title "Instructions for FreeDNS client
30+
Set the time in seconds in UPDATEINTERVAL.
31+
>>> Long interval may lead to not updating your IP address for long time. <<<" \
32+
20 90
33+
}
34+
35+
install()
36+
{
37+
apt-get install --no-install-recommends -y dnsutils
38+
cat > /usr/local/bin/freedns.sh <<EOF
39+
#!/bin/bash
40+
echo "FreeDNS client started"
41+
echo "${URL}"
42+
registeredIP=$(nslookup ${DOMAIN_}|tail -n2|grep A|sed s/[^0-9.]//g)
43+
currentIP=$(wget -q -O - http://checkip.dyndns.org|sed s/[^0-9.]//g)
44+
[ "\$currentIP" != "\$registeredIP" ] && {
45+
wget -q -O /dev/null ${URL}
46+
}
47+
echo "Registered IP: \$registeredIP | Current IP: \$currentIP"
48+
49+
EOF
50+
51+
chmod +744 /usr/local/bin/freedns.sh
52+
53+
cat > /etc/systemd/system/freedns.service <<EOF
54+
[Unit]
55+
Description=FreeDNS client
56+
57+
[Service]g
58+
Type=simple
59+
ExecStart=/bin/bash /usr/local/bin/freedns.sh
60+
61+
[Install]
62+
WantedBy=default.target
63+
EOF
64+
}
65+
66+
configure()
67+
{
68+
69+
cat > /etc/systemd/system/freedns.timer <<EOF
70+
[Unit]
71+
Description=Timer to run FreeDNS client per interval
72+
73+
[Timer]
74+
OnBootSec=${UPDATEINTERVAL_}
75+
OnUnitActiveSec=${UPDATEINTERVAL_}
76+
Unit=freedns.service
77+
78+
[Install]
79+
WantedBy=timers.target
80+
EOF
81+
systemctl daemon-reload
82+
83+
[[ $ACTIVE_ != "yes" ]] && {
84+
systemctl stop freedns.timer
85+
systemctl disable freedns.timer
86+
systemctl daemon-reload
87+
echo "FreeDNS client is disabled"
88+
return 0
89+
}
90+
systemctl daemon-reload
91+
systemctl enable freedns.timer
92+
systemctl start freedns.timer
93+
echo "FreeDNS client is enabled"
94+
95+
cd /var/www/nextcloud
96+
sudo -u www-data php occ config:system:set trusted_domains 3 --value="$DOMAIN_"
97+
sudo -u www-data php occ config:system:set overwrite.cli.url --value=https://"$DOMAIN_"
98+
99+
100+
}
101+
102+
cleanup() { :; }
103+
# License
104+
#
105+
# This script is free software; you can redistribute it and/or modify it
106+
# under the terms of the GNU General Public License as published by
107+
# the Free Software Foundation; either version 2 of the License, or
108+
# (at your option) any later version.
109+
#
110+
# This script is distributed in the hope that it will be useful,
111+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
112+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
113+
# GNU General Public License for more details.
114+
#
115+
# You should have received a copy of the GNU General Public License
116+
# along with this script; if not, write to the
117+
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
118+
# Boston, MA 02111-1307 USA

0 commit comments

Comments
 (0)