#/!/bin/bash
##################################
# Installation mit Apache2 php   #
# Shellinabox und Samba          #
# und Samba mit Schematas        #
# Erstellt am 24.05.2025 von TR  #
##################################
### Farbdefinitionen ####
#   TEXT in Weiss       #
#   DATEIEN in Gelb     #
#   ORDNER in HellBlau  #
#########################
# 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
# Variabelen Festlegen
Pfad="root"
BezReg="Arnsberg"
IPADDRESSE=""
SCHILD_VERSIONSNR=""
# Pruefen on der Benutzer root oder sudo 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
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/bash/.bashrc
cp .bashrc.1 .bashrc
#
echo
echo -e -n "${TUERKIS}Update und Upgrade des Debian ${NC}"
echo
sleep 1
apt-get update && apt upgrade -y && apt install net-tools ssh gnupg2 curl git unzip mc zip samba shellinabox apache2 php sudo htop libsqlite3-dev sqlite3 php-sqlite3 -y
a2ensite default-ssl.conf
a2enmod ssl
systemctl restart apache2
systemctl status apache2 --no-pager
echo
echo -e -n "${TUERKIS}Autoremove der nicht mehr genutzten Dateien ${NC}"
echo
sleep 1
apt-get autoremove -y
echo
echo -e -n "${TUERKIS}Einstellen der Zeitzone Europa/Berlin und des Deutschen Tastaurlayout. ${NC}"
echo
sleep 1
##############################
###apt install task-german -y#
##############################
dpkg-reconfigure tzdata
dpkg-reconfigure locales
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
## php.ini POST download limit auf 3800MB erhöhen
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/zip/php.zip
unzip php.zip
mv php.ini /etc/php/8.2/apache2
systemctl restart apache2
systemctl status apache2 --no-pager
#
#Automatisches Update
wget -q --show-progress https://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/update.sh
wget -q --show-progress https://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/crontab
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
#
# DockerWebseiten
mkdir /var/www/.docker
chmod -R 777 /var/www/.docker
chown -R www-data:www-data /var/www/.docker
cd /var/www/html
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/zip/DockerWebseiten.zip
rm index.html
unzip DockerWebseiten.zip
##chmod -R 744 /var/www/html/
chown -R www-data:www-data /var/www/html/
rm DockerWebseiten.zip
###################################################################################################
##chmod -R 744 /var/www/html/
chown -R www-data:www-data /var/www/html/
#################################
### Die IP des LXCs eingeben  ###
#################################
echo
read -p  "Hier die IP-Addresse des LXCs z.B. 10.1.0.3 eintragen: " IPADDRESSE
echo
##########################################################################
######## geaendert am 05-08-2025                                       ###
sed -i 's/00001/'$IPADDRESSE'/g' inc/conf/config.inc.php               ###
################### REM REM REM REM REM ##################################
##########################################################################
## sed -i 's/LOCALEIP/'$IPADDRESSE'/g' index.php                       ###
## sed -i 's/LOCALEIP/'$IPADDRESSE'/g' container_update.php            ###
## sed -i 's/LOCALEIP/'$IPADDRESSE'/g' schemata.php                    ###
## sed -i 's/LOCALEIP/'$IPADDRESSE'/g' schild3.php                     ###
## sed -i 's/LOCALEIP/'$IPADDRESSE'/g' container-status.php            ###
## sed -i 's/LOCALEIP/'$IPADDRESSE'/g' inc/footer/footer.php           ###
## sed -i 's/LOCALEIP/'$IPADDRESSE'/g' admin/alleSchemata.php          ###
## sed -i 's/LOCALEIP/'$IPADDRESSE'/g' admin/Lehrer.php                ###
## sed -i 's/LOCALEIP/'$IPADDRESSE'/g' admin/Schemata.php              ###
## sed -i 's/LOCALEIP/'$IPADDRESSE'/g' admin/Schueler.php              ###
## sed -i 's/LOCALEIP/'$IPADDRESSE'/g' admin/Schuljahresabschnitte.php ###
################### REM REM REM REM REM ##################################
##########################################################################
cd /root
# Samba einrichten
echo
echo -e -n "${TUERKIS}Installation des SAMBA-SERVERS erstellen ${NC}"
echo
echo
read -p  "Hier die SCHILD_VERSIONSNR z.B. 3.1.15 eintragen: " SCHILD_VERSIONSNR
echo
sleep 2
mkdir /netzlaufwerk/
mkdir /netzlaufwerk/SchILD3
###mkdir /netzlaufwerk/SchILD2
mkdir /netzlaufwerk/SVWS-Arbeitsverzeichnisse
mkdir /netzlaufwerk/installationfiles
###############################################################################################################################
## BasisReports aus git-Quelle in /netlaufwerk Laden                                                                       ####
cd /netzlaufwerk                                                                                                           ####
git clone https://github.com/SVWS-NRW/Schild-NRW-Reports.git                                                               ####
git clone https://github.com/SVWS-NRW/SVWS-TestMDBs.git                                                                    ####
###############################################################################################################################
cd /root
wget -q --show-progress https://github.com/SVWS-NRW/Schild3-BetaTest/releases/download/v$SCHILD_VERSIONSNR/Setup_SchILD3_v$SCHILD_VERSIONSNR.zip
###wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/zip/SchILD2.zip
###mv /root/SchILD2.zip /netzlaufwerk/installationfiles/
mv /root/Setup_SchILD3_v$SCHILD_VERSIONSNR.zip /netzlaufwerk/installationfiles/
mv Schild-Reports.zip /netzlaufwerk/installationfiles
###unzip /netzlaufwerk/installationfiles/SchILD2.zip -d /netzlaufwerk/SchILD2/
unzip /netzlaufwerk/installationfiles/Setup_SchILD3_v$SCHILD_VERSIONSNR.zip -d /netzlaufwerk/SchILD3/
cd /netzlaufwerk/SchILD3
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/zip/Admin.ini
#
cd /$Pfad
#
tee -a /etc/samba/smb.conf <<EOF

