Moved DynDNS config in separate scripts + added Gandi LiveDNS as a DynDNS provider. Requires testing & improvements

This commit is contained in:
Papa Dragon 2022-03-17 01:00:08 +01:00
parent 01d5bc3aa7
commit db6161d0cd
6 changed files with 312 additions and 145 deletions

View file

@ -29,8 +29,8 @@ You can of course run the script on a VPS or any distant server as long as the a
- apt-get install git
- mkdir -p /var/www
- cd /var/www
- git clone https://codeberg.org/streams/streams.git html (you can replace "html" with any name you like, which you'll have to do if you plan to have more than one hub/instance running on your server)
- cd html/.homeinstall
- git clone https://codeberg.org/streams/streams.git mywebsite (you can replace "mywebsite" with any name you like, which you'll have to do if you plan to have more than one hub/instance running on your server); if you plan to install a test server using "localhost" rather that a domain name, be sure to replace "mywebsite" with "html"
- cd website/.homeinstall
- cp server-config.txt.template server-config.txt
- nano server-config.txt
- Read the comments carefully

74
.homeinstall/ddns/freedns.sh Executable file
View file

@ -0,0 +1,74 @@
#!/bin/bash
#
#
#########################################################
# WHAT DOES THIS SCRIPT DO ? #
#########################################################
# This script will do two things :
# - Configure your freedns subdomain so that if points to your server's IP address
# - Create a cron job which will change you freedns IP configuration when needed
#
#########################################################
# INSTRUCTIONS #
#########################################################
#
# Get a free subdomain from freedns and use it for your dynamic ip address
#
# - Register for a Free domain at http://freedns.afraid.org/signup/
# - WATCH THIS: Make sure you choose a domain with as less subdomains as
# possible. Why? Let's encrpyt issues a limited count of certificates each
# day. Possible other users of this domain will try to issue a certificate
# at the same day.
# - Logon to FreeDNS (where you just registered)
# - Goto http://freedns.afraid.org/dynamic/
# - Right click on "Direct URL" and copy the URL and paste it somewhere.
# - You should notice a large and unique alpha-numeric key in the URL
# (after the question mark)
#
# http://freedns.afraid.org/dynamic/update.php?alpha-numeric-key
#
# Provided your url from freedns is
#
# http://freedns.afraid.org/dynamic/update.php?U1Z6aGt2R0NzMFNPNWRjbWxxZGpsd093OjE1Mzg5NDE5
#
# Then you have to provide
#
# freedns_key=U1Z6aGt2R0NzMFNPNWRjbWxxZGpsd093OjE1Mzg5NDE5
#
#
#########################################################
# THIS IS WHERE YOU ADD YOUR KEY #
#########################################################
freedns_key=
##########################################################
# DO NOT EDIT AFTER THIS #
##########################################################
function install_run_freedns {
print_info "run freedns (dynamic IP)..."
if [ -z "$freedns_key" ]
then
die "freedns was not started because 'freedns_key' is empty in ddns/freedns.sh"
exit 0
else
wget --no-check-certificate -O - http://freedns.afraid.org/dynamic/update.php?$freedns_key
fi
}
function configure_cron_freedns {
print_info "configure cron for freedns..."
# Use cron for dynamich ip update
# - at reboot
# - every 30 minutes
if [ -z "`grep $freedns_key /etc/crontab`" ]
then
echo "@reboot root http://freedns.afraid.org/dynamic/update.php?$freedns_key > /dev/null 2>&1" >> /etc/crontab
echo "*/30 * * * * root wget --no-check-certificate -O - http://freedns.afraid.org/dynamic/update.php?$freedns_key > /dev/null 2>&1" >> /etc/crontab
else
print_info "cron for freedns was configured already"
fi
}

131
.homeinstall/ddns/gandi.sh Executable file
View file

