#/!/bin/bash
##################################
# Installation eine SVWS-Servers #
# mit Apache2                    #
# und Samba mit Schild3          #
# Erstellt am 6.8.2024 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
#
echo
echo -e -n "${TUERKIS}Update und Upgrade des Debian ${NC}"
echo
sleep 1
apt-get update && apt upgrade -y
echo
echo -e -n "${TUERKIS}Autoremove der nicht mehr genutzten Dateien ${NC}"
echo
sleep 1
apt-get autoremove -y
echo
echo -e -n "${TUERKIS}Deutsches Tastaurlayout installiern ${NC}"
echo
sleep 1
apt install task-german -y
dpkg-reconfigure locales
echo
echo -e -n "${TUERKIS}XFCE4-Desktop installieren ${NC}"
echo
sleep 1
apt install xfce4 xfce4-goodies xorg dbus-x11 x11-xserver-utils net-tools ssh mc gnupg2 curl git unzip mc samba zip -y
wget http://web.webolch.de/bauanleitung/downloads/linux/zip/ssh.zip
unzip ssh.zip
mv sshd_config /etc/ssh
wget http://web.webolch.de/bauanleitung/downloads/linux/zip/docker.zip
unzip docker.zip
systemctl restart ssh
systemctl status ssh --no-pager
echo
echo -e -n "${TUERKIS}Remotedesktop installieren ${NC}"
echo
sleep 1
apt install xrdp -y
adduser xrdp ssl-cert
systemctl restart xrdp
echo
echo -e -n "${TUERKIS}Firefox installieren ${NC}"
echo
sleep 1
wget -q https://packages.mozilla.org/apt/repo-signing-key.gpg -O- | tee /etc/apt/keyrings/packages.mozilla.org.asc > /dev/null
gpg -n -q --import --import-options import-show /etc/apt/keyrings/packages.mozilla.org.asc | awk '/pub/{getline; gsub(/^ +| +$/,""); if($0 == "35BAA0B33E9EB396F59CA838C0BA5CE6DC6315A3") print "\nThe key fingerprint matches ("$0").\n"; else print "\nVerification failed: the fingerprint ("$0") does not match the expected one.\n"}'
echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" | tee -a /etc/apt/sources.list.d/mozilla.list > /dev/null
apt update && apt install firefox -y
apt install firefox-l10n-de -y
##
## [Installation Schild3]
##
# Samba einrichten
echo
echo -e -n "${TUERKIS}Installation des SAMBA-SERVERS und erstellen von SchILD3 ${NC}"
echo
sleep 2
mkdir /netzlaufwerk/
mkdir /netzlaufwerk/Schild_3
mkdir /netzlaufwerk/Schild_3_Arbeitsverzeichnis
mkdir /netzlaufwerk/Schild_3/Connection-Files
mkdir /netzlaufwerk/installationfiles
mkdir /netzlaufwerk/Programme
wget https://github.com/SVWS-NRW/Schild3-BetaTest/releases/download/v3.0.91/Setup_SchILD3_v3.0.91.zip
mv /root/Setup_SchILD3_v3.0.91.zip /netzlaufwerk/installationfiles/
#mv Schild-Reports.zip /netzlaufwerk/installationfiles
unzip /netzlaufwerk/installationfiles/Setup_SchILD3_v3.0.91.zip -d /netzlaufwerk/Schild_3/
git clone https://github.com/SVWS-NRW/SVWS-TestMDBs /netzlaufwerk/installationfiles/SVWS-TestMDBs/
tee -a /etc/samba/smb.conf <<EOF

[netzlaufwerk]
path = /netzlaufwerk
public = yes
writable = yes
comment = SVWS Freigabe
printable = no
guest ok = yes
EOF
#
cp /netzlaufwerk/Schild_3/Connection-Files/server.con.example /netzlaufwerk/Schild_3/Connection-Files/svwsdb.con
systemctl restart smbd.service
echo
echo -e "${TUERKIS} Ausgabe des Status des Samba-Servers !?!${NC}"
echo
systemctl status smbd.service --no-pager
wget http://web.webolch.de/bauanleitung/downloads/linux/zip/Admin.zip
unzip Admin.zip
mv Admin /netzlaufwerk/Programme
wget http://web.webolch.de/bauanleitung/downloads/windows/exe/ChromeStandaloneSetup64.exe
mv ChromeStandaloneSetup64.exe /netzlaufwerk/installationfiles
wget http://web.webolch.de/bauanleitung/downloads/windows/exe/italc-2.0.2-win64-setup.exe
mv italc-2.0.2-win64-setup.exe /netzlaufwerk/installationfiles
wget http://web.webolch.de/bauanleitung/downloads/windows/exe/AcroRdrDC1500920069_de_DE.exe
mv AcroRdrDC1500920069_de_DE.exe /netzlaufwerk/installationfiles
chmod -R 777 /netzlaufwerk/
#
echo
echo -e -n "${TUERKIS}Installation der DOCKER Pakete ${GELB}docker-ce docker-ce-cli containerd.io ${NC}"
echo
sleep 1
apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian bookworm stable"
apt update && apt install docker-ce docker-ce-cli containerd.io -y
systemctl status docker --no-pager
#
echo
echo -e -n "${TUERKIS}Installation des DOCKER Portainer ${GELB}docker volume create portainer_data ${NC}"
echo
sleep 1
docker volume create portainer_data
docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
#
echo
echo -e -n "${TUERKIS}Installation des SVWS-Servers ${GELB}docker compose up -d ${NC}"
echo
sleep 1
#
cd nrw
docker compose up -d
# 
echo
echo -e -n "${TUERKIS}Installation von DOCKER mit einem SVWS-Server Containers ist abgeschlossen!!!!! ${NC}"
echo