[netzlaufwerk]
path = /netzlaufwerk
public = yes
writable = yes
comment = SVWS Freigabe
printable = no
guest ok = yes
EOF
#
systemctl restart smbd.service
echo
echo -e -n "${TUERKIS} Ausgabe des Samba-Server Status  ${NC}"
echo
systemctl status smbd.service --no-pager
# Samba-User für Windows Freigabe anlegen
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/smbuser.sh
bash smbuser.sh
echo
chmod -R 777 /netzlaufwerk/
chown -R www-data:www-data /netzlaufwerk/
ln -s /netzlaufwerk /var/www/html/netzlaufwerk
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/docker-container-schulungen.sh
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/docker-schemata-update.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/docker-schemata.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/Gesamtschule.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/Grundschule.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/Gymnasium_2HJ.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/Gymnasium_FaecherSek2.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/Gymnasium_LaufbahnenJG10.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/Gymnasium_LaufbahnenJGEF.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/Gymnasium_LaufbahnenJGEFMitBlockung.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/Gymnasium_LaufbahnenJGEFvollst.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/S1-Schulung.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/S2-Schulung.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/schema_menu.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/container-update_menu.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/wenom-und-laufbahn-update.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/connection-files.sh
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/Status-Anzeige-Install.sh
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/Erste-Letzte-Zeile.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/wenomsslIP.sh
#wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/SH-Scripte/docker-container-svws-1.0.7/wenomsslDNS.sh
#
echo
echo -e -n "${TUERKIS}Installation von DOCKER ${NC}"
echo
sleep 1
curl -fsSL https://get.docker.com -o get-docker.sh
bash get-docker.sh
wget -q --show-progress http://web.webolch.de/bauanleitung/downloads/linux/zip/daemon.zip
unzip daemon.zip
mv daemon.json /etc/docker 
systemctl status docker --no-pager
usermod -aG sudo www-data
usermod -aG docker www-data
#
echo
echo -e -n "${TUERKIS}Installation der Docker-STACKs ${NC}"
echo
sleep 2
bash docker-container-schulungen.sh