@ -0,0 +1,131 @@
#!/bin/bash
#
#
#########################################################
# WHAT DOES THIS SCRIPT DO ? #
#########################################################
#
# This script will do two things :
# - Configure your domain (or subdomain) Gandi.net DNS records so that if points to your server's IP address
# - Create a cron job which will change you Gandi.net DNS records configuration when needed
#
#########################################################
# INSTRUCTIONS #
#########################################################
#
# 1. Register a domain at gandi.net, pricing will depend on the TLD
# (some domains can cost a few EUR/USD/AUD a year others can cost thousands)
#
# 2. Make sure that your domain is configured with Gandi's LiveDNS nameservers
# (it's enabled by default and an option easy to configure)
#
# 3. Get your API key
# * Go to https://account.gandi.net/en/users/_USERNAME_/security
# (replace _USERNAME_ with your Gandi account username)
# * Click on the "(Re)generate the API key" link
# * Copy the API key which will be as pretty as N8Azky2QxZbQhuP6EQXmD58S
# (IMPORTANT : YOU WON'T BE ABLE TO RETRIEVE IT LATER, ONLY GENERATE A NEW ONE)
# * Add you API key in this script
#
# for example: gandi_api_key=N8Azky2QxZbQhuP6EQXmD58S
#
# 4. Set Gandi as your DDNS provider in server-config.txt (.homeinstall folder)
#
# like this: dns_provider=gandi
#
# That way the ddns/gandi.sh (which you're editing) will be run during install
#
# 5. Run server-setup.sh in the .homeinstall folder
#
#########################################################
# THIS IS WHERE YOU ADD YOUR API KEY #
#########################################################
gandi_api_key=
##########################################################
# SECOND LEVEL DOMAIN NAME (SLD) #
##########################################################
#
# As some people may want to buy a domain name with a SLD
# (for instance ending with *.net.au or *.co.uk) we need to
# make sure that it is recognised as such.
#
# Below is a list of some of the most common sld
sld=".com.au,.net.au,.org.au,.com.br,.net.br,.co.jp,.co.uk,.org.uk,.co.za,.eu.com"
#
# If your use a SLD that's not on the list just put it below
#
# for example: sld=.emp.br
# (uncomment the line below if needed)
# sld=
#
##########################################################
# DO NOT EDIT AFTER THIS #
##########################################################
function fqdn_slice {
# We find the domain name which we'll be needing later in the script
domain_name=$(echo $le_domain | awk -F. 'END {print $(NF-1)"."$NF}')
if [ ! -z $(echo $sld | grep .$domain_name) ]
then
domain_name=$(echo $le_domain | awk -F. 'END {print $(NF-2)"."$(NF-1)"."$NF}')
fi
# The subdomain will also be useful
subdomain=${le_domain//\.$domain_name/}
if [ $le_domain == $domain_name ]
then
subdomain="@"
fi
}
function install_run_gandi {
print_info "install and start Gandi LiveDNS (dynamic IP)..."
if [ -z "$gandi_api_key" ]
then
die "Gandi LiveDNS was not started because 'gandi_api_key' is empty in ddns/gandi.sh"
else
# We clone the git repository (if not already present)
# Repository still exists as of March 2022...
if [ ! -d /opt/gandi-automatic-dns ]
then
git clone https://github.com/brianreumere/gandi-automatic-dns.git /opt/gandi-automatic-dns
fi
fi
print_info "First run of Gandi LiveDNS ddns script..."
if [ -z $ip4 ]
then
die "IP address could not be retrieved. Check your internet connection"
else
echo $ip4 | /opt/gandi-automatic-dns/gad -5 -s -a $gandi_api_key -d $domain_name -r "$subdomain"
if [ $ip4 != $ip6 ]
then
echo $ip6 | /opt/gandi-automatic-dns/gad -5 -6 -s -a $gandi_api_key -d $domain_name -r "$subdomain"
fi
fi
}
function configure_cron_gandi {
print_info "configure cron for Gandi LiveDNS..."
# Use cron for dynamich ip update
# - at reboot
# - every 5 minutes
if [ -z "'grep $domain_name.*$subdomain /etc/crontab'" ]
then
echo "@reboot root curl ip4.me/ip/ | /bin/bash /opt/gandi-automatic-dns/gad -5 -s -a $gandi_api_key -d $domain_name -r \"$subdomain\" > /dev/null 2>&1" >> /etc/crontab
echo "*/5 * * * * root curl ip4.me/ip/ | /bin/bash /opt/gandi-automatic-dns/gad -5 -s -a $gandi_api_key -d $domain_name -r \"$subdomain\" > /dev/null 2>&1" >> /etc/crontab
if [ $ip4 != $ip6 ]
then
echo "@reboot root curl ip6.me/ip/ | /bin/bash /opt/gandi-automatic-dns/gad -5 -6 -s -a $gandi_api_key -d $domain_name -r \"$subdomain\" > /dev/null 2>&1" >> /etc/crontab
echo "*/5 * * * * root curl ip6.me/ip/ | /bin/bash /opt/gandi-automatic-dns/gad -5 -6 -s -a $gandi_api_key -d $domain_name -r \"$subdomain\" > /dev/null 2>&1" >> /etc/crontab
fi
else
print_info "cron for Gandi LiveDNS was configured already"
fi
}
ip4=$(curl ip4.me/ip/)
ip6=$(curl ip6.me/ip/)
fqdn_slice

77
.homeinstall/ddns/selfhost.sh Executable file
View file

@ -0,0 +1,77 @@
#!/bin/bash
#
#
#########################################################
# WHAT DOES THIS SCRIPT DO ? #
#########################################################
# This script will do two things :
# - Configure your selfHOST.de domain so that it points to your server's IP address
# - Create a cron job which will change you selfHOST.de IP configuration when needed
#
#########################################################
# INSTRUCTIONS #
#########################################################
#
# 1. Register a domain at selfhost.de
# - choose offer "DOMAIN dynamisch" 1,50€/mon at 04/2019
# 2. Get your configuration for dynamic IP update
# - Log in at selfhost.de
# - go to "DynDNS Accounte"
# - klick "Details" of your (freshly) registered domain
# - You will find the configuration there
# - Benutzername (user name) > use this for "selfhost_user="
# - Passwort (password) > use this for "selfhost_pass="
#
#########################################################
# THIS IS WHERE YOU ADD YOUR CREDENTIALS #
#########################################################
selfhost_user=
selfhost_pass=
##########################################################
# DO NOT EDIT AFTER THIS #
##########################################################
function install_run_selfhost {
print_info "install and start selfhost (dynamic IP)..."
if [ -z "$selfhost_user" ]
then
die "selfHOST was not started because 'selfhost_user' is empty in ddns/selfhost.sh"
elif [ -z "$selfhost_pass" ]
then
die "selfHOST was not started because 'selfhost_pass' is empty in ddns/selfhots.sh"
else
if [ ! -d $selfhostdir ]
then
mkdir $selfhostdir
fi
# the old way
# https://carol.selfhost.de/update?username=123456&password=supersafe
#
# the prefered way
wget --output-document=$selfhostdir/$selfhostscript http://jonaspasche.de/selfhost-updater
echo "router" > $selfhostdir/device
echo "$selfhost_user" > $selfhostdir/user
echo "$selfhost_pass" > $selfhostdir/pass
bash $selfhostdir/$selfhostscript update
fi
}
function configure_cron_selfhost {
print_info "configure cron for selfhost..."
# Use cron for dynamich ip update
# - at reboot
# - every 5 minutes
if [ -z "`grep $selfhostscript /etc/crontab`" ]
then
echo "@reboot root bash $selfhostdir/$selfhostscript update > /dev/null 2>&1" >> /etc/crontab
echo "*/5 * * * * root /bin/bash $selfhostdir/$selfhostscript update > /dev/null 2>&1" >> /etc/crontab
else
print_info "cron for selfhost was configured already"
fi
}
selfhostdir=/etc/selfhost
selfhostscript=selfhost-updater.sh

View file

@ -42,53 +42,21 @@ webserver=apache
###############################################
### OPTIONAL - selfHOST - dynamic IP address ##
### OPTIONAL - DDNS CONFIGURATION ###
#
# 1. Register a domain at selfhost.de
# - choose offer "DOMAIN dynamisch" 1,50€/mon at 04/2019
# 2. Get your configuration for dynamic IP update
# - Log in at selfhost.de
# - go to "DynDNS Accounte"
# - klick "Details" of your (freshly) registered domain
# - You will find the configuration there
# - Benutzername (user name) > use this for "selfhost_user="
# - Passwort (pass word) > use this for "selfhost_pass="
# A set of scripts is available in the "ddns" folder.
# Each one is intended for a specific provider (FreeDNS, Gandi LiveDNS, selfHOST.de)
# You can set ddns_provider to match one of them.
#
# "freedns" will run freedns.sh if you choose FreeDNS (https://freedns.afraid.org)
# "gandi" will run gandi.sh if you choose Gandi LiveDNS (https://gandi.net)
# "selfhost" will run selfhost.sh if you choose selfHOST.de (https://selfost.de)
#
selfhost_user=
selfhost_pass=
###############################################
### OPTIONAL - FreeDNS - dynamic IP address ###
# Example : ddns_provider=gandi
#
# Please give the alpha-numeric-key of freedns
ddns_provider=
#
# Get a free subdomain from freedns and use it for your dynamic ip address
# Documentation under http://www.techjawab.com/2013/06/setup-dynamic-dns-dyndns-for-free-on.html
#
# - Register for a Free domain at http://freedns.afraid.org/signup/
# - WATCH THIS: Make sure you choose a domain with as less subdomains as
# possible. Why? Let's encrpyt issues a limited count of certificates each
# day. Possible other users of this domain will try to issue a certificate
# at the same day.
# - Logon to FreeDNS (where you just registered)
# - Goto http://freedns.afraid.org/dynamic/
# - Right click on "Direct Link" and copy the URL and paste it somewhere.
# - You should notice a large and unique alpha-numeric key in the URL
#
# http://freedns.afraid.org/dynamic/update.php?alpha-numeric-key
#
# Provided your url from freedns is
#
# http://freedns.afraid.org/dynamic/update.php?U1Z6aGt2R0NzMFNPNWRjbWxxZGpsd093OjE1Mzg5NDE5
#
# Then you have to provide
#
# freedns_key=U1Z6aGt2R0NzMFNPNWRjbWxxZGpsd093OjE1Mzg5NDE5
#
#
freedns_key=
# Feel free to add scripts for other providers if you feel you can do that!
###############################################
### OPTIONAL - Backup to external device ######
@ -100,7 +68,7 @@ freedns_key=
# - ext4
#
# You should test to mount the device before you run the script
# (hubzilla-setup.sh).
# (server-setup.sh).
# How to find your (pluged-in) devices?
#
# fdisk -l
@ -170,9 +138,3 @@ website_db_pass=$db_pass
# Example: mysqlpass="aber hallo has blanks in it"
#
mysqlpass=$db_pass
# Password for package phpmyadmin
# Example: phpmyadminpass=aberhallo
# Example: phpmyadminpass="aber hallo has blanks in it"
phpmyadminpass=$db_pass

View file

@ -90,12 +90,9 @@ function check_sanity {
then
die "Debian is supported only"
fi
if ! grep -q 'Linux 11' /etc/issue
if [ -z "$(grep 'Linux 10\|Linux 11' /etc/issue)" ]
then
if ! grep -q 'Linux 10' /etc/issue
then
die "Debian 11 (bullseye) or Debian 10 (buster) are supported only"
fi
die "Debian 11 (bullseye) or Debian 10 (buster) are supported only"
fi
}
@ -299,14 +296,14 @@ function install_php {
print_info "installing php..."
if [ $webserver = "nginx" ]
then
nocheck_install "php-fpm php php-pear php-curl php-gd php-mbstring php-xml php-zip"
nocheck_install "php-fpm php php-mysql php-pear php-curl php-gd php-mbstring php-xml php-zip"
php_version
sed -i "s/^upload_max_filesize =.*/upload_max_filesize = 100M/g" /etc/php/$phpversion/fpm/php.ini
sed -i "s/^post_max_size =.*/post_max_size = 100M/g" /etc/php/$phpversion/fpm/php.ini
systemctl reload php${phpversion}-fpm
elif [ $webserver = "apache" ]
then
nocheck_install "libapache2-mod-php php php-pear php-curl php-gd php-mbstring php-xml php-zip"
nocheck_install "libapache2-mod-php php php-mysql php-pear php-curl php-gd php-mbstring php-xml php-zip"
php_version
sed -i "s/^upload_max_filesize =.*/upload_max_filesize = 100M/g" /etc/php/$phpversion/apache2/php.ini
sed -i "s/^post_max_size =.*/post_max_size = 100M/g" /etc/php/$phpversion/apache2/php.ini
@ -421,50 +418,6 @@ function create_website_db {
fi
}
function run_freedns {
print_info "run freedns (dynamic IP)..."
if [ -z "$freedns_key" ]
then
print_info "freedns was not started because 'freedns_key' is empty in $configfile"
else
if [ -n "$selfhost_user" ]
then
die "You can not use freeDNS AND selfHOST for dynamic IP updates ('freedns_key' AND 'selfhost_user' set in $configfile)"
fi
wget --no-check-certificate -O - http://freedns.afraid.org/dynamic/update.php?$freedns_key
fi
}
function install_run_selfhost {
print_info "install and start selfhost (dynamic IP)..."
if [ -z "$selfhost_user" ]
then
print_info "selfHOST was not started because 'selfhost_user' is empty in $configfile"
else
if [ -n "$freedns_key" ]
then
die "You can not use freeDNS AND selfHOST for dynamic IP updates ('freedns_key' AND 'selfhost_user' set in $configfile)"
fi
if [ -z "$selfhost_pass" ]
then
die "selfHOST was not started because 'selfhost_pass' is empty in $configfile"
fi
if [ ! -d $selfhostdir ]
then
mkdir $selfhostdir
fi
# the old way
# https://carol.selfhost.de/update?username=123456&password=supersafe
#
# the prefered way
wget --output-document=$selfhostdir/$selfhostscript http://jonaspasche.de/selfhost-updater
echo "router" > $selfhostdir/device
echo "$selfhost_user" > $selfhostdir/user
echo "$selfhost_pass" > $selfhostdir/pass
bash $selfhostdir/$selfhostscript update
fi
}
function ping_domain {
print_info "ping domain $domain..."
# Is the domain resolved? Try to ping 6 times à 10 seconds
@ -487,44 +440,6 @@ function ping_domain {
sleep 5
}
function configure_cron_freedns {
print_info "configure cron for freedns..."
if [ -z "$freedns_key" ]
then
print_info "freedns is not configured because freedns_key is empty in $configfile"
else
# Use cron for dynamich ip update
# - at reboot
# - every 30 minutes
if [ -z "`grep 'freedns.afraid.org' /etc/crontab`" ]
then
echo "@reboot root http://freedns.afraid.org/dynamic/update.php?$freedns_key > /dev/null 2>&1" >> /etc/crontab
echo "*/30 * * * * root wget --no-check-certificate -O - http://freedns.afraid.org/dynamic/update.php?$freedns_key > /dev/null 2>&1" >> /etc/crontab
else
print_info "cron for freedns was configured already"
fi
fi
}
function configure_cron_selfhost {
print_info "configure cron for selfhost..."
if [ -z "$selfhost_user" ]
then
print_info "selfhost is not configured because selfhost_key is empty in $configfile"
else
# Use cron for dynamich ip update
# - at reboot
# - every 5 minutes
if [ -z "`grep 'selfhost-updater.sh' /etc/crontab`" ]
then
echo "@reboot root bash /etc/selfhost/selfhost-updater.sh update > /dev/null 2>&1" >> /etc/crontab
echo "*/5 * * * * root /bin/bash /etc/selfhost/selfhost-updater.sh update > /dev/null 2>&1" >> /etc/crontab
else
print_info "cron for selfhost was configured already"
fi
fi
}
function install_letsencrypt {
print_info "installing let's encrypt ..."
# check if user gave domain
@ -798,7 +713,10 @@ install_imagemagick
install_php
if [ $webserver = "nginx" ]
then
add_nginx_conf
if [ "$install_path" != "/var/www/html" ]
then
add_nginx_conf
fi
elif [ $webserver = "apache" ]
then
if [ "$install_path" != "/var/www/html" ]
@ -812,11 +730,16 @@ install_adminer
create_website_db
if [ "$le_domain" != "localhost" ]
then
run_freedns
install_run_selfhost
if [ ! -z $ddns_provider ]
source ddns/$ddns_provider.sh
then
install_run_$ddns_provider
fi
ping_domain
configure_cron_freedns
configure_cron_selfhost
if [ ! -z $ddns_provider ]
then
configure_cron_$ddns_provider
fi
install_letsencrypt
check_https
else