#!/bin/bash
### MODUL-NR. 017 ###
# (c) August 2008 Stefan Schäfer / FSP Computer & Netzwerke
# (c) 2009-2026 Stefan Schäfer / invis-server.org / stefan@invis-server.org
# (c) 2013,2014 Dimitri Asarowski / invis-server.org / dimitri@invis-server.org
# (c) 2013-2017 Ingo Göppert / invis-server.org / ingo@invis-server.org

# License: GPLv3
# Questions: info@invis-server.org

# Groupware Installation

# Groupware Setup

# Dieses Programm ist freie Software. Sie können es unter den Bedingungen der 
# GNU General Public License, wie von der Free Software Foundation veröffentlicht,
# weitergeben und/oder modifizieren, entweder gemäß Version 3 der Lizenz oder
# (nach Ihrer Option) jeder späteren Version.

# Die Veröffentlichung dieses Programms erfolgt in der Hoffnung, daß es Ihnen
# von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne die implizite 
# Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. 
# Details finden Sie in der GNU General Public License.

# Sie sollten ein Exemplar der GNU General Public License zusammen mit diesem 
# Programm erhalten haben. Falls nicht, siehe <http://www.gnu.org/licenses/>. 

# 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/>.

# include functions
source $SINEINCLUDEDIR/functions

modulename=`basename $0`

clear
windowtitle="Groupware Setup"
pgsubtitle="Roundcube - Grommunio"

whichgroupware=`getconfdata "Groupware" "2"`

case "$whichgroupware" in

    "grommunio" )
	windowtitle="grommunio Installation"
	dialog --backtitle "$DIALOGTITLE - Modul: $modulename" --title "$windowtitle" --exit-label "Weiter" --textbox "$INFODIR/grommunio.txt" 38 90 --and-widget --backtitle "$DIALOGTITLE" --title "$windowtitle"  --defaultno --yesno "Möchten Sie Grommunio installieren?" 0 0
	cont=${?}

	if [[ $cont == "0" ]]; then
	    pgsubtitle="Zusätzliche Software wird installiert"
	    zypper refresh 2>&1 | tee -a $LOGFILE | pgbox
	    zyppercheck ${PIPESTATUS[0]}

	else
	    msgbox "grommunio Installation übersprungenen." "$windowtitle"
	fi
	;; 
    "roundcube" )
	windowtitle="Roundcube Installation"
	dialog --backtitle "$DIALOGTITLE - Modul: $modulename" --title "$windowtitle" --exit-label "Weiter" --textbox "$INFODIR/roundcube.txt" 38 90
	zypper refresh 2>&1 | tee -a $LOGFILE | pgbox
	commonrepo=`zypper repos |grep common|tr -d " "|cut -d '|' -f1`
	zypper -n install --from $commonrepo -n roundcubemail 2>&1 | tee -a $LOGFILE | pgbox
	zyppercheck ${PIPESTATUS[0]}
	
	# Datenbank anlegen
	rcmdbpass=`mkdbsilent roundcubemail roundcube a`
	echo "DB-User roundcube:RCDBPW:$rcmdpass" >> $SINEWORKINGDIR/invis_pws 
	mariadb -u roundcube --password=$rcmdbpass roundcubemail < /usr/share/doc/packages/roundcubemail/SQL/mysql.initial.sql

	# Konfigurationsdateien kopieren und anpassen
	path="/etc/roundcubemail/"
	cp $TEMPLATEDIR/$modulename/roundcube/*.php $path
	file="config.inc.php"
	string="roundcube:pass%roundcube:$rcmdbpass"
	changevalues $path $file "$string"

	domain=`getconfdata "Domain" "2"`
	file="defaults.inc.php"
	string="invis-net.loc%$domain"
	changevalues $path $file "$string"

	# Roundcube im Portal aktivieren
	swpestat Roundcube TRUE 2>&1 | tee -a $LOGFILE | pgbox

	;;
esac
