#!/bin/bash
#
# .---.                  .              .
# |                      |              |
# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
#
#                    Freedom in the Cloud
#
# Interactively creates a configuration file for use with the main
# freedombone command
#
# License
# =======
#
# Copyright (C) 2015 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 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

NO_OF_ARGS=$#

# Web site
FREEDOMBONE_WEBSITE="http://freedombone.uk.to"

# Contact details
FREEDOMBONE_BITMESSAGE="BM-2cWuhmBvVdfrHhLoZTdspCkKeiTorUesSL"

# Minimum number of characters in a password
MINIMUM_PASSWORD_LENGTH=10

# Different system variants which may be specified within
# the SYSTEM_TYPE option
VARIANT_FULL="full"
VARIANT_WRITER="writer"
VARIANT_CLOUD="cloud"
VARIANT_CHAT="chat"
VARIANT_MAILBOX="mailbox"
VARIANT_NONMAILBOX="nonmailbox"
VARIANT_SOCIAL="social"
VARIANT_MEDIA="media"
VARIANT_DEVELOPER="developer"

MY_USERNAME=
DEFAULT_DOMAIN_NAME=
DEFAULT_DOMAIN_CODE=
MY_EMAIL_ADDRESS=
SYSTEM_TYPE=
INSTALLING_ON_BBB=
DDNS_PROVIDER=
DDNS_USERNAME=
DDNS_PASSWORD=
MY_NAME=
LOCAL_NETWORK_STATIC_IP_ADDRESS=
ROUTER_IP_ADDRESS=
ENABLE_CJDNS=
DEBIAN_REPO=
NAMESERVER1=
NAMESERVER2=
WIKI_TITLE=
WIKI_DOMAIN_NAME=
WIKI_CODE=
MY_BLOG_TITLE=
FULLBLOG_DOMAIN_NAME=
FULLBLOG_CODE=
OWNCLOUD_DOMAIN_NAME=
OWNCLOUD_CODE=
REDMATRIX_DOMAIN_NAME=
REDMATRIX_CODE=
MICROBLOG_DOMAIN_NAME=
MICROBLOG_CODE=
GIT_DOMAIN_NAME=
GIT_CODE=

CONFIGURATION_FILE=

function show_help {
  echo ''
  echo 'freedombone-config -f [config filename] -m [min password length]'
  echo ''
  echo 'Creates an inventory of remote backup locations'
  echo ''
  echo ''
  echo '  -h --help             Show help'
  echo '  -f --filename         Configuration file (usually freedombone.cfg)'
  echo '  -m --min              Minimum password length (characters)'
  echo '  -w --www              Freedombone web site'
  echo '  -b --bm               Freedombone support Bitmessage address'
  echo ''
  exit 0
}

# Get the commandline options
while [[ $# > 1 ]]
do
key="$1"

case $key in
    -h|--help)
    show_help
    ;;
    # Configuration filename
    -f|--filename)
    shift
    CONFIGURATION_FILE="$1"
    ;;
    # Minimum password length
    -m|--min)
    shift
    MINIMUM_PASSWORD_LENGTH="$1"
    ;;
    # Freedombone website
    -w|--www)
    shift
    FREEDOMBONE_WEBSITE="$1"
    ;;
    # Bitmessage address for support
    -b|--bm)
    shift
    FREEDOMBONE_BITMESSAGE="$1"
    ;;
    *)
    # unknown option
    ;;
esac
shift
done

