#!/bin/bash
# Pruefen ob der Benutzer root ist
if ! [ $( id -u ) = 0 ]; then
    echo -e -n "${HELLROT}Bitte fuehren Sie dieses Script als root im root-Verzeichniss aus! ${NC}" 1>&2
    echo
    exit 1
fi
#
# Farbdefinitionen zur Ausgabe #
ROT='\033[0;31m' 
HELLROT='\033[1;31m'
GRUEN='\033[0;32m'
HELLGRUEN='\033[1;32m'
GELB='\033[1;33m'
BLAU='\033[0;34m'
HELLBLAU='\033[1;34m'
LILA='\033[0;35m'
HELLLILA='\033[1;35m'
DUNKELESTUERKIS='\033[0;36m'
TUERKIS='\033[1;36m'
HELLGRAU='\033[0;37m'
WEISS='\033[1;37m'
NC='\033[0m' # No Color
#
#
##################### DATEN - INSTALLATION ######################################
PHPVERSION=""
APACHEPORT=7443
#################################################################################
#
#
### Apache2 und PHP installation
apt update && apt upgrade -y
dpkg-reconfigure tzdata
dpkg-reconfigure locales
apt install -y curl sudo zip unzip git dnsutils nmap net-tools nano mc ssh ca-certificates gnupg2 lsb-release apt-transport-https gpg libsqlite3-dev sqlite3 
apt install -y apache2 php php-sqlite3
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/zip/php.zip
unzip php.zip
echo
read -p  "Hier für (Debian12 bookworm)  8.2 eintragen oder für (Debian13 trixie) 8.4 eintragen: " PHPVERSION
echo
mv php.ini /etc/php/${PHPVERSION}/apache2
a2enmod ssl
a2ensite default-ssl.conf
usermod -aG sudo www-data
rm /root/.bashrc
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/bash/.bashrc
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/schuljahr-erhoehung/crontab
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/schuljahr-erhoehung/update.sh
mkdir -p /var/log/cron
mv update.sh /usr/local/sbin/update.sh
chmod -R 744 /usr/local/sbin/update.sh
mv crontab /etc/crontab
clear
echo
echo -e -n "${TUERKIS}OpenSSH wird fuer die root Benutzung konfiguriert. ${NC}"
echo
sleep 3
#
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/zip/ssh.zip
unzip ssh.zip
mv sshd_config /etc/ssh
systemctl restart ssh
systemctl status ssh --no-pager
#
echo
echo -e -n "${HELLGRUEN}OK ${NC}"
echo
sleep 3
#
##sed -i "s|;extension=pdo_sqlite.*$|extension=pdo_sqlite|" /etc/php/${PHPVERSION}/apache2/php.ini
sed -i 's/443/'$APACHEPORT'/g' /etc/apache2/sites-available/000-default.conf
sed -i 's/443/'$APACHEPORT'/g' /etc/apache2/sites-available/default-ssl.conf
sed -i 's/443/'$APACHEPORT'/g' /etc/apache2/ports.conf
#
systemctl reload apache2.service 
systemctl status apache2.service --no-pager
#
cd /var/www/html
rm index.html
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/zip/Schuljahr-Erhoehung-Apache.zip
unzip Schuljahr-Erhoehung-Apache.zip
chmod -R 777 /var/www/html/
chown -R www-data:www-data /var/www/html/
rm Schuljahr-Erhoehung-Apache.zip
clear
ip a
echo
echo -e -n "${TUERKIS}Das Webprojekt ist unter https://IP-Adresse:7443 zu erreichen. ${NC}"
echo
sleep 5
reboot