#!/bin/bash
###============================================================
##      Ubuntu 18.04 Additional Domain Installer
###============================================================
## Zet comments hieronder:
#
#
#
##=============================================================

##----------##
#    Menu    #
##----------##

echo "Ubuntu 18.04 extra domein installatie script."
echo "Domein zonder www:"
read domain
while true; do
    read -p "bestaat www.${domain} in DNS -> yes/no?" yn
    case $yn in
        [Yy]* ) domainwww=1
        break;;
        [Nn]* ) domainwww=0
        break;;
        * ) echo "Kies yes of no.";;
    esac
done
echo "Algemeen wachtwoord:"
read password
echo "Administrator email:"
read email
echo "Webserver:"
PS3='Keuze:'
options=("Apache" "Nginx proxy" "Nginx proxy & standalone" "Nginx, PHP-FPM" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "Apache")
            script=https://git.ictmaatwerk.com/VPS-scripts/Ubuntu-Web/raw/branch/master/Extra_Domains/Apache_Domain.sh
            break;;
        "Nginx proxy")
            script=https://git.ictmaatwerk.com/VPS-scripts/Ubuntu-Web/raw/branch/master/Extra_Domains/RevProxySimple_Domain.sh
            break;;
        "Nginx proxy & standalone")
            script=https://git.ictmaatwerk.com/VPS-scripts/Ubuntu-Web/raw/branch/mastermaster/Extra_Domains/RevProxyAdvanced_Domain.sh
            break;;
        "Nginx, PHP-FPM")
            script=https://git.ictmaatwerk.com/VPS-scripts/Ubuntu-Web/raw/branch/master/Extra_Domains/NGINX_Domain.sh
            break;;
        "Quit")
            exit;;
        *) echo "Fout commando $REPLY";;
    esac
done

while true; do
    read -p "Installeer Netdata -> yes/no?" yn
    case $yn in
        [Yy]* ) netdata=1
        break;;
        [Nn]* ) netdata=0
        break;;
        * ) echo "Kies yes of no.";;
    esac
done

while true; do
    read -p "Installeer Wordpress -> yes/no?" yn
    case $yn in
        [Yy]* ) wordpress=1
        break;;
        [Nn]* ) wordpress=0
        break;;
        * ) echo "Kies yes of no.";;
    esac
done

##----------------##
#    Pre-Config    #
##----------------##

cd /tmp
# Make sure all repositories and packages are up-to-date
apt update
apt upgrade -y
apt dist-upgrade -y
apt clean
apt autoremove -y
# Setup domain folder
mkdir -p /var/www/"$domain"/html
chmod -R 755 /var/www

##-------------------##
#    Install Phase    #
##-------------------##

echo "****************************"
sleep 0.5
echo "Installatie duurt 1 minuut."
sleep 0.5
echo "****************************"

wget $script -O Ubuntu-Domain_Installer.sh
source Ubuntu-Domain_Installer.sh

echo "Installatie geslaagd!"