function save_configuration_file {
  if [ ! $CONFIGURATION_FILE ]; then
      CONFIGURATION_FILE='freedombone.cfg'
  fi

  echo "MY_USERNAME=$MY_USERNAME" > $CONFIGURATION_FILE
  echo "DEFAULT_DOMAIN_NAME=$DEFAULT_DOMAIN_NAME" >> $CONFIGURATION_FILE
  if [ $DEFAULT_DOMAIN_CODE ]; then
      echo "DEFAULT_DOMAIN_CODE=$DEFAULT_DOMAIN_CODE" >> $CONFIGURATION_FILE
  fi
  echo "SYSTEM_TYPE=$SYSTEM_TYPE" >> $CONFIGURATION_FILE
  echo "INSTALLING_ON_BBB=$INSTALLING_ON_BBB" >> $CONFIGURATION_FILE
  echo "DDNS_PROVIDER=$DDNS_PROVIDER" >> $CONFIGURATION_FILE
  echo "DDNS_USERNAME=$DDNS_USERNAME" >> $CONFIGURATION_FILE
  echo "DDNS_PASSWORD=$DDNS_PASSWORD" >> $CONFIGURATION_FILE
  echo "MY_NAME=$MY_NAME" >> $CONFIGURATION_FILE
  echo "MY_EMAIL_ADDRESS=$MY_EMAIL_ADDRESS" >> $CONFIGURATION_FILE
  echo "LOCAL_NETWORK_STATIC_IP_ADDRESS=$LOCAL_NETWORK_STATIC_IP_ADDRESS" >> $CONFIGURATION_FILE
  echo "ROUTER_IP_ADDRESS=$ROUTER_IP_ADDRESS" >> $CONFIGURATION_FILE
  if [ $ENABLE_CJDNS ]; then
      echo "ENABLE_CJDNS=$ENABLE_CJDNS" >> $CONFIGURATION_FILE
  fi
  echo "DEBIAN_REPO=$DEBIAN_REPO" >> $CONFIGURATION_FILE
  echo "NAMESERVER1=$NAMESERVER1" >> $CONFIGURATION_FILE
  echo "NAMESERVER2=$NAMESERVER2" >> $CONFIGURATION_FILE
  if [ $WIKI_TITLE ]; then
      echo "WIKI_TITLE=$WIKI_TITLE" >> $CONFIGURATION_FILE
  fi
  if [ $WIKI_DOMAIN_NAME ]; then
      echo "WIKI_DOMAIN_NAME=$WIKI_DOMAIN_NAME" >> $CONFIGURATION_FILE
  fi
  if [ $WIKI_CODE ]; then
      echo "WIKI_CODE=$WIKI_CODE" >> $CONFIGURATION_FILE
  fi
  if [ $MY_BLOG_TITLE ]; then
      echo "MY_BLOG_TITLE=$MY_BLOG_TITLE" >> $CONFIGURATION_FILE
  fi
  if [ $FULLBLOG_DOMAIN_NAME ]; then
      echo "FULLBLOG_DOMAIN_NAME=$FULLBLOG_DOMAIN_NAME" >> $CONFIGURATION_FILE
  fi
  if [ $FULLBLOG_CODE ]; then
      echo "FULLBLOG_CODE=$FULLBLOG_CODE" >> $CONFIGURATION_FILE
  fi
  if [ $OWNCLOUD_DOMAIN_NAME ]; then
      echo "OWNCLOUD_DOMAIN_NAME=$OWNCLOUD_DOMAIN_NAME" >> $CONFIGURATION_FILE
  fi
  if [ $OWNCLOUD_CODE ]; then
      echo "OWNCLOUD_CODE=$OWNCLOUD_CODE" >> $CONFIGURATION_FILE
  fi
  if [ $REDMATRIX_DOMAIN_NAME ]; then
      echo "REDMATRIX_DOMAIN_NAME=$REDMATRIX_DOMAIN_NAME" >> $CONFIGURATION_FILE
  fi
  if [ $REDMATRIX_CODE ]; then
      echo "REDMATRIX_CODE=$REDMATRIX_CODE" >> $CONFIGURATION_FILE
  fi
  if [ $MICROBLOG_DOMAIN_NAME ]; then
      echo "MICROBLOG_DOMAIN_NAME=$MICROBLOG_DOMAIN_NAME" >> $CONFIGURATION_FILE
  fi
  if [ $MICROBLOG_CODE ]; then
      echo "MICROBLOG_CODE=$MICROBLOG_CODE" >> $CONFIGURATION_FILE
  fi
  if [ $GIT_DOMAIN_NAME ]; then
      echo "GIT_DOMAIN_NAME=$GIT_DOMAIN_NAME" >> $CONFIGURATION_FILE
  fi
  if [ $GIT_CODE ]; then
      echo "GIT_CODE=$GIT_CODE" >> $CONFIGURATION_FILE
  fi
}

