#!/bin/bash
#
# .---.                  .              .
# |                      |              |
# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
#
#                    Freedom in the Cloud
#
# Initial reading of the configuration file, typically called freedombone.cfg
#
# License
# =======
#
# Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

function read_configuration {
	# if not installing on a Beaglebone then use sdb as the USB drive by default
	if [ ! $INSTALLING_ON_BBB ]; then
		if [[ $USB_DRIVE == /dev/sda1 ]]; then
			USB_DRIVE=/dev/sdb1
		fi
	fi

	if [[ $INSTALLING_FROM_CONFIGURATION_FILE == "yes"  ]]; then
		if [ ! -f $CONFIGURATION_FILE ]; then
			echo $"The configuration file $CONFIGURATION_FILE was not found"
			exit 8935
		fi
	fi

	if [ -f $CONFIGURATION_FILE ]; then
		read_repo_servers

		# Ensure that a copy of the config exists for upgrade purposes
		if [[ $CONFIGURATION_FILE != "/root/${PROJECT_NAME}.cfg" ]]; then
			cp $CONFIGURATION_FILE /root/${PROJECT_NAME}.cfg
		fi
		if grep -q "REFRESH_GPG_KEYS_HOURS" $CONFIGURATION_FILE; then
			REFRESH_GPG_KEYS_HOURS=$(grep "REFRESH_GPG_KEYS_HOURS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "WEBMAIL_REPO" $CONFIGURATION_FILE; then
			WEBMAIL_REPO=$(grep "WEBMAIL_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "WEBMAIL_COMMIT" $CONFIGURATION_FILE; then
			WEBMAIL_COMMIT=$(grep "WEBMAIL_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "WIFI_INTERFACE" $CONFIGURATION_FILE; then
			WIFI_INTERFACE=$(grep "WIFI_INTERFACE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "WIFI_SSID" $CONFIGURATION_FILE; then
			WIFI_SSID=$(grep "WIFI_SSID" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "WIFI_TYPE" $CONFIGURATION_FILE; then
			WIFI_TYPE=$(grep "WIFI_TYPE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "WIFI_PASSPHRASE" $CONFIGURATION_FILE; then
			WIFI_PASSPHRASE=$(grep "WIFI_PASSPHRASE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "WIFI_HOTSPOT" $CONFIGURATION_FILE; then
			WIFI_HOTSPOT=$(grep "WIFI_HOTSPOT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "WIFI_NETWORKS_FILE" $CONFIGURATION_FILE; then
			WIFI_NETWORKS_FILE=$(grep "WIFI_NETWORKS_FILE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SYNCTHING_ID" $CONFIGURATION_FILE; then
			SYNCTHING_ID=$(grep "SYNCTHING_ID" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SYNCTHING_CONFIG_PATH" $CONFIGURATION_FILE; then
			SYNCTHING_CONFIG_PATH=$(grep "SYNCTHING_CONFIG_PATH" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SYNCTHING_CONFIG_FILE" $CONFIGURATION_FILE; then
			SYNCTHING_CONFIG_FILE=$(grep "SYNCTHING_CONFIG_FILE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SYNCTHING_RELAY_SERVER" $CONFIGURATION_FILE; then
			SYNCTHING_RELAY_SERVER=$(grep "SYNCTHING_RELAY_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SYNCTHING_RELEASES" $CONFIGURATION_FILE; then
			SYNCTHING_RELEASES=$(grep "SYNCTHING_RELEASES" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SYNCTHING_PORT" $CONFIGURATION_FILE; then
			SYNCTHING_PORT=$(grep "SYNCTHING_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SYNCTHING_SHARED_DATA" $CONFIGURATION_FILE; then
			SYNCTHING_SHARED_DATA=$(grep "SYNCTHING_SHARED_DATA" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "VOIP_TURN_PORT" $CONFIGURATION_FILE; then
			VOIP_TURN_PORT=$(grep "VOIP_TURN_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "VOIP_TURN_TLS_PORT" $CONFIGURATION_FILE; then
			VOIP_TURN_TLS_PORT=$(grep "VOIP_TURN_TLS_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "VOIP_TURN_NONCE" $CONFIGURATION_FILE; then
			VOIP_TURN_NONCE=$(grep "VOIP_TURN_NONCE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "DEFAULT_SEARCH" $CONFIGURATION_FILE; then
			DEFAULT_SEARCH=$(grep "DEFAULT_SEARCH" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SEARCH_ENGINE_PASSWORD" $CONFIGURATION_FILE; then
			SEARCH_ENGINE_PASSWORD=$(grep "SEARCH_ENGINE_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "XMPP_PASSWORD" $CONFIGURATION_FILE; then
			XMPP_PASSWORD=$(grep "XMPP_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "RSS_READER_REPO" $CONFIGURATION_FILE; then
			RSS_READER_REPO=$(grep "RSS_READER_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "RSS_MOBILE_READER_REPO" $CONFIGURATION_FILE; then
			RSS_MOBILE_READER_REPO=$(grep "RSS_MOBILE_READER_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "RSS_READER_COMMIT" $CONFIGURATION_FILE; then
			RSS_READER_COMMIT=$(grep "RSS_READER_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "RSS_MOBILE_READER_COMMIT" $CONFIGURATION_FILE; then
			RSS_MOBILE_READER_COMMIT=$(grep "RSS_MOBILE_READER_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "RSS_READER_ADMIN_PASSWORD" $CONFIGURATION_FILE; then
			RSS_READER_ADMIN_PASSWORD=$(grep "RSS_READER_ADMIN_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "RSS_READER_DOMAIN_NAME" $CONFIGURATION_FILE; then
			RSS_READER_DOMAIN_NAME=$(grep "RSS_READER_DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MICROBLOG_BACKGROUND_IMAGE_URL" $CONFIGURATION_FILE; then
			MICROBLOG_BACKGROUND_IMAGE_URL=$(grep "MICROBLOG_BACKGROUND_IMAGE_URL" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MICROBLOG_WELCOME_MESSAGE" $CONFIGURATION_FILE; then
			MICROBLOG_WELCOME_MESSAGE=$(grep "MICROBLOG_WELCOME_MESSAGE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "PROJECT_WEBSITE" $CONFIGURATION_FILE; then
			PROJECT_WEBSITE=$(grep "PROJECT_WEBSITE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "PROJECT_REPO" $CONFIGURATION_FILE; then
			PROJECT_REPO=$(grep "PROJECT_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "ONION_ONLY" $CONFIGURATION_FILE; then
			ONION_ONLY=$(grep "ONION_ONLY" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "IRC_PASSWORD" $CONFIGURATION_FILE; then
			IRC_PASSWORD=$(grep "IRC_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "DEFAULT_LANGUAGE" $CONFIGURATION_FILE; then
			DEFAULT_LANGUAGE=$(grep "DEFAULT_LANGUAGE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MINIMAL_INSTALL" $CONFIGURATION_FILE; then
			MINIMAL_INSTALL=$(grep "MINIMAL_INSTALL" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "LETSENCRYPT_SERVER" $CONFIGURATION_FILE; then
			LETSENCRYPT_SERVER=$(grep "LETSENCRYPT_SERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "FULLBLOG_REPO" $CONFIGURATION_FILE; then
			FULLBLOG_REPO=$(grep "FULLBLOG_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "FULLBLOG_COMMIT" $CONFIGURATION_FILE; then
			FULLBLOG_COMMIT=$(grep "FULLBLOG_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "GOGS_COMMIT" $CONFIGURATION_FILE; then
			GOGS_COMMIT=$(grep "GOGS_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "TOXCORE_COMMIT" $CONFIGURATION_FILE; then
			TOXCORE_COMMIT=$(grep "TOXCORE_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "TOXIC_COMMIT" $CONFIGURATION_FILE; then
			TOXIC_COMMIT=$(grep "TOXIC_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "GPGIT_REPO" $CONFIGURATION_FILE; then
			GPGIT_REPO=$(grep "GPGIT_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "GPGIT_COMMIT" $CONFIGURATION_FILE; then
			GPGIT_COMMIT=$(grep "GPGIT_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "HUBZILLA_REPO" $CONFIGURATION_FILE; then
			HUBZILLA_REPO=$(grep "HUBZILLA_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "HUBZILLA_COMMIT" $CONFIGURATION_FILE; then
			HUBZILLA_COMMIT=$(grep "HUBZILLA_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "IPFS_COMMIT" $CONFIGURATION_FILE; then
			IPFS_COMMIT=$(grep "IPFS_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "ZERONET_BLOG_COMMIT" $CONFIGURATION_FILE; then
			ZERONET_BLOG_COMMIT=$(grep "ZERONET_BLOG_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "ZERONET_MAIL_COMMIT" $CONFIGURATION_FILE; then
			ZERONET_MAIL_COMMIT=$(grep "ZERONET_MAIL_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "ZERONET_FORUM_COMMIT" $CONFIGURATION_FILE; then
			ZERONET_FORUM_COMMIT=$(grep "ZERONET_FORUM_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MICROBLOG_COMMIT" $CONFIGURATION_FILE; then
			MICROBLOG_COMMIT=$(grep "MICROBLOG_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "NGINX_ENSITE_REPO" $CONFIGURATION_FILE; then
			NGINX_ENSITE_REPO=$(grep "NGINX_ENSITE_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "NGINX_ENSITE_COMMIT" $CONFIGURATION_FILE; then
			NGINX_ENSITE_COMMIT=$(grep "NGINX_ENSITE_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "CLEANUP_MAILDIR_COMMIT" $CONFIGURATION_FILE; then
			CLEANUP_MAILDIR_COMMIT=$(grep "CLEANUP_MAILDIR_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "CLEANUP_MAILDIR_REPO" $CONFIGURATION_FILE; then
			CLEANUP_MAILDIR_REPO=$(grep "CLEANUP_MAILDIR_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "ZERONET_COMMIT" $CONFIGURATION_FILE; then
			ZERONET_COMMIT=$(grep "ZERONET_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "INADYN_REPO" $CONFIGURATION_FILE; then
			INADYN_REPO=$(grep "INADYN_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "INADYN_COMMIT" $CONFIGURATION_FILE; then
			INADYN_COMMIT=$(grep "INADYN_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "GPG_KEYSERVER" $CONFIGURATION_FILE; then
			GPG_KEYSERVER=$(grep "GPG_KEYSERVER" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "IPFS_PORT" $CONFIGURATION_FILE; then
			IPFS_PORT=$(grep "IPFS_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "TRACKER_PORT" $CONFIGURATION_FILE; then
			TRACKER_PORT=$(grep "TRACKER_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "ZERONET_PORT" $CONFIGURATION_FILE; then
			ZERONET_PORT=$(grep "ZERONET_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "DH_KEYLENGTH" $CONFIGURATION_FILE; then
			DH_KEYLENGTH=$(grep "DH_KEYLENGTH" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "IRC_PORT" $CONFIGURATION_FILE; then
			IRC_PORT=$(grep "IRC_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "WIFI_CHANNEL" $CONFIGURATION_FILE; then
			WIFI_CHANNEL=$(grep "WIFI_CHANNEL" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "BATMAN_CELLID" $CONFIGURATION_FILE; then
			BATMAN_CELLID=$(grep "BATMAN_CELLID" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "TOX_PORT" $CONFIGURATION_FILE; then
			TOX_PORT=$(grep "TOX_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "TOX_NODES" $CONFIGURATION_FILE; then
			TOX_NODES=$(grep "TOX_NODES" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "TOXCORE_REPO" $CONFIGURATION_FILE; then
			TOXCORE_REPO=$(grep "TOXCORE_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "ENABLE_SOCIAL_KEY_MANAGEMENT" $CONFIGURATION_FILE; then
			ENABLE_SOCIAL_KEY_MANAGEMENT=$(grep "ENABLE_SOCIAL_KEY_MANAGEMENT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "IPV6_NETWORK" $CONFIGURATION_FILE; then
			IPV6_NETWORK=$(grep "IPV6_NETWORK" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "HWRNG_TYPE" $CONFIGURATION_FILE; then
			HWRNG_TYPE=$(grep "HWRNG_TYPE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MEDIAGOBLIN_DOMAIN_NAME" $CONFIGURATION_FILE; then
			MEDIAGOBLIN_DOMAIN_NAME=$(grep "MEDIAGOBLIN_DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MEDIAGOBLIN_CODE" $CONFIGURATION_FILE; then
			MEDIAGOBLIN_CODE=$(grep "MEDIAGOBLIN_CODE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MEDIAGOBLIN_REPO" $CONFIGURATION_FILE; then
			MEDIAGOBLIN_REPO=$(grep "MEDIAGOBLIN_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MEDIAGOBLIN_COMMIT" $CONFIGURATION_FILE; then
			MEDIAGOBLIN_COMMIT=$(grep "MEDIAGOBLIN_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "GIT_ADMIN_PASSWORD" $CONFIGURATION_FILE; then
			GIT_ADMIN_PASSWORD=$(grep "GIT_ADMIN_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "GIT_DOMAIN_NAME" $CONFIGURATION_FILE; then
			GIT_DOMAIN_NAME=$(grep "GIT_DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "GIT_CODE" $CONFIGURATION_FILE; then
			GIT_CODE=$(grep "GIT_CODE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SYSTEM_TYPE" $CONFIGURATION_FILE; then
			SYSTEM_TYPE=$(grep "SYSTEM_TYPE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SSL_PROTOCOLS" $CONFIGURATION_FILE; then
			SSL_PROTOCOLS=$(grep "SSL_PROTOCOLS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SSL_CIPHERS" $CONFIGURATION_FILE; then
			SSL_CIPHERS=$(grep "SSL_CIPHERS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SSH_CIPHERS" $CONFIGURATION_FILE; then
			SSH_CIPHERS=$(grep "SSH_CIPHERS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SSH_MACS" $CONFIGURATION_FILE; then
			SSH_MACS=$(grep "SSH_MACS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SSH_KEX" $CONFIGURATION_FILE; then
			SSH_KEX=$(grep "SSH_KEX" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SSH_HOST_KEY_ALGORITHMS" $CONFIGURATION_FILE; then
			SSH_HOST_KEY_ALGORITHMS=$(grep "SSH_HOST_KEY_ALGORITHMS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SSH_PASSWORDS" $CONFIGURATION_FILE; then
			SSH_PASSWORDS=$(grep "SSH_PASSWORDS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "XMPP_CIPHERS" $CONFIGURATION_FILE; then
			XMPP_CIPHERS=$(grep "XMPP_CIPHERS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "XMPP_ECC_CURVE" $CONFIGURATION_FILE; then
			XMPP_ECC_CURVE=$(grep "XMPP_ECC_CURVE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MY_USERNAME" $CONFIGURATION_FILE; then
			MY_USERNAME=$(grep "MY_USERNAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "DOMAIN_NAME" $CONFIGURATION_FILE; then
			# for backwards compatability
			DEFAULT_DOMAIN_NAME=$(grep "DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "DEFAULT_DOMAIN_NAME" $CONFIGURATION_FILE; then
			DEFAULT_DOMAIN_NAME=$(grep "DEFAULT_DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "DEFAULT_DOMAIN_CODE" $CONFIGURATION_FILE; then
			DEFAULT_DOMAIN_CODE=$(grep "DEFAULT_DOMAIN_CODE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "NAMESERVER1" $CONFIGURATION_FILE; then
			NAMESERVER1=$(grep "NAMESERVER1" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "NAMESERVER2" $CONFIGURATION_FILE; then
			NAMESERVER2=$(grep "NAMESERVER2" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "DEBIAN_REPO" $CONFIGURATION_FILE; then
			DEBIAN_REPO=$(grep "DEBIAN_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
			CHECK_MESSAGE=$"Check your internet connection, /etc/network/interfaces and /etc/resolv.conf, then delete $COMPLETION_FILE, run 'rm -fR /var/lib/apt/lists/* && apt-get update --fix-missing' and run this script again. If hash sum mismatches persist then try setting $DEBIAN_REPO to a different mirror and also change /etc/apt/sources.list."
		fi
		if grep -q "VOIP_PORT" $CONFIGURATION_FILE; then
			VOIP_PORT=$(grep "VOIP_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "VOIP_SERVER_PASSWORD" $CONFIGURATION_FILE; then
			VOIP_SERVER_PASSWORD=$(grep "VOIP_SERVER_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SIP_PORT" $CONFIGURATION_FILE; then
			SIP_PORT=$(grep "SIP_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SIP_TLS_PORT" $CONFIGURATION_FILE; then
			SIP_TLS_PORT=$(grep "SIP_TLS_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SIP_SERVER_PASSWORD" $CONFIGURATION_FILE; then
			SIP_SERVER_PASSWORD=$(grep "SIP_SERVER_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "GET_IP_ADDRESS_URL" $CONFIGURATION_FILE; then
			GET_IP_ADDRESS_URL=$(grep "GET_IP_ADDRESS_URL" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "DDNS_PROVIDER" $CONFIGURATION_FILE; then
			DDNS_PROVIDER=$(grep "DDNS_PROVIDER" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "DDNS_USERNAME" $CONFIGURATION_FILE; then
			DDNS_USERNAME=$(grep "DDNS_USERNAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "DDNS_PASSWORD" $CONFIGURATION_FILE; then
			DDNS_PASSWORD=$(grep "DDNS_PASSWORD" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "LOCAL_NETWORK_STATIC_IP_ADDRESS" $CONFIGURATION_FILE; then
			LOCAL_NETWORK_STATIC_IP_ADDRESS=$(grep "LOCAL_NETWORK_STATIC_IP_ADDRESS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "ENABLE_BABEL" $CONFIGURATION_FILE; then
			ENABLE_BABEL=$(grep "ENABLE_BABEL" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "ENABLE_BATMAN" $CONFIGURATION_FILE; then
			ENABLE_BATMAN=$(grep "ENABLE_BATMAN" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "ENABLE_CJDNS" $CONFIGURATION_FILE; then
			ENABLE_CJDNS=$(grep "ENABLE_CJDNS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "CJDNS_COMMIT" $CONFIGURATION_FILE; then
			CJDNS_COMMIT=$(grep "CJDNS_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "CJDNS_IPV6" $CONFIGURATION_FILE; then
			CJDNS_IPV6=$(grep "CJDNS_IPV6" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "CJDNS_PUBLIC_KEY" $CONFIGURATION_FILE; then
			CJDNS_PUBLIC_KEY=$(grep "CJDNS_PUBLIC_KEY" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "CJDNS_PRIVATE_KEY" $CONFIGURATION_FILE; then
			CJDNS_PRIVATE_KEY=$(grep "CJDNS_PRIVATE_KEY" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "ROUTER_IP_ADDRESS" $CONFIGURATION_FILE; then
			ROUTER_IP_ADDRESS=$(grep "ROUTER_IP_ADDRESS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "CPU_CORES" $CONFIGURATION_FILE; then
			CPU_CORES=$(grep "CPU_CORES" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "WEBSERVER_LOG_LEVEL" $CONFIGURATION_FILE; then
			WEBSERVER_LOG_LEVEL=$(grep "WEBSERVER_LOG_LEVEL" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "ROUTE_THROUGH_TOR" $CONFIGURATION_FILE; then
			ROUTE_THROUGH_TOR=$(grep "ROUTE_THROUGH_TOR" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "WIKI_TITLE" $CONFIGURATION_FILE; then
			WIKI_TITLE=$(grep "WIKI_TITLE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MY_NAME" $CONFIGURATION_FILE; then
			MY_NAME=$(grep "MY_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MY_EMAIL_ADDRESS" $CONFIGURATION_FILE; then
			MY_EMAIL_ADDRESS=$(grep "MY_EMAIL_ADDRESS" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "INSTALLING_ON_BBB" $CONFIGURATION_FILE; then
			INSTALLING_ON_BBB=$(grep "INSTALLING_ON_BBB" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "SSH_PORT" $CONFIGURATION_FILE; then
			SSH_PORT=$(grep "SSH_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "INSTALLED_WITHIN_DOCKER" $CONFIGURATION_FILE; then
			INSTALLED_WITHIN_DOCKER=$(grep "INSTALLED_WITHIN_DOCKER" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "PUBLIC_MAILING_LIST" $CONFIGURATION_FILE; then
			PUBLIC_MAILING_LIST=$(grep "PUBLIC_MAILING_LIST" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MICROBLOG_DOMAIN_NAME" $CONFIGURATION_FILE; then
			MICROBLOG_DOMAIN_NAME=$(grep "MICROBLOG_DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MICROBLOG_CODE" $CONFIGURATION_FILE; then
			MICROBLOG_CODE=$(grep "MICROBLOG_CODE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "HUBZILLA_DOMAIN_NAME" $CONFIGURATION_FILE; then
			HUBZILLA_DOMAIN_NAME=$(grep "HUBZILLA_DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "HUBZILLA_CODE" $CONFIGURATION_FILE; then
			HUBZILLA_CODE=$(grep "HUBZILLA_CODE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "WIKI_DOMAIN_NAME" $CONFIGURATION_FILE; then
			WIKI_DOMAIN_NAME=$(grep "WIKI_DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "WIKI_CODE" $CONFIGURATION_FILE; then
			WIKI_CODE=$(grep "WIKI_CODE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "FULLBLOG_DOMAIN_NAME" $CONFIGURATION_FILE; then
			FULLBLOG_DOMAIN_NAME=$(grep "FULLBLOG_DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "FULLBLOG_CODE" $CONFIGURATION_FILE; then
			FULLBLOG_CODE=$(grep "FULLBLOG_CODE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MY_BLOG_TITLE" $CONFIGURATION_FILE; then
			MY_BLOG_TITLE=$(grep "MY_BLOG_TITLE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MY_BLOG_SUBTITLE" $CONFIGURATION_FILE; then
			MY_BLOG_SUBTITLE=$(grep "MY_BLOG_SUBTITLE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "GPG_ENCRYPT_STORED_EMAIL" $CONFIGURATION_FILE; then
			GPG_ENCRYPT_STORED_EMAIL=$(grep "GPG_ENCRYPT_STORED_EMAIL" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MY_GPG_PUBLIC_KEY" $CONFIGURATION_FILE; then
			MY_GPG_PUBLIC_KEY=$(grep "MY_GPG_PUBLIC_KEY" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MY_GPG_PRIVATE_KEY" $CONFIGURATION_FILE; then
			MY_GPG_PRIVATE_KEY=$(grep "MY_GPG_PRIVATE_KEY" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MY_GPG_PUBLIC_KEY_ID" $CONFIGURATION_FILE; then
			MY_GPG_PUBLIC_KEY_ID=$(grep "MY_GPG_PUBLIC_KEY_ID" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "USB_DRIVE" $CONFIGURATION_FILE; then
			USB_DRIVE=$(grep "USB_DRIVE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "MAX_PHP_MEMORY" $CONFIGURATION_FILE; then
			MAX_PHP_MEMORY=$(grep "MAX_PHP_MEMORY" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "TLS_TIME_SOURCE1" $CONFIGURATION_FILE; then
			TLS_TIME_SOURCE1=$(grep "TLS_TIME_SOURCE1" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
		if grep -q "TLS_TIME_SOURCE2" $CONFIGURATION_FILE; then
			TLS_TIME_SOURCE2=$(grep "TLS_TIME_SOURCE2" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
		fi
	fi
	echo "System type: $SYSTEM_TYPE"
}

# check that domain names are sensible
function check_domains {
	if [ ${#WIKI_DOMAIN_NAME} -gt 1 ]; then
		function_check test_domain_name
		test_domain_name "$WIKI_DOMAIN_NAME"

		if [[ "$test_domain_name" == "$FULLBLOG_DOMAIN_NAME" ]]; then
			echo $'Wiki domain name is the same as blog domain name. They must be different'
			exit 97326
		fi
		if [[ "$test_domain_name" == "$MICROBLOG_DOMAIN_NAME" ]]; then
			echo $'Wiki domain name is the same as microblog domain name. They must be different'
			exit 36827
		fi
		if [[ "$test_domain_name" == "$HUBZILLA_DOMAIN_NAME" ]]; then
			echo $'Wiki domain name is the same as hubzilla domain name. They must be different'
			exit 65848
		fi
		if [ ${#GIT_DOMAIN_NAME} -gt 1 ]; then
			if [[ "$test_domain_name" == "$GIT_DOMAIN_NAME" ]]; then
				echo $'Wiki domain name is the same as Gogs domain name. They must be different'
				exit 73529
			fi
		fi
	fi

	if [ ${#FULLBLOG_DOMAIN_NAME} -gt 1 ]; then
		function_check test_domain_name
		test_domain_name "$FULLBLOG_DOMAIN_NAME"

		if [[ "$test_domain_name" == "$WIKI_DOMAIN_NAME" ]]; then
			echo $'Blog domain name is the same as wiki domain name. They must be different'
			exit 62348
		fi
		if [[ "$test_domain_name" == "$MICROBLOG_DOMAIN_NAME" ]]; then
			echo $'Blog domain name is the same as microblog domain name. They must be different'
			exit 38236
		fi
		if [[ "$test_domain_name" == "$HUBZILLA_DOMAIN_NAME" ]]; then
			echo $'Blog domain name is the same as hubzilla domain name. They must be different'
			exit 35483
		fi
		if [ $GIT_DOMAIN_NAME ]; then
			if [[ "$test_domain_name" == "$GIT_DOMAIN_NAME" ]]; then
				echo $'Blog domain name is the same as Gogs domain name. They must be different'
				exit 84695
			fi
		fi
	fi

	if [ ${#MICROBLOG_DOMAIN_NAME} -gt 1 ]; then
		function_check test_domain_name
		test_domain_name "$MICROBLOG_DOMAIN_NAME"

		if [[ "$test_domain_name" == "$WIKI_DOMAIN_NAME" ]]; then
			echo $'Microblog domain name is the same as wiki domain name. They must be different'
			exit 73924
		fi
		if [[ "$test_domain_name" == "$FULLBLOG_DOMAIN_NAME" ]]; then
			echo $'Microblog domain name is the same as blog domain name. They must be different'
			exit 26832
		fi
		if [[ "$test_domain_name" == "$HUBZILLA_DOMAIN_NAME" ]]; then
			echo $'Microblog domain name is the same as hubzilla domain name. They must be different'
			exit 678382
		fi
		if [ $GIT_DOMAIN_NAME ]; then
			if [[ "$test_domain_name" == "$GIT_DOMAIN_NAME" ]]; then
				echo $'Microblog domain name is the same as Gogs domain name. They must be different'
				exit 684325
			fi
		fi
	fi

	if [ $HUBZILLA_DOMAIN_NAME ]; then
		function_check test_domain_name
		test_domain_name "$HUBZILLA_DOMAIN_NAME"

		if [[ "$test_domain_name" == "$WIKI_DOMAIN_NAME" ]]; then
			echo $'Hubzilla domain name is the same as wiki domain name. They must be different'
			exit 83682
		fi
		if [[ "$test_domain_name" == "$FULLBLOG_DOMAIN_NAME" ]]; then
			echo $'Hubzilla domain name is the same as blog domain name. They must be different'
			exit 74817
		fi
		if [[ "$test_domain_name" == "$MICROBLOG_DOMAIN_NAME" ]]; then
			echo $'Hubzilla domain name is the same as microblog domain name. They must be different'
			exit 83683
		fi
		if [ ${#GIT_DOMAIN_NAME} -gt 1 ]; then
			if [[ "$test_domain_name" == "$GIT_DOMAIN_NAME" ]]; then
				echo $'Hubzilla domain name is the same as Gogs domain name. They must be different'
				exit 135523
			fi
		fi
	fi

	if [ ${#GIT_DOMAIN_NAME} -gt 1 ]; then
		function_check test_domain_name
		test_domain_name "$GIT_DOMAIN_NAME"

		if [[ "$test_domain_name" == "$WIKI_DOMAIN_NAME" ]]; then
			echo $'Hubzilla domain name is the same as wiki domain name. They must be different'
			exit 83682
		fi
		if [[ "$test_domain_name" == "$FULLBLOG_DOMAIN_NAME" ]]; then
			echo $'Hubzilla domain name is the same as blog domain name. They must be different'
			exit 74817
		fi
		if [[ "$test_domain_name" == "$MICROBLOG_DOMAIN_NAME" ]]; then
			echo $'Hubzilla domain name is the same as microblog domain name. They must be different'
			exit 83683
		fi
		if [[ "$test_domain_name" == "$HUBZILLA_DOMAIN_NAME" ]]; then
			echo $'Microblog domain name is the same as hubzilla domain name. They must be different'
			exit 678382
		fi
	fi
}

# NOTE: deliberately no exit 0