# test a domain name to see if it's valid
function validate_domain_name {
  # count the number of dots in the domain name
  dots=${TEST_DOMAIN_NAME//[^.]}
  no_of_dots=${#dots}
  if (( $no_of_dots > 3 )); then
      TEST_DOMAIN_NAME="The domain $TEST_DOMAIN_NAME has too many subdomains. It should be of the type w.x.y.z, x.y.z or y.z"
  fi
  if (( $no_of_dots == 0 )); then
      TEST_DOMAIN_NAME="The domain $TEST_DOMAIN_NAME has no top level domain. It should be of the type w.x.y.z, x.y.z or y.z"
  fi
}

function interactive_configuration {
  # create a temporary copy of the configuration file
  # which can be used to pre-populate selections
  if [ -f $CONFIGURATION_FILE ]; then
      cp $CONFIGURATION_FILE temp.cfg
  fi

  FREEDNS_MESSAGE="Please enter the FreeDNS code for this domain.\n\nThe code can be found by going to https://freedns.afraid.org, selecting 'Dynamic DNS' and then opening 'Wget example'. The code will consist of letters and numbers and be between the ? and = characters."

  dialog --title "Freedombone" --msgbox "Welcome to the Freedombone interactive installer. Communications freedom is only a short time away.\n\nEnsure that you have your domain and dynamic DNS settings ready.\n\nFor more information please visit $FREEDOMBONE_WEBSITE or send a Bitmessage to $FREEDOMBONE_BITMESSAGE" 15 50

  data=$(tempfile 2>/dev/null)
  trap "rm -f $data" 0 1 2 5 15
  dialog --backtitle "Freedombone Configuration" \
      --radiolist "Type of Installation:" 17 40 9 \
      1 Full on \
      2 Writer off \
      3 Cloud off \
      4 Chat off \
      5 Mailbox off \
      6 Non-Mailbox off \
      7 Social off \
      8 Media off \
      9 Developer off 2> $data
  sel=$?
  case $sel in
      1) exit 0;;
      255) exit 0;;
  esac
  case $(cat $data) in
      1) SYSTEM_TYPE=$VARIANT_FULL;;
      2) SYSTEM_TYPE=$VARIANT_WRITER;;
      3) SYSTEM_TYPE=$VARIANT_CLOUD;;
      4) SYSTEM_TYPE=$VARIANT_CHAT;;
      5) SYSTEM_TYPE=$VARIANT_MAILBOX;;
      6) SYSTEM_TYPE=$VARIANT_NONMAILBOX;;
      7) SYSTEM_TYPE=$VARIANT_SOCIAL;;
      8) SYSTEM_TYPE=$VARIANT_MEDIA;;
      9) SYSTEM_TYPE=$VARIANT_DEVELOPER;;
  esac
  save_configuration_file

  data=$(tempfile 2>/dev/null)
  trap "rm -f $data" 0 1 2 5 15
  dialog --title "Select the user account to install as" \
      --backtitle "Freedombone Configuration" \
      --dselect "/home/$(grep 'MY_USERNAME' temp.cfg | awk -F '=' '{print $2}')" 14 40 2> $data
  sel=$?
  case $sel in
      0) MY_USERNAME=$(cat $data | awk -F '/' '{print $3}');;
      1) exit 0;;
      255) exit 0;;
  esac
  if [ ! $MY_USERNAME ]; then
      echo 'No user account was selected'
      exit 64398
  fi
  if [[ $MY_USERNAME == '-f' ]]; then
      echo 'No user account was selected'
      exit 8347
  fi
  if [[ $MY_USERNAME == 'debian' ]]; then
      echo "Don't use the default debian user account"
      exit 9341
  fi
  if [ ! -d /home/$MY_USERNAME ]; then
      echo "The directory /home/$MY_USERNAME does not exist"
      exit 6437
  fi
  save_configuration_file

  if [[ $(grep "INSTALLING_ON_BBB" temp.cfg | awk -F '=' '{print $2}') == "yes" ]]; then
      dialog --title "Install Target" \
          --backtitle "Freedombone Configuration" \
          --yesno "\nAre you installing onto a Beaglebone Black?" 7 60
  else
      dialog --title "Install Target" \
          --backtitle "Freedombone Configuration" \
          --defaultno \
          --yesno "\nAre you installing onto a Beaglebone Black?" 7 60
  fi
  sel=$?
  case $sel in
      0) INSTALLING_ON_BBB="yes";;
      1) INSTALLING_ON_BBB="no";;
      255) exit 0;;
  esac
  save_configuration_file

  data=$(tempfile 2>/dev/null)
  trap "rm -f $data" 0 1 2 5 15
  dialog --backtitle "Freedombone Configuration" \
      --radiolist "Where to download Debian packages from:" 25 45 49 \
      1 "Australia" off \
      2 "Austria" off \
      3 "Belarus" off \
      4 "Belgium" off \
      5 "Bosnia and Herzegovina" off \
      6 "Brazil" off \
      7 "Bulgaria" off \
      8 "Canada" off \
      9 "Chile" off \
      10 "China" off \
      11 "Croatia" off \
      12 "Czech Republic" off \
      13 "Denmark" off \
      14 "El Salvador" off \
      15 "Estonia" off \
      16 "Finland" off \
      17 "France 1" off \
      18 "France 2" off \
      19 "Germany 1" off \
      20 "Germany 2" off \
      21 "Greece" off \
      22 "Hungary" off \
      23 "Iceland" off \
      24 "Iran" off \
      25 "Ireland" off \
      26 "Italy" off \
      27 "Japan" off \
      28 "Korea" off \
      29 "Lithuania" off \
      30 "Mexico" off \
      31 "Netherlands" off \
      32 "New Caledonia" off \
      33 "New Zealand" off \
      34 "Norway" off \
      35 "Poland" off \
      36 "Portugal" off \
      37 "Romania" off \
      38 "Russia" off \
      39 "Slovakia" off \
      40 "Slovenia" off \
      41 "Spain" off \
      42 "Sweden" off \
      43 "Switzerland" off \
      44 "Taiwan" off \
      45 "Thailand" off \
      46 "Turkey" off \
      47 "Ukraine" off \
      48 "United Kingdom" off \
      49 "United States" on 2> $data
  sel=$?
  case $sel in
      1) exit 0;;
      255) exit 0;;
  esac
  case $(cat $data) in
      1) DEBIAN_REPO='ftp.au.debian.org';;
      2) DEBIAN_REPO='ftp.at.debian.org';;
      3) DEBIAN_REPO='ftp.by.debian.org';;
      4) DEBIAN_REPO='ftp.be.debian.org';;
      5) DEBIAN_REPO='ftp.ba.debian.org';;
      6) DEBIAN_REPO='ftp.br.debian.org';;
      7) DEBIAN_REPO='ftp.bg.debian.org';;
      8) DEBIAN_REPO='ftp.ca.debian.org';;
      9) DEBIAN_REPO='ftp.cl.debian.org';;
      10) DEBIAN_REPO='ftp.cn.debian.org';;
      11) DEBIAN_REPO='ftp.hr.debian.org';;
      12) DEBIAN_REPO='ftp.cz.debian.org';;
      13) DEBIAN_REPO='ftp.dk.debian.org';;
      14) DEBIAN_REPO='ftp.sv.debian.org';;
      15) DEBIAN_REPO='ftp.ee.debian.org';;
      16) DEBIAN_REPO='ftp.fi.debian.org';;
      17) DEBIAN_REPO='ftp2.fr.debian.org';;
      18) DEBIAN_REPO='ftp.fr.debian.org';;
      19) DEBIAN_REPO='ftp2.de.debian.org';;
      20) DEBIAN_REPO='ftp.de.debian.org';;
      21) DEBIAN_REPO='ftp.gr.debian.org';;
      22) DEBIAN_REPO='ftp.hu.debian.org';;
      23) DEBIAN_REPO='ftp.is.debian.org';;
      24) DEBIAN_REPO='ftp.ir.debian.org';;
      25) DEBIAN_REPO='ftp.ie.debian.org';;
      26) DEBIAN_REPO='ftp.it.debian.org';;
      27) DEBIAN_REPO='ftp.jp.debian.org';;
      28) DEBIAN_REPO='ftp.kr.debian.org';;
      29) DEBIAN_REPO='ftp.lt.debian.org';;
      30) DEBIAN_REPO='ftp.mx.debian.org';;
      31) DEBIAN_REPO='ftp.nl.debian.org';;
      32) DEBIAN_REPO='ftp.nc.debian.org';;
      33) DEBIAN_REPO='ftp.nz.debian.org';;
      34) DEBIAN_REPO='ftp.no.debian.org';;
      35) DEBIAN_REPO='ftp.pl.debian.org';;
      36) DEBIAN_REPO='ftp.pt.debian.org';;
      37) DEBIAN_REPO='ftp.ro.debian.org';;
      38) DEBIAN_REPO='ftp.ru.debian.org';;
      39) DEBIAN_REPO='ftp.sk.debian.org';;
      40) DEBIAN_REPO='ftp.si.debian.org';;
      41) DEBIAN_REPO='ftp.es.debian.org';;
      42) DEBIAN_REPO='ftp.se.debian.org';;
      43) DEBIAN_REPO='ftp.ch.debian.org';;
      44) DEBIAN_REPO='ftp.tw.debian.org';;
      45) DEBIAN_REPO='ftp.th.debian.org';;
      46) DEBIAN_REPO='ftp.tr.debian.org';;
      47) DEBIAN_REPO='ftp.ua.debian.org';;
      48) DEBIAN_REPO='ftp.uk.debian.org';;
      49) DEBIAN_REPO='ftp.us.debian.org';;
      255) exit 0;;
  esac
  save_configuration_file

  data=$(tempfile 2>/dev/null)
  trap "rm -f $data" 0 1 2 5 15
  dialog --backtitle "Freedombone Configuration" \
      --radiolist "Pick a domain name service (DNS):" 25 50 16 \
      1 "Digital Courage" on \
      2 "German Privacy Foundation 1" off \
      3 "German Privacy Foundation 2" off \
      4 "Chaos Computer Club" off \
      5 "ClaraNet" off \
      6 "OpenNIC 1" off \
      7 "OpenNIC 2" off \
      8 "OpenNIC 3" off \
      9 "OpenNIC 4" off \
      10 "OpenNIC 5" off \
      11 "OpenNIC 6" off \
      12 "OpenNIC 7" off \
      13 "PowerNS" off \
      14 "ValiDOM" off \
      15 "Freie Unzensierte" off \
      16 "Google" off 2> $data
  sel=$?
  case $sel in
      1) exit 0;;
      255) exit 0;;
  esac
  case $(cat $data) in
      1) NAMESERVER1='85.214.73.63'
         NAMESERVER2='213.73.91.35'
         ;;
      2) NAMESERVER1='87.118.100.175'
         NAMESERVER2='94.75.228.29'
         ;;
      3) NAMESERVER1='85.25.251.254'
         NAMESERVER2='2.141.58.13'
         ;;
      4) NAMESERVER1='213.73.91.35'
         NAMESERVER2='85.214.73.63'
         ;;
      5) NAMESERVER1='212.82.225.7'
         NAMESERVER2='212.82.226.212'
         ;;
      6) NAMESERVER1='58.6.115.42'
         NAMESERVER2='58.6.115.43'
         ;;
      7) NAMESERVER1='119.31.230.42'
         NAMESERVER2='200.252.98.162'
         ;;
      8) NAMESERVER1='217.79.186.148'
         NAMESERVER2='81.89.98.6'
         ;;
      9) NAMESERVER1='78.159.101.37'
         NAMESERVER2='203.167.220.153'
         ;;
      10) NAMESERVER1='82.229.244.191'
          NAMESERVER2='82.229.244.191'
          ;;
      11) NAMESERVER1='216.87.84.211'
          NAMESERVER2='66.244.95.20'
          ;;
      12) NAMESERVER1='207.192.69.155'
          NAMESERVER2='72.14.189.120'
          ;;
      13) NAMESERVER1='194.145.226.26'
          NAMESERVER2='77.220.232.44'
          ;;
      14) NAMESERVER1='78.46.89.147'
          NAMESERVER2='88.198.75.145'
          ;;
      15) NAMESERVER1='85.25.149.144'
          NAMESERVER2='87.106.37.196'
          ;;
      16) NAMESERVER1='8.8.8.8'
          NAMESERVER2='4.4.4.4'
          ;;
      255) exit 0;;
  esac
  save_configuration_file

  data=$(tempfile 2>/dev/null)
  trap "rm -f $data" 0 1 2 5 15
  dialog --backtitle "Freedombone Configuration" \
      --radiolist "Choose Dynamic DNS provider:" 15 40 14 \
      1 dyndns off \
      2 freedns on \
      3 zoneedit off \
      4 no-ip off \
      5 easydns off \
      6 tzo off \
      7 3322 off \
      8 dnsomatic off \
      9 tunnelbroker off \
      10 dns.he.net off \
      11 dynsip off \
      12 sitelutions off \
      13 dnsexit off \
      14 changeip off 2> $data
  sel=$?
  case $sel in
      1) exit 0;;
      255) exit 0;;
  esac
  case $(cat $data) in
      1) DDNS_PROVIDER="default@dyndns.org";;
      2) DDNS_PROVIDER="default@freedns.afraid.org";;
      3) DDNS_PROVIDER="default@zoneedit.com";;
      4) DDNS_PROVIDER="default@no-ip.com";;
      5) DDNS_PROVIDER="default@easydns.com";;
      6) DDNS_PROVIDER="default@tzo.com";;
      7) DDNS_PROVIDER="dyndns@3322.org";;
      8) DDNS_PROVIDER="default@dnsomatic.com";;
      9) DDNS_PROVIDER="ipv6tb@he.net";;
      10) DDNS_PROVIDER="dyndns@he.net";;
      11) DDNS_PROVIDER="default@dynsip.org";;
      12) DDNS_PROVIDER="default@sitelutions.com";;
      13) DDNS_PROVIDER="default@dnsexit.com";;
      14) DDNS_PROVIDER="default@changeip.com";;
      255) exit 0;;
  esac
  save_configuration_file

  while [ ! $DDNS_USERNAME ]
  do
      data=$(tempfile 2>/dev/null)
      trap "rm -f $data" 0 1 2 5 15
      dialog --backtitle "Freedombone Configuration" \
          --inputbox "Dynamic DNS provider username" 10 30 "$(grep 'DDNS_USERNAME' temp.cfg | awk -F '=' '{print $2}')" 2> $data
      sel=$?
      case $sel in
          0) DDNS_USERNAME=$(cat $data);;
          1) exit 0;;
          255) exit 0;;
      esac
  done
  save_configuration_file

  while [ ! $DDNS_PASSWORD ]
  do
      data=$(tempfile 2>/dev/null)
      trap "rm -f $data" 0 1 2 5 15
      dialog --backtitle "Freedombone Configuration" \
          --clear \
          --insecure \
          --passwordbox "Dynamic DNS provider password" 10 30 "$(grep 'DDNS_PASSWORD' temp.cfg | awk -F '=' '{print $2}')" 2> $data
      sel=$?
      case $sel in
          0) DDNS_PASSWORD=$(cat $data);;
          1) exit 0;;
          255) exit 0;;
      esac
      if [ ${#DDNS_PASSWORD} -lt $MINIMUM_PASSWORD_LENGTH ]; then
          dialog --title "Password quality check" --msgbox "The password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters. You may need to change your password on the dynamic DNS provider's web site." 10 40
          DDNS_PASSWORD=""
      fi
  done
  save_configuration_file

  while [ ! $MY_NAME ]
  do
      data=$(tempfile 2>/dev/null)
      trap "rm -f $data" 0 1 2 5 15
      dialog --backtitle "Freedombone Configuration" \
          --inputbox "Your full name (or nick)" 10 30 "$(grep 'MY_NAME' temp.cfg | awk -F '=' '{print $2}')" 2> $data
      sel=$?
      case $sel in
          0) MY_NAME=$(cat $data);;
          1) exit 0;;
          255) exit 0;;
      esac
  done
  save_configuration_file

  if [ ! $LOCAL_NETWORK_STATIC_IP_ADDRESS ]; then
      LOCAL_NETWORK_STATIC_IP_ADDRESS=$(grep 'LOCAL_NETWORK_STATIC_IP_ADDRESS' temp.cfg | awk -F '=' '{print $2}')
      if [ ! $LOCAL_NETWORK_STATIC_IP_ADDRESS ]; then
          LOCAL_NETWORK_STATIC_IP_ADDRESS='192.168..'
      fi
  fi
  if [ ! $ROUTER_IP_ADDRESS ]; then
      ROUTER_IP_ADDRESS=$(grep 'ROUTER_IP_ADDRESS' temp.cfg | awk -F '=' '{print $2}')
      if [ ! $ROUTER_IP_ADDRESS ]; then
          ROUTER_IP_ADDRESS='192.168..'
      fi
  fi
  data=$(tempfile 2>/dev/null)
  trap "rm -f $data" 0 1 2 5 15
  dialog --backtitle "Freedombone Configuration" \
      --title "Local Network Configuration" \
      --form "\nPlease enter the IP addresses:" 11 55 3 \
      "This system:" 1 1 "$LOCAL_NETWORK_STATIC_IP_ADDRESS" 1 16 16 15 \
      "Internet router:" 2 1 "$ROUTER_IP_ADDRESS" 2 16 16 15 \
      2> $data
  sel=$?
  case $sel in
      1) exit 0;;
      255) exit 0;;
  esac
  LOCAL_NETWORK_STATIC_IP_ADDRESS=$(cat $data | sed -n 1p)
  ROUTER_IP_ADDRESS=$(cat $data | sed -n 2p)
  save_configuration_file

  if [[ $SYSTEM_TYPE == "$VARIANT_WRITER" || $SYSTEM_TYPE == "$VARIANT_FULL" ]]; then
      WIKI_DETAILS_COMPLETE=
      while [ ! $WIKI_DETAILS_COMPLETE ]
      do
          data=$(tempfile 2>/dev/null)
          trap "rm -f $data" 0 1 2 5 15

          if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
              dialog --backtitle "Freedombone Configuration" \
                     --title "Wiki Configuration" \
                     --form "\nPlease enter your wiki details:" 11 55 4 \
                     "Title:" 1 1 "$(grep 'WIKI_TITLE' temp.cfg | awk -F '=' '{print $2}')" 1 16 25 40 \
                     "Domain:" 2 1 "$(grep 'WIKI_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 2 16 25 40 \
                     "Code:" 3 1 "$(grep 'WIKI_CODE' temp.cfg | awk -F '=' '{print $2}')" 3 16 25 40 \
                     2> $data
          else
              dialog --backtitle "Freedombone Configuration" \
                     --title "Wiki Configuration" \
                     --form "\nPlease enter your wiki details:" 11 55 3 \
                     "Title:" 1 1 "$(grep 'WIKI_TITLE' temp.cfg | awk -F '=' '{print $2}')" 1 16 25 40 \
                     "Domain:" 2 1 "$(grep 'WIKI_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 2 16 25 40 \
                     2> $data
          fi
          sel=$?
          case $sel in
              1) exit 0;;
              255) exit 0;;
          esac
          WIKI_TITLE=$(cat $data | sed -n 1p)
          WIKI_DOMAIN_NAME=$(cat $data | sed -n 2p)
          if [ $WIKI_DOMAIN_NAME ]; then
              TEST_DOMAIN_NAME=$WIKI_DOMAIN_NAME
              validate_domain_name
              if [[ $TEST_DOMAIN_NAME != $WIKI_DOMAIN_NAME ]]; then
                  WIKI_DOMAIN_NAME=
                  dialog --title "Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
              else
                  if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
                      WIKI_CODE=$(cat $data | sed -n 3p)
                      if [ ${#WIKI_CODE} -lt 30 ]; then
                          WIKI_DOMAIN_NAME=
                          dialog --title "FreeDNS code" --msgbox "$FREEDNS_MESSAGE" 15 50
                      fi
                  fi
              fi
          fi
          if [ $WIKI_DOMAIN_NAME ]; then
              WIKI_DETAILS_COMPLETE="yes"
          fi
      done
      save_configuration_file
  fi

  if [[ $SYSTEM_TYPE == "$VARIANT_WRITER" || $SYSTEM_TYPE == "$VARIANT_FULL" ]]; then
      FULLBLOG_DETAILS_COMPLETE=
      while [ ! $FULLBLOG_DETAILS_COMPLETE ]
      do
          data=$(tempfile 2>/dev/null)
          trap "rm -f $data" 0 1 2 5 15
          if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
              dialog --backtitle "Freedombone Configuration" \
                     --title "Blog Configuration" \
                     --form "\nPlease enter your blog details:" 11 55 4 \
                     "Title:" 1 1 "$(grep 'MY_BLOG_TITLE' temp.cfg | awk -F '=' '{print $2}')" 1 16 25 30 \
                     "Domain:" 2 1 "$(grep 'FULLBLOG_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 2 16 25 30 \
                     "Code:" 3 1 "$(grep 'FULLBLOG_CODE' temp.cfg | awk -F '=' '{print $2}')" 3 16 25 30 \
                     2> $data
          else
              dialog --backtitle "Freedombone Configuration" \
                     --title "Blog Configuration" \
                     --form "\nPlease enter your blog details:" 11 55 3 \
                     "Title:" 1 1 "$(grep 'MY_BLOG_TITLE' temp.cfg | awk -F '=' '{print $2}')" 1 16 25 30 \
                     "Domain:" 2 1 "$(grep 'FULLBLOG_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 2 16 25 30 \
                     2> $data
          fi
          sel=$?
          case $sel in
              1) exit 0;;
              255) exit 0;;
          esac
          MY_BLOG_TITLE=$(cat $data | sed -n 1p)
          FULLBLOG_DOMAIN_NAME=$(cat $data | sed -n 2p)
          if [ $FULLBLOG_DOMAIN_NAME ]; then
              if [[ $FULLBLOG_DOMAIN_NAME == "$WIKI_DOMAIN_NAME" ]]; then
                  FULLBLOG_DOMAIN_NAME=""
              fi
              TEST_DOMAIN_NAME=$FULLBLOG_DOMAIN_NAME
              validate_domain_name
              if [[ $TEST_DOMAIN_NAME != $FULLBLOG_DOMAIN_NAME ]]; then
                  FULLBLOG_DOMAIN_NAME=
                  dialog --title "Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
              else
                  if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
                      FULLBLOG_CODE=$(cat $data | sed -n 3p)
                      if [ ${#FULLBLOG_CODE} -lt 30 ]; then
                          FULLBLOG_DOMAIN_NAME=
                          dialog --title "FreeDNS code" --msgbox "$FREEDNS_MESSAGE" 15 50
                      fi
                  fi
              fi
          fi
          if [ $FULLBLOG_DOMAIN_NAME ]; then
              FULLBLOG_DETAILS_COMPLETE="yes"
          fi
      done
      save_configuration_file
  fi

  if [[ $SYSTEM_TYPE == "$VARIANT_CLOUD" || $SYSTEM_TYPE == "$VARIANT_FULL" ]]; then
      OWNCLOUD_DETAILS_COMPLETE=
      while [ ! $OWNCLOUD_DETAILS_COMPLETE ]
      do
          data=$(tempfile 2>/dev/null)
          trap "rm -f $data" 0 1 2 5 15
          if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
              dialog --backtitle "Freedombone Configuration" \
                     --title "Owncloud Configuration" \
                     --form "\nPlease enter your Owncloud details:" 11 55 3 \
                     "Domain:" 1 1 "$(grep 'OWNCLOUD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 25 30 \
                     "Code:" 2 1 "$(grep 'OWNCLOUD_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 16 25 30 \
                     2> $data
          else
              dialog --backtitle "Freedombone Configuration" \
                     --title "Owncloud Configuration" \
                     --form "\nPlease enter your Owncloud details:" 11 55 3 \
                     "Domain:" 1 1 "$(grep 'OWNCLOUD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 25 30 \
                     2> $data
          fi
          sel=$?
          case $sel in
              1) exit 0;;
              255) exit 0;;
          esac
          OWNCLOUD_DOMAIN_NAME=$(cat $data | sed -n 1p)
          if [ $OWNCLOUD_DOMAIN_NAME ]; then
              TEST_DOMAIN_NAME=$OWNCLOUD_DOMAIN_NAME
              validate_domain_name
              if [[ $TEST_DOMAIN_NAME != $OWNCLOUD_DOMAIN_NAME ]]; then
                  OWNCLOUD_DOMAIN_NAME=
                  dialog --title "Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
              else
                  if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
                      OWNCLOUD_CODE=$(cat $data | sed -n 2p)
                      if [ ${#OWNCLOUD_CODE} -lt 30 ]; then
                          OWNCLOUD_DOMAIN_NAME=
                          dialog --title "FreeDNS code" --msgbox "$FREEDNS_MESSAGE" 15 50
                      fi
                  fi
              fi
          fi
          if [ $OWNCLOUD_DOMAIN_NAME ]; then
              OWNCLOUD_DETAILS_COMPLETE="yes"
          fi
      done
      save_configuration_file
  fi

  if [[ $SYSTEM_TYPE == "$VARIANT_SOCIAL" || $SYSTEM_TYPE == "$VARIANT_FULL" ]]; then
      REDMATRIX_DETAILS_COMPLETE=
      while [ ! $REDMATRIX_DETAILS_COMPLETE ]
      do
          data=$(tempfile 2>/dev/null)
          trap "rm -f $data" 0 1 2 5 15
          if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
              dialog --backtitle "Freedombone Configuration" \
                     --title "RedMatrix Configuration" \
                     --form "\nPlease enter your RedMatrix details:" 11 55 3 \
                     "Domain:" 1 1 "$(grep 'REDMATRIX_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 25 30 \
                     "Code:" 2 1 "$(grep 'REDMATRIX_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 16 25 30 \
                     2> $data
          else
              dialog --backtitle "Freedombone Configuration" \
                     --title "RedMatrix Configuration" \
                     --form "\nPlease enter your RedMatrix details:" 11 55 3 \
                     "Domain:" 1 1 "$(grep 'REDMATRIX_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 25 30 \
                     2> $data
          fi
          sel=$?
          case $sel in
              1) exit 0;;
              255) exit 0;;
          esac
          REDMATRIX_DOMAIN_NAME=$(cat $data | sed -n 1p)
          if [ $REDMATRIX_DOMAIN_NAME ]; then
              TEST_DOMAIN_NAME=$REDMATRIX_DOMAIN_NAME
              validate_domain_name
              if [[ $TEST_DOMAIN_NAME != $REDMATRIX_DOMAIN_NAME ]]; then
                  REDMATRIX_DOMAIN_NAME=
                  dialog --title "Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
              else
                  if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
                      REDMATRIX_CODE=$(cat $data | sed -n 2p)
                      if [ ${#REDMATRIX_CODE} -lt 30 ]; then
                          REDMATRIX_DOMAIN_NAME=
                          dialog --title "FreeDNS code" --msgbox "$FREEDNS_MESSAGE" 15 50
                      fi
                  fi
              fi
          fi
          if [ $REDMATRIX_DOMAIN_NAME ]; then
              REDMATRIX_DETAILS_COMPLETE="yes"
          fi
      done
      save_configuration_file
  fi

  if [[ $SYSTEM_TYPE == "$VARIANT_SOCIAL" || $SYSTEM_TYPE == "$VARIANT_FULL" ]]; then
      MICROBLOG_DETAILS_COMPLETE=
      while [ ! $MICROBLOG_DETAILS_COMPLETE ]
      do
          data=$(tempfile 2>/dev/null)
          trap "rm -f $data" 0 1 2 5 15
          if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
              dialog --backtitle "Freedombone Configuration" \
                     --title "Microblog Configuration" \
                     --form "\nPlease enter your Microblog details:" 11 55 3 \
                     "Domain:" 1 1 "$(grep 'MICROBLOG_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 25 30 \
                     "Code:" 2 1 "$(grep 'MICROBLOG_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 16 25 30 \
                     2> $data
          else
              dialog --backtitle "Freedombone Configuration" \
                     --title "Microblog Configuration" \
                     --form "\nPlease enter your Microblog details:" 11 55 3 \
                     "Domain:" 1 1 "$(grep 'MICROBLOG_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 25 30 \
                     2> $data
          fi
          sel=$?
          case $sel in
              1) exit 0;;
              255) exit 0;;
          esac
          MICROBLOG_DOMAIN_NAME=$(cat $data | sed -n 1p)
          if [ $MICROBLOG_DOMAIN_NAME ]; then
              if [[ $MICROBLOG_DOMAIN_NAME == "$REDMATRIX_DOMAIN_NAME" ]]; then
                  MICROBLOG_DOMAIN_NAME=""
              fi
              TEST_DOMAIN_NAME=$MICROBLOG_DOMAIN_NAME
              validate_domain_name
              if [[ $TEST_DOMAIN_NAME != $MICROBLOG_DOMAIN_NAME ]]; then
                  MICROBLOG_DOMAIN_NAME=
                  dialog --title "Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
              else
                  if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
                      MICROBLOG_CODE=$(cat $data | sed -n 2p)
                      if [ ${#MICROBLOG_CODE} -lt 30 ]; then
                          MICROBLOG_DOMAIN_NAME=
                          dialog --title "FreeDNS code" --msgbox "$FREEDNS_MESSAGE" 15 50
                      fi
                  fi
              fi
          fi
          if [ $MICROBLOG_DOMAIN_NAME ]; then
              MICROBLOG_DETAILS_COMPLETE="yes"
          fi
      done
      save_configuration_file
  fi

  if [[ $SYSTEM_TYPE == "$VARIANT_DEVELOPER" || $SYSTEM_TYPE == "$VARIANT_FULL" ]]; then
      DEVELOPER_DETAILS_COMPLETE=
      while [ ! $DEVELOPER_DETAILS_COMPLETE ]
      do
          data=$(tempfile 2>/dev/null)
          trap "rm -f $data" 0 1 2 5 15

          if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
              dialog --backtitle "Freedombone Configuration" \
                     --title "Developer Configuration" \
                     --form "\nPlease enter your Git hosting site details.\nIf You don't need developer tools then just select Ok" 11 55 3 \
                     "Domain:" 1 1 "$(grep 'GIT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 25 40 \
                     "Code:" 2 1 "$(grep 'GIT_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 16 25 40 \
                     2> $data
          else
              dialog --backtitle "Freedombone Configuration" \
                     --title "Developer Configuration" \
                     --form "\nPlease enter your Git hosting site details.\nIf You don't need developer tools then just select Ok" 11 55 2 \
                     "Domain:" 1 1 "$(grep 'GIT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 25 40 \
                     2> $data
          fi
          sel=$?
          case $sel in
              1) exit 0;;
              255) exit 0;;
          esac
          GIT_DOMAIN_NAME=$(cat $data | sed -n 1p)
          if [ $GIT_DOMAIN_NAME ]; then
              TEST_DOMAIN_NAME=$GIT_DOMAIN_NAME
              validate_domain_name
              if [[ $TEST_DOMAIN_NAME != $GIT_DOMAIN_NAME ]]; then
                  GIT_DOMAIN_NAME=
                  dialog --title "Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
              else
                  if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
                      GIT_CODE=$(cat $data | sed -n 2p)
                      if [ ${#GIT_CODE} -lt 30 ]; then
                          GIT_DOMAIN_NAME=
                          dialog --title "FreeDNS code" --msgbox "$FREEDNS_MESSAGE" 15 50
                      fi
                  fi
              fi
          else
              DEVELOPER_DETAILS_COMPLETE="yes"
          fi
          if [ $GIT_DOMAIN_NAME ]; then
              DEVELOPER_DETAILS_COMPLETE="yes"
          fi
      done
      save_configuration_file
  fi

  DEFAULT_DOMAIN_DETAILS_COMPLETE=
  while [ ! $DEFAULT_DOMAIN_DETAILS_COMPLETE ]
  do
      data=$(tempfile 2>/dev/null)
      trap "rm -f $data" 0 1 2 5 15
      if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
          dialog --backtitle "Freedombone Configuration" \
                 --title "Default Domain" \
                 --form "\nWhich domain name should your email/XMPP/IRC/VoIP be associated with?" 11 55 3 \
                 "Domain:" 1 1 "$(grep 'DEFAULT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 16 25 30 \
                 "Code:" 2 1 "$(grep 'DEFAULT_DOMAIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 16 25 30 \
                 2> $data
          sel=$?
          case $sel in
              1) exit 0;;
              255) exit 0;;
          esac
          DEFAULT_DOMAIN_NAME=$(cat $data | sed -n 1p)
          DEFAULT_DOMAIN_CODE=$(cat $data | sed -n 2p)
          if [ $DEFAULT_DOMAIN_NAME ]; then
              if [ ${#DEFAULT_DOMAIN_CODE} -lt 30 ]; then
                  DEFAULT_DOMAIN_NAME=
                  dialog --title "FreeDNS code" --msgbox "$FREEDNS_MESSAGE" 15 50
              fi
          fi
      else
          dialog --backtitle "Freedombone Configuration" \
              --inputbox "Which domain name should your email/XMPP/IRC/VoIP be associated with?" 10 45 \
              "$(grep 'DEFAULT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 2> $data
          sel=$?
          case $sel in
              0) DEFAULT_DOMAIN_NAME=$(cat $data);;
              1) exit 0;;
              255) exit 0;;
          esac
      fi
      if [ $DEFAULT_DOMAIN_NAME ]; then
          TEST_DOMAIN_NAME=$DEFAULT_DOMAIN_NAME
          validate_domain_name
          if [[ $TEST_DOMAIN_NAME != $DEFAULT_DOMAIN_NAME ]]; then
              DEFAULT_DOMAIN_NAME=
              dialog --title "Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
          else
              DEFAULT_DOMAIN_DETAILS_COMPLETE="yes"
          fi
      fi
  done
  save_configuration_file

  while [ ${#MY_EMAIL_ADDRESS} -lt 5 ]
  do
      EMAIL_ADDRESS=$(grep 'MY_EMAIL_ADDRESS' temp.cfg | awk -F '=' '{print $2}')
      if [ ! $EMAIL_ADDRESS ]; then
          EMAIL_ADDRESS=$MY_USERNAME@$DEFAULT_DOMAIN_NAME
      fi
      if [ ${#MY_EMAIL_ADDRESS} -lt 5 ]; then
          EMAIL_ADDRESS=$MY_USERNAME@$DEFAULT_DOMAIN_NAME
      fi

      data=$(tempfile 2>/dev/null)
      trap "rm -f $data" 0 1 2 5 15
      dialog --backtitle "Freedombone Configuration" \
          --inputbox "Your email address" 10 30 "$EMAIL_ADDRESS" 2> $data
      sel=$?
      case $sel in
          0) MY_EMAIL_ADDRESS=$(cat $data);;
          1) exit 0;;
          255) exit 0;;
      esac
  done

  save_configuration_file

  # delete the temporary configuration file
  if [ -f temp.cfg ]; then
      shred -zu temp.cfg
  fi
}

function show_result {
  clear
  echo ''
  echo "Configuration filename: $CONFIGURATION_FILE"
  echo ''
  echo 'Contents:'
  echo ''
  cat $CONFIGURATION_FILE
  echo ''
}

function read_configuration {
  if [ ! $CONFIGURATION_FILE ]; then
      CONFIGURATION_FILE='freedombone.cfg'
  fi

  if [ -f $CONFIGURATION_FILE ]; then
      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 "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 "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_CJDNS" $CONFIGURATION_FILE; then
          ENABLE_CJDNS=$(grep "ENABLE_CJDNS" $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 "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 "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 "REDMATRIX_DOMAIN_NAME" $CONFIGURATION_FILE; then
          REDMATRIX_DOMAIN_NAME=$(grep "REDMATRIX_DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
      fi
      if grep -q "REDMATRIX_CODE" $CONFIGURATION_FILE; then
          REDMATRIX_CODE=$(grep "REDMATRIX_CODE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
      fi
      if grep -q "OWNCLOUD_DOMAIN_NAME" $CONFIGURATION_FILE; then
          OWNCLOUD_DOMAIN_NAME=$(grep "OWNCLOUD_DOMAIN_NAME" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
      fi
      if grep -q "OWNCLOUD_CODE" $CONFIGURATION_FILE; then
          OWNCLOUD_CODE=$(grep "OWNCLOUD_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
  fi
}

read_configuration
interactive_configuration
show_result
exit 0
