roundcube/install_roundcube.sh

3031 lines
89 KiB
Bash
Executable File

#!/usr/bin/env bash
clear
echo -e "\n\t\033[32mStart script for installation Roundcube Webmailer..\033[m"
## -----------------------------------------------------------------
## ----------------------------------------------------------------
## ---
## --- For configurations see file conf/install_upgrade_roundcube.conf
## ---
## --- Dont make changes here!
## ---
## -----------------------------------------------------------------
## -----------------------------------------------------------------
# -------------
# - Settings
# -------------
_src_base_dir="$(realpath $(dirname $0))"
#_src_base_dir=/usr/local/src/postfixadmin
conf_file="${_src_base_dir}/conf/install_upgrade_roundcube.conf"
curdir=`pwd`
log_file="$(mktemp)"
tmp_dir="$(mktemp -d)"
backup_date="$(date +%Y-%m-%d-%H%M)"
# -------------
# - Functions
# -------------
clean_up() {
# Perform program exit housekeeping
rm -f "$log_file"
rm -rf "$tmp_dir"
exit $1
}
echononl(){
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo "$*\\c" 1>&2
else
echo -e -n "$*" 1>&2
fi
rm /tmp/shprompt$$
}
fatal(){
echo ""
echo -e "\t[ \033[31m\033[1mFatal\033[m ]: $*"
echo ""
echo -e "\t\033[31m\033[1mInstalllation wird abgebrochen\033[m"
echo ""
clean_up 1
}
error(){
echo ""
echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*"
echo ""
}
warn (){
echo ""
echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*"
echo ""
}
info (){
echo ""
echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*"
echo ""
}
echo_ok() {
echo -e "\033[75G[ \033[32mok\033[m ]"
}
echo_failed(){
echo -e "\033[75G[ \033[1;31mfailed\033[m ]"
}
echo_skipped() {
echo -e "\033[75G[ \033[30m\033[1mskipped\033[m ]"
}
trap clean_up SIGHUP SIGINT SIGTERM
if [ "$DB_TYPE" = "postgres" -o "$DB_TYPE" = "postgresql" -o "$DB_TYPE" = "pgsql" -o "$DB_TYPE" = "psql" ];then
DB_TYPE=pgsql
fi
echo
echononl "\tInclude Configuration file.."
if [[ ! -f $conf_file ]]; then
echo_failed
fatal "Missing configuration file '$conf_file'"
else
source $conf_file
echo_ok
fi
echo -e "\033[32m--\033[m"
echo ""
echo "Version of the Roundcube Webmailer to install"
echo ""
echo ""
ROUNDCUBE_VERSION=
while [ "X$ROUNDCUBE_VERSION" = "X" ]
do
echononl "Roundcube Version: "
read ROUNDCUBE_VERSION
if [ "X$ROUNDCUBE_VERSION" = "X" ]; then
echo -e "\n\t\033[33m\033[1mA version number is required!\033[m\n"
fi
done
echo ""
echo -e "\033[32m--\033[m"
echo ""
# - Default values
# -
DEFAULT_SPAM_FOLDER_NAME="Spam"
DEFAULT_HTTP_USER="www-data"
DEFAULT_HTTP_GROUP="www-data"
DEFAULT_APACHE_LOG_DIR="/var/log/apache2"
DEFAULT_WEBSITE_BASEDIR="/var/www/${WEBSITE_NAME}"
DEFAULT_ROUNDCUBE_TMPDIR="${DEFAULT_WEBSITE_BASEDIR}/temp"
DEFAULT_DEBIAN_APACHE_CERT_DIR="/etc/apache2"
DEFAULT_APACHE_CERT_DIR="/usr/local/apache2/conf"
DEFAULT_APACHE_SERVER_CERT="server-bundle.crt"
DEFAULT_APACHE_SERVER_KEY="server.key"
DEFAULT_DEBIAN_APACHE_VHOST_DIR="/etc/apache2/sites-available"
DEFAULT_APACHE_VHOST_DIR="/usr/local/apache2/conf/vhosts"
DEFAULT_DB_HOST="localhost"
DEFAULT_DB_NAME="roundcubemail"
DEFAULT_DB_USER="roundcube"
DEFAULT_DEBIAN_MYSQL_CREDENTIALS="/etc/mysql/debian.cnf"
DEFAULT_MYSQL_CREDENTIALS="/usr/local/mysql/sys-maint.cnf"
[[ -n "$ROUNDCUBE_VERSION" ]] || fatal "Roundcube Version (ROUNDCUBE_VERSION) not present!"
[[ -n "$WEBSITE_NAME" ]] || fatal "Website's name (WEBSITE_NAME) not present!"
TLD=${WEBSITE_NAME##*.}
_tmp_string=${WEBSITE_NAME%.*}
MAIN_DOMAIN=${_tmp_string##*.}
[[ -n "$WEBMASTER_EMAIL" ]] || WEBMASTER_EMAIL="admin@${MAIN_DOMAIN}.$TLD"
[[ -n "$ROUNDCUBE_TMPDIR" ]] || ROUNDCUBE_TMPDIR="$DEFAULT_ROUNDCUBE_TMPDIR"
[[ -n "$IPV4" ]] || fatal "IPv4 Address (IPV4) not present!"
[[ -n "$IPV6" ]] || fatal "IPv4 Address (IPV6) not present!"
[[ -n "$APACHE_DEBIAN_INSTALLATION" ]] || APACHE_DEBIAN_INSTALLATION=false
httpd_binary="`which httpd`"
if [ -z "$httpd_binary" ]; then
httpd_binary="$(ps -axu | grep httpd | grep -e "^root" | grep -v grep | awk '{print$11}')"
if [ -z "$httpd_binary" ]; then
if [ -x "/usr/local/apache2/bin/httpd" ]; then
httpd_binary="/usr/local/apache2/bin/httpd"
fi
fi
fi
if [ -x "$httpd_binary" ];then
# - Determin websever user
# -
HTTP_USER="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^User" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
HTTP_GROUP="`$httpd_binary -t -D DUMP_RUN_CFG | grep -i -e "^Group" | awk '{print$2}' | cut -d\"=\" -f2 | tr -d '"'`"
[[ -n "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
# - Is webserver running ?
# -
PID=$(ps aux | grep "$(realpath $httpd_binary)" | grep -e "^root" | grep -v grep | awk '{print$2}')
if [[ "X${PID}X" = "XX" ]] ;then
IS_HTTPD_RUNNING=false
else
IS_HTTPD_RUNNING=true
fi
fi
[[ -n "$WEBMASTER_EMAIL" ]] || fatal "E-Mail (WEBMASTER_EMAIL) for webmaster not present!"
[[ -n "$WEBSITE_BASEDIR" ]] || WEBSITE_BASEDIR=$DEFAULT_WEBSITE_BASEDIR
if [[ -z "$APACHE_CERT_DIR" ]] ; then
if $APACHE_DEBIAN_INSTALLATION ; then
APACHE_CERT_DIR="$DEFAULT_DEBIAN_APACHE_CERT_DIR"
else
APACHE_CERT_DIR="$DEFAULT_APACHE_CERT_DIR"
fi
fi
[[ -n "$APACHE_SERVER_CERT" ]] || APACHE_SERVER_CERT=$DEFAULT_APACHE_SERVER_CERT
[[ -n "$APACHE_SERVER_KEY" ]] || APACHE_SERVER_KEY=$DEFAULT_APACHE_SERVER_KEY
[[ -n "$APACHE_LOG_DIR" ]] || APACHE_LOG_DIR=$DEFAULT_APACHE_LOG_DIR
if [[ -z "$PHP_TYPE" ]]; then
PHP_TYPE="php_fpm"
else
[[ "$PHP_TYPE" = "php_fpm" ]] || [[ "$PHP_TYPE" = "fcgid" ]] || [[ "$PHP_TYPE" = "mod_php" ]] || fatal "Wrong type of PHP (PHP_TYPE) given!"
fi
if [[ -z "$APACHE_VHOST_DIR" ]] ; then
if $APACHE_DEBIAN_INSTALLATION ; then
APACHE_VHOST_DIR="$DEFAULT_DEBIAN_APACHE_VHOST_DIR"
else
APACHE_VHOST_DIR="$DEFAULT_APACHE_VHOST_DIR"
fi
fi
[[ -n "$AUTOREPLY_HOSTNAME" ]] || AUTOREPLY_HOSTNAME=autoreply.${MAIN_DOMAIN}.$TLD
[[ -n "$DB_TYPE" ]] || fatal "Database Type of Roundcube Database (DB_TYPE) not present!"
[[ -n "$DB_HOST" ]] || DB_HOST="$DEFAULT_DB_HOST"
[[ -n "$DB_NAME" ]] || DB_NAME="$DEFAULT_DB_NAME"
[[ -n "$DB_USER" ]] || DB_USER="$DEFAULT_DB_USER"
[[ -n "$DB_PASS" ]] || fatal "Password of Roundcube Database (DB_PASS) not given!"
[[ -n "$MYSQL_DEBIAN_INSTALLATION" ]] || MYSQL_DEBIAN_INSTALLATION=false
if [[ "$DB_TYPE" = "mysql" ]]; then
if $MYSQL_DEBIAN_INSTALLATION ; then
[[ -n "$MYSQL_CREDENTIALS" ]] || MYSQL_CREDENTIALS="$DEFAULT_DEBIAN_MYSQL_CREDENTIALS"
else
[[ -n "$MYSQL_CREDENTIALS" ]] || MYSQL_CREDENTIALS="$DEFAULT_MYSQL_CREDENTIALS"
fi
else
[[ "$DB_TYPE" = "pgsql" ]] || fatal "Unknown Database Type '$DB_TYPE' (DB_TYPE)"
fi
[[ -n "$SPAM_FOLDER_NAME" ]] || SPAM_FOLDER_NAME=$DEFAULT_SPAM_FOLDER_NAME
[[ -n "$SUPPORT_URL" ]] || SUPPORT_URL="http://www.${MAIN_DOMAIN}.$TLD"
SKIN_LOGO_PRESENT=false
if [[ -f "${WEBSITE_BASEDIR}/htdocs/${SKIN_LOGO}" ]]; then
SKIN_LOGO_PRESENT=true
SKIN_LOGO_DIR="$(echo "${SKIN_LOGO%/*}")"
SKIN_LOGO_FILE="$(echo "${SKIN_LOGO##*/}")"
if [[ "$(echo "${SKIN_LOGO%/*}")" = "$SKIN_LOGO" ]] ; then
cp -a "${WEBSITE_BASEDIR}/htdocs/${SKIN_LOGO}" "${tmp_dir}/"
else
cp -a "${WEBSITE_BASEDIR}/htdocs/${SKIN_LOGO_DIR}" "${tmp_dir}/"
fi
fi
# ---
# - Plugins
# --
# - Pligin acl
# -
[[ -n "$INCLUDE_ACL_PLUGIN" ]] || INCLUDE_ACL_PLUGIN=false
# - Plugin passord
# -
[[ -n "$PW_CONFIRM_CURRENT" ]] || PW_CONFIRM_CURRENT=true
[[ -n "$PW_MIN_LENGTH" ]] || PW_MIN_LENGTH=10
[[ -n "$PW_REQUIRE_NONALPHA" ]] || PW_REQUIRE_NONALPHA=true
[[ -n "$PW_PASSWD_ALGO" ]] || PW_PASSWD_ALGO="dovecot"
#[[ -n "$PW_PASSWD_ALGO_PREFIX" ]] || PW_PASSWD_ALGO_PREFIX="{CRAM-MD5}"
[[ -n "$POSTFIX_DB_TYPE" ]] || fatal "Plugin password: Database Type for Password Database (POSTFIX_DB_TYPE) not given!"
if [[ "$POSTFIX_DB_TYPE" != "pgsql" ]] && [[ "$POSTFIX_DB_TYPE" != "mysql" ]]; then
fatal "Unknown Database Type '$POSTFIX_DB_TYPE' for Password Database (POSTFIX_DB_TYPE)"
fi
[[ -n "$POSTFIX_DB_HOST" ]] || POSTFIX_DB_HOST="localhost"
[[ -n "$POSTFIX_DB_NAME" ]] || POSTFIX_DB_NAME="postfix"
[[ -n "$POSTFIX_DB_USER" ]] || POSTFIX_DB_USER="postfix"
[[ -n "$POSTFIX_DB_PASSWD" ]] || fatal "Plugin password: Password for Password Database (POSTFIX_DB_PASSWD) not given!"
[[ -n "$PW_DB_UPDATE_STRING" ]] || fatal "Plugin password: No SQL query for changing password present!"
[[ -n "$PW_DOVEADM_PW" ]] || PW_DOVEADM_PW='/usr/local/dovecot/bin/doveadm pw'
[[ -n "$PW_DOVECOT_PW_METHOD" ]] || PW_DOVECOT_PW_METHOD='CRAM-MD5'
# - Plugin vacation
# -
[[ -n "$VAC_GUI_FORWARDER" ]] || VAC_GUI_FORWARDER=false
# - Determin PHP of all installed versions
# -
echononl "\tGet major version of all installed PHP versions"
php_major_versions=`find /usr/local/ -maxdepth 1 -mindepth 1 -type l -name "php-*" -print | cut -d "-" -f2 | sort`
if [[ -z "$php_major_versions" ]]; then
echo_failed
error "Getting major version of installed PHP versions failed! No installed PHP versiond found!"
else
echo_ok
fi
# - Get the latest PHP version
# -
echononl "\tGet major version of latest installed PHP version"
php_latest_ver=""
if [[ -n "$php_major_versions" ]]; then
for _ver in $php_major_versions ; do
if [[ -z "$php_latest_ver" ]] ; then
php_latest_ver=$_ver
elif [[ "${_ver%.*}" -gt "${php_latest_ver%.*}" ]] ; then
php_latest_ver=$_ver
elif [[ "${_ver%.*}" -eq "${php_latest_ver%.*}" ]] ; then
[[ "${_ver#*.}" -gt "${php_latest_ver#*.}" ]] && php_latest_ver=$_ver
fi
done
echo_ok
else
echo_skipped
warn "Getting major version of latest installed PHP version failed! - No installed PHP versiond found!"
fi
echo ""
echo ""
echo -e "\033[1;32mSettings for installation of \033[1;37mRoundcube Webmail\033[m"
echo ""
echo -e "\tRoundcube Version....................: $ROUNDCUBE_VERSION"
echo ""
echo -e "\tName of the Website..................: $WEBSITE_NAME"
echo ""
echo -e "\tIPv4 Address.........................: $IPV4"
echo -e "\tIPv6 Address.........................: $IPV6"
echo ""
echo -e "\tApache from Debian Package System....: $APACHE_DEBIAN_INSTALLATION"
echo -e "\tApache User..........................: $HTTP_USER"
echo -e "\tApache Group.........................: $HTTP_GROUP"
echo -e "\tApache VHOST Directory...............: $APACHE_VHOST_DIR"
echo -e "\tApache LOG Directory.................: $APACHE_LOG_DIR"
echo ""
echo -e "\tApache Cert directory................: $APACHE_CERT_DIR"
echo -e "\tWebsite Certificate..................: $APACHE_SERVER_CERT"
if [[ -n "$CERT_ChainFile" ]] ; then
echo -e "\tCertificate Chain File...............: $CERT_ChainFile"
fi
echo -e "\tWebsite Key..........................: $APACHE_SERVER_KEY"
echo ""
echo -e "\tWebmasters E-Mail Address............: $WEBMASTER_EMAIL"
echo -e "\tBase Directory of Roundcube Website..: $WEBSITE_BASEDIR"
echo ""
echo -e "\tRoundcube TEMP Directory.............: $ROUNDCUBE_TMPDIR"
echo -e "\tRoundcube LOG Directory..............: ${WEBSITE_BASEDIR}/logs"
echo -e "\tType of PHP connection...............: $PHP_TYPE"
echo ""
echo -e "\tInstalled PHP versions...............: $php_major_versions"
echo -e "\tNewest PHP Version...................: $php_latest_ver"
echo ""
if [[ "$DB_TYPE" = "mysql" ]]; then
echo -e "\tDatabase type of Roundcube Database..: MySQL"
echo -e "\tMySQL from Debian Package System.....: $MYSQL_DEBIAN_INSTALLATION"
else
echo -e "\tDatabase type of Roundcube Database..: PostgreSQL"
fi
echo -e "\tHost of Roundcube Database...........: $DB_HOST"
echo -e "\tName of Roundcube Database...........: $DB_NAME"
echo -e "\tUser of Roundcube Database...........: $DB_USER"
echo -e "\tPassword of Roundcube Database.......: $DB_PASS"
if [[ "$DB_TYPE" = "mysql" ]]; then
echo -e "\tMySQL Credentials (root access)......: $MYSQL_CREDENTIALS"
fi
echo ""
echo -e "\tHostname for Vacation Messages.......: $AUTOREPLY_HOSTNAME"
echo ""
echo -e "\tName of Junk Folder..................: $SPAM_FOLDER_NAME"
echo ""
echo ""
echo -e "\tInclude 'acl' plugin?..................: $INCLUDE_ACL_PLUGIN"
echo ""
echo -n "Type upper case 'YES' to continue executing with this parameters: "
read OK
if [[ "$OK" = "YES" ]] ; then
echo ""
echo ""
echo -e "\t\033[1;32mGoing to install Roundcube Webmailer \033[1;37m$network \033[m"
echo ""
else
fatal "Abort by user request - Answer as not 'YES'"
fi
_log_dir=${_src_base_dir}/log-roundcube-$_version
## ----------------------------
## - Begin Installation
# - REQUIREMENTS
# - ============
# -
# - * An IMAP, HTTP and SMTP server
# - * .htaccess support allowing overrides for DirectoryIndex
# - * PHP Version 5.4 or greater including:
# - - PCRE, DOM, JSON, Session, Sockets, OpenSSL, Mbstring (required)
# - - PHP PDO with driver for either MySQL, PostgreSQL, SQL Server, Oracle or SQLite (required)
# - - Iconv, Zip, Fileinfo, Intl, Exif (recommended)
# - - LDAP for LDAP addressbook support (optional)
# - * PEAR and PEAR packages distributed with Roundcube or external:
# - - Mail_Mime 1.10.0 or newer
# - - Net_SMTP 1.7.1 or newer
# - - Net_Socket 1.0.12 or newer
# - - Net_IDNA2 0.1.1 or newer
# - - Auth_SASL 1.0.6 or newer
# - - Net_Sieve 1.3.2 or newer (for managesieve plugin)
# - - Crypt_GPG 1.6.0 or newer (for enigma plugin)
# - - Endroid/QrCode 1.6.0 or newer (https://github.com/endroid/QrCode)
# - * php.ini options (see .htaccess file):
# - - error_reporting E_ALL & ~E_NOTICE & ~E_STRICT
# - - memory_limit > 16MB (increase as suitable to support large attachments)
# - - file_uploads enabled (for attachment upload features)
# - - session.auto_start disabled
# - - suhosin.session.encrypt disabled
# - - mbstring.func_overload disabled
# - * A MySQL, PostgreSQL, MS SQL Server (2005 or newer), Oracle database
# - or SQLite support in PHP - with permission to create tables
# - * Composer installed either locally or globally (https://getcomposer.org)
needed_php_pear_modules="
MDB2
Mail_Mime
Mail_mimeDecode
Net_SMTP
Net_IDNA2
Auth_SASL"
if [[ "$DB_TYPE" = "pgsql" ]]; then
needed_php_pear_modules="$needed_php_pear_modules MDB2_Driver_pgsql"
else
needed_php_pear_modules="$needed_php_pear_modules MDB2_Driver_mysql MDB2_Driver_mysqli"
fi
## - install php PEAR packages
## -
## - !! Take care to do this for all php installations (PHP 5.5/5.6/..)
## -
for _version in $php_major_versions ; do
echo -e "\n\n\t\033[37m\033[1mInstall modules for PHP Version ${_version}..\033[m\n"
for _module in $needed_php_pear_modules ; do
echononl "\tInstall Module '$_module'.."
if ! /usr/local/php-${_version}/bin/pear list | grep -q "$_module" 2> /dev/null ; then
/usr/local/php-${_version}/bin/pear install $_module > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
if [[ "$_module" = "Net_IDNA2" ]]; then
echononl "\tInstall (beta) Net_IDNA2-0.1.1 .."
/usr/local/php-${_version}/bin/pear install channel://pear.php.net/Net_IDNA2-0.1.1 > $log_file 2>&1
if [ "$?" = "0" ]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
fi
fi
else
echo_skipped
fi
done
done
echo -e "\n\n\t\033[37m\033[1mInstall (global) composer..\033[m\n"
echononl "\tDownload composer from 'getcomposer.org'.."
php -r "copy('https://getcomposer.org/installer', '${_src_base_dir}/composer-setup.php');" > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tInstall composer to /usr/local/bin"
php ${_src_base_dir}/composer-setup.php --install-dir=/usr/local/bin --filename=composer > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echo -e "\n\n\t\033[37m\033[1mCreate some Backups..\033[m\n"
echononl "\tBackup existing source directory 'roundcubemail-${ROUNDCUBE_VERSION}'.."
if [[ -d "${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION}" ]] ;then
mv ${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION} \
${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION}.$backup_date > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tBackup existing web-directory 'roundcubemail-${ROUNDCUBE_VERSION}'.."
if [[ -d "${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" ]]; then
mv ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION} \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}.$backup_date > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echo -e "\n\n\t\033[37m\033[1mBase install Roundcube Webmail..\033[m\n"
# - install roundcube
# -
echononl "\tDownload 'roundcubemail-${ROUNDCUBE_VERSION}'.."
if [[ ! -f "$_src_base_dir/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz" ]]; then
wget -O ${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz https://github.com/roundcube/roundcubemail/releases/download/${ROUNDCUBE_VERSION}/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tUnpack 'roundcubemail-${ROUNDCUBE_VERSION}'.."
gunzip < ${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz | tar -C ${_src_base_dir} -xf - 2> $log_file
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCreate '$WEBSITE_BASEDIR'.."
if [[ ! -d "$WEBSITE_BASEDIR" ]]; then
mkdir $WEBSITE_BASEDIR > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tCopy Roundcube to web-directory"
cp -a ${_src_base_dir}/roundcubemail-${ROUNDCUBE_VERSION} $WEBSITE_BASEDIR/ > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tChange owner/group for Roundcube Webdirectory.."
chown -R ${HTTP_USER}:$HTTP_GROUP $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION} > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tChange into Roundcube Webdirectory.."
cd "${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tRename the composer.json-dist file into composer.json"
cp -a "composer.json-dist" "composer.json" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tInstall composer to ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}"
php ${_src_base_dir}/composer-setup.php --install-dir=${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION} > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tRemove the installer"
php -r "unlink('${_src_base_dir}/composer-setup.php');" > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tInstall PHP dependencies.."
#/usr/local/php-${php_latest_ver}/bin/php /usr/local/bin/composer install --no-dev
su www-data -c"cd ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}
/usr/local/php-${php_latest_ver}/bin/php /usr/local/bin/composer install --no-dev" -s /bin/bash \
> $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tInstall Javascript dependencies.."
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/bin/install-jsdeps.sh > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
# - Install a cronjob for cleaning up database
# -
echononl "\tInstall a cronjob for cleaning up database"
crontab -l > /tmp/tmp_crontab
if ! grep -q -E "${WEBSITE_BASEDIR}/htdocs/bin/cleandb.sh" /tmp/tmp_crontab 2> /dev/null ; then
echo "" >> /tmp/tmp_crontab
echo "# - Keep roundcube database slick and clean" >> /tmp/tmp_crontab
echo "# -" >> /tmp/tmp_crontab
echo "37 3 * * * ${WEBSITE_BASEDIR}/htdocs/bin/cleandb.sh" >> /tmp/tmp_crontab
crontab /tmp/tmp_crontab > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tSet Permissions 'root:root' on \n\t ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}"
chown -R root:root $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION} > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tRemove existing symlink '${WEBSITE_BASEDIR}/htdocs'"
if [[ -h "${WEBSITE_BASEDIR}/htdocs" ]]; then
rm ${WEBSITE_BASEDIR}/htdocs
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tCreate Symlink for DocumentRoot Directory 'htdocs'.."
if [[ ! -h "${WEBSITE_BASEDIR}/htdocs" ]]; then
ln -s roundcubemail-${ROUNDCUBE_VERSION} ${WEBSITE_BASEDIR}/htdocs > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
if $SKIN_LOGO_PRESENT ; then
_failed=false
echononl "\tRestore logo '$SKIN_LOGO_FILE'"
if [[ "$(echo "${SKIN_LOGO%/*}")" = "$SKIN_LOGO" ]] ; then
cp -a "${tmp_dir}/${SKIN_LOGO}" "${WEBSITE_BASEDIR}/htdocs/" >> $log_file 2>&1
else
if [[ ! -d "${WEBSITE_BASEDIR}/htdocs/${SKIN_LOGO_DIR}" ]]; then
cp -a "${tmp_dir}/${SKIN_LOGO_DIR}" "${WEBSITE_BASEDIR}/htdocs/" >> $log_file 2>&1
else
cp -a "$(realpath "${tmp_dir}/${SKIN_LOGO_DIR}/${SKIN_LOGO_FILE}")" \
"${WEBSITE_BASEDIR}/htdocs/${SKIN_LOGO_DIR}/${SKIN_LOGO_FILE}" >> $log_file 2>&1
fi
fi
if [[ $? -ne 0 ]]; then
echo_failed
error $(cat $log_file)
else
echo_ok
fi
fi
echononl "\tCreate Roundcube LOG directory '${WEBSITE_BASEDIR}/logs'"
if [[ ! -d "${WEBSITE_BASEDIR}/logs" ]]; then
mkdir ${WEBSITE_BASEDIR}/logs > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tSet Permissions on Roundcube LOG directory '${WEBSITE_BASEDIR}/logs'.."
chown -R ${HTTP_USER}:$HTTP_GROUP ${WEBSITE_BASEDIR}/logs > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCreate Roundcube TMP directory (ROUNDCUBE_TMPDIR)"
if [[ ! -d "$ROUNDCUBE_TMPDIR" ]]; then
mkdir $ROUNDCUBE_TMPDIR > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tSet Permissions on Roundcube TMP directory '${ROUNDCUBE_TMPDIR}'.."
chown -R ${HTTP_USER}:$HTTP_GROUP $ROUNDCUBE_TMPDIR > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
if [[ "$PHP_TYPE" = "fcgid" ]] ; then
echo -e "\n\n\t\033[37m\033[1mConfiguration for FastCGI PHP Connections (mod_fcgid)..\033[m\n"
elif [[ "$PHP_TYPE" = "php_fpm" ]] ; then
echo -e "\n\n\t\033[37m\033[1mConfiguration for PHP-FPM Connection ..\033[m\n"
elif [[ "$PHP_TYPE" = "mod_php" ]] ; then
echo -e "\n\n\t\033[37m\033[1mConfiguration for PHP Connection using Apache's mod_php..\033[m\n"
else
fatal "Wrong PHP Type '$PHP_TYPE' (PHP_TYPE)!"
fi
echononl "\tCreate Log Directory '$APACHE_LOG_DIR'.."
if [[ ! -d "$APACHE_LOG_DIR" ]]; then
mkdir $APACHE_LOG_DIR > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
if [[ "$PHP_TYPE" = "fcgid" ]] ; then
_dirs="${WEBSITE_BASEDIR}/sessions ${WEBSITE_BASEDIR}/tmp ${WEBSITE_BASEDIR}/logs"
for _dir in $_dirs ; do
echononl "\tCreate Directory '$_dir'"
if [[ ! -d "$_dir" ]]; then
mkdir $_dir > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tSet Permissons on '$_dir'.."
chown ${HTTP_USER}:${HTTP_GROUP} $_dir > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
done
echononl "\tCreate directory '${WEBSITE_BASEDIR}/conf'.."
if [[ ! -d "${WEBSITE_BASEDIR}/conf" ]]; then
mkdir ${WEBSITE_BASEDIR}/conf > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tSet Permissions on '${WEBSITE_BASEDIR}/conf'.."
_failed=false
chown root:$HTTP_USER ${WEBSITE_BASEDIR}/conf > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
chmod 750 ${WEBSITE_BASEDIR}/conf > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
if ! $_failed ; then
echo_ok
fi
for _version in $php_major_versions ; do
echononl "\tPlace file '${WEBSITE_BASEDIR}/conf/php.ini-$_version'"
cp /usr/local/php-${_version}/etc/php.ini ${WEBSITE_BASEDIR}/conf/php.ini-$_version > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tSet Permissions on '${WEBSITE_BASEDIR}/conf'.."
_failed=false
chown root:$HTTP_USER ${WEBSITE_BASEDIR}/conf/php.ini-$_version > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
chmod 640 ${WEBSITE_BASEDIR}/conf/php.ini-$_version > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
if ! $_failed ; then
echo_ok
fi
echononl "\tCreate file '${WEBSITE_BASEDIR}/conf/fcgid-$_version'.."
cat <<EOF > ${WEBSITE_BASEDIR}/conf/fcgid-$_version 2> $log_file
#!/bin/sh
export PHPRC="${WEBSITE_BASEDIR}/conf/"
export TMPDIR="${WEBSITE_BASEDIR}/tmp"
# PHP child process management (PHP_FCGI_CHILDREN) should
# always be disabled with mod_fcgid, which will only route one
# request at a time to application processes it has spawned;
# thus, any child processes created by PHP will not be used
# effectively. (Additionally, the PHP child processes may not
# be terminated properly.) By default, and with the environment
# variable setting PHP_FCGI_CHILDREN=0, PHP child process
# management is disabled.
PHP_FCGI_CHILDREN=0
export PHP_FCGI_CHILDREN
exec /usr/local/php-${_version}/bin/php-cgi
EOF
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tSet Permissions on '${WEBSITE_BASEDIR}/conf/fcgid-$_version'.."
_failed=false
chown root:$HTTP_USER ${WEBSITE_BASEDIR}/conf/fcgid-$_version > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
chmod 750 ${WEBSITE_BASEDIR}/conf/fcgid-$_version > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
if ! $_failed ; then
echo_ok
fi
done
# - Create Symlinks in fcgid's config directory
# -
if [[ "$_version" = "$php_latest_ver" ]]; then
echononl "\tCreate symlink '${WEBSITE_BASEDIR}/conf/php.ini'.."
if [[ ! -h "${WEBSITE_BASEDIR}/conf/php.ini" ]]; then
ln -s php.ini-$_version ${WEBSITE_BASEDIR}/conf/php.ini > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tCreate symlink '${WEBSITE_BASEDIR}/conf/fcgid'.."
if [[ ! -h "${WEBSITE_BASEDIR}/conf/fcgid" ]]; then
ln -s fcgid-$_version ${WEBSITE_BASEDIR}/conf/fcgid > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
fi
echononl "\tCreate file '${WEBSITE_BASEDIR}/conf/changes.php.ini.txt'.."
cat << EOF > ${WEBSITE_BASEDIR}/conf/changes.php.ini.txt
error_log = "${WEBSITE_BASEDIR}/logs/php_errors.log"
sys_temp_dir = "${WEBSITE_BASEDIR}/tmp"
upload_tmp_dir = "${WEBSITE_BASEDIR}/tmp"
session.save_path = "${WEBSITE_BASEDIR}/sessions"
soap.wsdl_cache_dir = "${WEBSITE_BASEDIR}/tmp"
EOF
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCreate file '${WEBSITE_BASEDIR}/logs/php_errors.log'.."
if [[ ! -f "${WEBSITE_BASEDIR}/logs/php_errors.log" ]]; then
touch ${WEBSITE_BASEDIR}/logs/php_errors.log > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
chown ${HTTP_USER}:${HTTP_GROUP} ${WEBSITE_BASEDIR}/logs/php_errors.log > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
if ! $_failed ; then
echo_ok
fi
else
echo_skipped
fi
_php_ini_file="${WEBSITE_BASEDIR}/conf/php.ini-*"
echononl "\tAdjust files '${WEBSITE_BASEDIR}/conf/php.ini-*'.."
_failed=false
_key=error_log
_val="${WEBSITE_BASEDIR}/logs/php_errors.log"
if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
#sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file
perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file > $log_file 2>&1
elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file > $log_file 2>&1
fi
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
_key="sys_temp_dir"
_val="${WEBSITE_BASEDIR}/tmp"
if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
#sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file
perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file > $log_file 2>&1
elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file > $log_file 2>&1
fi
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
_key="upload_tmp_dir"
_val="${WEBSITE_BASEDIR}/tmp"
if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
#sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file
perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file > $log_file 2>&1
elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file > $log_file 2>&1
fi
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
_key="session.save_path"
_val="${WEBSITE_BASEDIR}/sessions"
if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
#sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file
perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file > $log_file 2>&1
elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file > $log_file 2>&1
fi
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
_key="soap.wsdl_cache_dir"
_val="${WEBSITE_BASEDIR}/tmp"
if grep -e "^\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
#sed -i "0,/^\([ \t]*${_key}[ \t]*=.*\)/ s##;\1\n${_key} = \"${_val}\"#" $_php_ini_file
perl -i -n -p -e "s#^(\s*${_key}\s*=.*)#;\1\n${_key} = ${_val}#" $_php_ini_file > $log_file 2>&1
elif grep -e "^\s*;\s*${_key}\s*=" $_php_ini_file > /dev/null 2>&1 ; then
sed -i "0,/^\([ \t]*;[ \t]*${_key}[ \t]*=.*\)/ s##\1\n${_key} = \"${_val}\"\n#" $_php_ini_file > $log_file 2>&1
fi
if [[ $? -ne 0 ]]; then
_failed=true
error "$(cat $log_file)"
fi
if ! $_failed ; then
echo_ok
fi
fi
echo -e "\n\n\t\033[37m\033[1mConfigure Apache Webservice\033[m\n"
SSLCertificateChainFile=""
# - Create SSCertificateChainFile rule for apache vhost entry
# -
echononl "\tCreate SSCertificateChainFile rule for apache vhost entry"
if [ -n "$CERT_ChainFile" ];then
SSLCertificateChainFile="SSLCertificateChainFile ${APACHE_CERT_DIR}/$CERT_ChainFile"
echo_ok
else
echo_skipped
fi
echo ""
# - Save existing vhost file
# -
echononl "\tSave existing vhost file.."
if [ -f ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf ];then
if [[ -f "${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf" ]]; then
mv ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf.$backup_date > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
else
echo_skipped
fi
echononl "\tCreate VHost Configuration '${WEBSITE_NAME}.conf'.."
_failed=false
cat <<EOF > ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
# -- $WEBSITE_NAME -- #
<VirtualHost $IPV4:80>
ServerAdmin $WEBMASTER_EMAIL
ServerName $WEBSITE_NAME
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
CustomLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-access.log combined
ErrorLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-error.log
</VirtualHost>
<VirtualHost $IPV4:443>
ServerAdmin $WEBMASTER_EMAIL
ServerName $WEBSITE_NAME
EOF
if [[ $? -ne 0 ]]; then
failed=true
fi
if [[ "$PHP_TYPE" = "mod_php" ]] ; then
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
## - its allowed to overwrite by .htaccess
## -
php_value error_reporting "E_ALL & ~E_NOTICE"
## - Overwriting by .htaccess NOT allowd
## -
php_admin_value upload_tmp_dir "${WEBSITE_BASEDIR}/tmp/"
php_admin_flag log_errors on
php_admin_value error_log "${WEBSITE_BASEDIR}/logs/php_error.log"
php_admin_value session.save_path "${WEBSITE_BASEDIR}/sessions"
DocumentRoot "${WEBSITE_BASEDIR}/htdocs/"
EOF
if [[ $? -ne 0 ]]; then
failed=true
fi
elif [[ "$PHP_TYPE" = "fcgid" ]]; then
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
DocumentRoot "${WEBSITE_BASEDIR}/htdocs/"
<Directory "${WEBSITE_BASEDIR}/htdocs">
Require all granted
FCGIWrapper ${WEBSITE_BASEDIR}/conf/fcgid .php
<FilesMatch \.php$>
SetHandler fcgid-script
</FilesMatch>
Options +ExecCGI
</Directory>
EOF
if [[ $? -ne 0 ]]; then
failed=true
fi
elif [[ "$PHP_TYPE" = "php_fpm" ]]; then
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
DocumentRoot "${WEBSITE_BASEDIR}/htdocs/"
<FilesMatch \.php$>
SetHandler "proxy:unix:/tmp/php-${php_latest_ver}-fpm.www.sock|fcgi://127.0.0.1"
</FilesMatch>
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
EOF
if [[ $? -ne 0 ]]; then
failed=true
fi
fi
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
SSLEngine on
# - HTTP Strict Transport Security (HSTS)
# -
# - HSTS tells a browser that the website should only be accessed through
# - a secure connection. The HSTS header will be remembered by a standard
# compliant browser for max-age seconds.
# -
# - Remember this settings for 1 year
# -
Header always set Strict-Transport-Security "max-age=31536000"
SSLCertificateFile ${APACHE_CERT_DIR}/$APACHE_SERVER_CERT
SSLCertificateKeyFile ${APACHE_CERT_DIR}/$APACHE_SERVER_KEY
$SSLCertificateChainFile
CustomLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-access.log combined
ErrorLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-error.log
</VirtualHost>
# ---
# --- IPv6
# ---
<VirtualHost [$IPV6]:80>
ServerAdmin $WEBMASTER_EMAIL
ServerName $WEBSITE_NAME
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
CustomLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-access.log combined
ErrorLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-error.log
</VirtualHost>
<VirtualHost [$IPV6]:443>
ServerAdmin $WEBMASTER_EMAIL
ServerName $WEBSITE_NAME
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
if [[ "$PHP_TYPE" = "mod_php" ]]; then
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
## - its allowed to overwrite by .htaccess
## -
php_value error_reporting "E_ALL & ~E_NOTICE"
## - Overwriting by .htaccess NOT allowd
## -
php_admin_value upload_tmp_dir "${WEBSITE_BASEDIR}/tmp/"
php_admin_flag log_errors on
php_admin_value error_log "${WEBSITE_BASEDIR}/logs/php_error.log"
php_admin_value session.save_path "${WEBSITE_BASEDIR}/sessions"
DocumentRoot "${WEBSITE_BASEDIR}/htdocs/"
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
elif [[ "$PHP_TYPE" = "fcgid" ]]; then
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
DocumentRoot "${WEBSITE_BASEDIR}/htdocs/"
<Directory "${WEBSITE_BASEDIR}/htdocs">
Require all granted
FCGIWrapper ${WEBSITE_BASEDIR}/conf/fcgid .php
<FilesMatch \.php$>
SetHandler fcgid-script
</FilesMatch>
Options +ExecCGI
</Directory>
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
elif [[ "$PHP_TYPE" = "php_fpm" ]]; then
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
DocumentRoot "${WEBSITE_BASEDIR}/htdocs/"
<FilesMatch \.php$>
SetHandler "proxy:unix:/tmp/php-${php_latest_ver}-fpm.www.sock|fcgi://127.0.0.1"
</FilesMatch>
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
EOF
if [[ $? -ne 0 ]]; then
failed=true
fi
fi
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
SSLEngine on
# - HTTP Strict Transport Security (HSTS)
# -
# - HSTS tells a browser that the website should only be accessed through
# - a secure connection. The HSTS header will be remembered by a standard
# compliant browser for max-age seconds.
# -
# - Remember this settings for 1 year
# -
Header always set Strict-Transport-Security "max-age=31536000"
SSLCertificateFile ${APACHE_CERT_DIR}/$APACHE_SERVER_CERT
SSLCertificateKeyFile ${APACHE_CERT_DIR}/$APACHE_SERVER_KEY
$SSLCertificateChainFile
CustomLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-access.log combined
ErrorLog ${APACHE_LOG_DIR}/${WEBSITE_NAME}-error.log
</VirtualHost>
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
if $_failed ; then
echo_failed
error "$(cat $log_file)"
else
echo_ok
fi
if $APACHE_DEBIAN_INSTALLATION ; then
## - add to /etc/apache2/ports.conf
## -
## - NameVirtualHost 46.4.73.217:80
## - NameVirtualHost [2a01:4f8:140:34c1::4]:80
## - Listen 46.4.73.217:80
## - Listen [2a01:4f8:140:34c1::4]:80
## - <IfModule mod_ssl.c>
## - ..
## - NameVirtualHost 46.4.73.217:443
## - NameVirtualHost [2a01:4f8:140:34c1::4]:443
## - Listen 46.4.73.217:443
## - Listen [2a01:4f8:140:34c1::4]:443
## - </IfModule>
## - ..
#vim /etc/apache2/ports.conf
## - enable site webmail.warenform.de
## -
echononl "\tEnable ${WEBSITE_NAME}.conf"
a2ensite ${WEBSITE_NAME}.conf > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
fi
echononl "\tCreate 'robots.txt'.."
cat <<EOF > ${WEBSITE_BASEDIR}/htdocs/robots.txt 2> $log_file
User-agent: *
Disallow: /
EOF
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tRestart Apache Webservice.."
if $APACHE_DEBIAN_INSTALLATION ; then
/etc/init.d/apache2 reload > $log_file 2>&1
else
/etc/init.d/apache2 restart > $log_file 2>&1
fi
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
# - Install a cronjob for cleaning up tmp-directory
# -
if [[ "$PHP_TYPE" = "fcgid" ]] ; then
echononl "\tCreate cronjob for cleaning up tmp-directory.."
crontab -l > /tmp/tmp_crontab
if ! grep -q -E "find\s+${WEBSITE_BASEDIR}/tmp\s*-type\s*f" /tmp/tmp_crontab 2> /dev/null ; then
echo "" >> /tmp/tmp_crontab
echo "# - Cleanup tmp directory of the Rounfcube Webmailer" >> /tmp/tmp_crontab
echo "# -" >> /tmp/tmp_crontab
echo "23 3 * * * find $WEBSITE_BASEDIR/tmp -type f -mtime +1 -exec rm -f {} \;" >> /tmp/tmp_crontab
crontab /tmp/tmp_crontab
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
rm /tmp/tmp_crontab
fi
# - Logrotate logfiles from webmailer, locatet at $WEBSITE_BASEDIR/logs
# -
echononl "\tCreate logrotate entry.."
if [[ "$PHP_TYPE" = "fcgid" ]] ; then
cat <<EOF > /etc/logrotate.d/roundcube 2> $log_file
$WEBSITE_BASEDIR/logs/errors
$WEBSITE_BASEDIR/logs/sql
$WEBSITE_BASEDIR/logs/sendmail
$WEBSITE_BASEDIR/logs/*.log {
daily
start 0
rotate 7
missingok
notifempty
compress
delaycompress
create 640 www-data www-data
copytruncate
}
EOF
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
elif [[ "$APACHE_LOG_DIR" =~ ${WEBSITE_BASEDIR} ]] ; then
cat <<EOF > /etc/logrotate.d/roundcube 2> $log_file
$APACHE_LOG_DIR/*.log {
daily
start 0
rotate 7
missingok
notifempty
compress
delaycompress
create 640 www-data www-data
copytruncate
}
EOF
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echo -e "\n\n\t\033[37m\033[1mSetup Database '$DB_TYPE'..\033[m\n"
# - Datenbank etstellen:
# -
# - MySQL/PostgreSQL Datenbank erstellen
# -
# -
if [[ "$DB_TYPE" = "mysql" ]]; then
if ! mysql $MYSQL_CREDENTIALS -N -s -e \
"SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$DB_NAME'" 2>> $log_file \
| grep $DB_NAME >> $log_file 2>&1 ; then
database_exists=false
else
database_exists=true
fi
elif [[ "$DB_TYPE" = "pgsql" ]]; then
count=$(su - postgres -c "psql -q -A -t -l" | grep -c -e "^$DB_NAME")
if [[ $count -eq 0 ]];then
database_exists=false
else
database_exists=true
fi
else
fatal "Cannot detect database type (value of DB_TYPE is neither 'mysql' nor 'pgsql')"
fi
_failed=false
echononl "\tCreate Database '$DB_NAME'"
if ! $database_exists ; then
if [[ "$DB_TYPE" = "mysql" ]]; then
echo -n " (MySQL).."
mysql -u$_mysql_rootuser -p$_mysql_rootpass -N -s -e \
"CREATE DATABASE IF NOT EXISTS $DB_NAME CHARACTER SET utf8 COLLATE utf8_general_ci"
if [[ $? -ne 0 ]]; then
_failed=true
fi
mysql -u$_mysql_rootuser -p$_mysql_rootpass -N -s -e \
"GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASS'"
if [[ $? -ne 0 ]]; then
_failed=true
fi
mysql -u$_mysql_rootuser -p$_mysql_rootpass -N -s -e "FLUSH PRIVILEGES"
if [[ $? -ne 0 ]]; then
_failed=true
fi
if ! $_failed ; then
echo_ok
else
echo_failed
fi
elif [[ "$DB_TYPE" = "pgsql" ]]; then
echo -n " (PostgreSQL).."
echo "CREATE ROLE $DB_USER WITH LOGIN NOCREATEDB NOCREATEROLE NOSUPERUSER ENCRYPTED PASSWORD '$DB_PASS'" \
| su - postgres -c "psql" > /dev/null
if [[ $? -ne 0 ]]; then
_failed=true
fi
su - postgres -c "createdb -E utf8 -O $DB_USER $DB_NAME"
if [[ $? -ne 0 ]]; then
_failed=true
fi
if ! $_failed ; then
echo_ok
else
echo_failed
fi
fi
else
echo_skipped
fi
echononl "\tBackup existing Database '$DB_NAME'"
if $database_exists ; then
if [[ "$DB_TYPE" = "mysql" ]]; then
echo -n " (MySQL).."
mysqldump -u$_mysql_rootuser -p$_mysql_rootpass --opt $DB_NAME > ${WEBSITE_BASEDIR}/${DB_NAME}.$backup_date 2> $log_file
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
elif [[ "$DB_TYPE" = "pgsql" ]]; then
echo -n " (PostgreSQL).."
su - postgres -c "pg_dump -c $DB_NAME" > ${WEBSITE_BASEDIR}/${DB_NAME}.$backup_date.sql 2> $log_file
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
fi
else
echo_skipped
fi
info "Now browse to the intaller site and continue installation.\n$(cat <<EOF
Browse to site: \033[1mhttps://${WEBSITE_NAME}/installer\033[m
Maybe you want to change some values as follows
General configuration:
product_name...........: $PRODUCT_NAME
support_url............: $SUPPORT_URL
skin_logo..............: $SKIN_LOGO
temp_dir...............: $ROUNDCUBE_TMPDIR
Logging and Debugging:
log_dir................: ${WEBSITE_BASEDIR}/logs
Database setup:
Database type..........: $DB_TYPE
Database server........: $DB_HOST
Database name..........: $DB_NAME
Database user name.....: $DB_USER
Database password......: $DB_PASS
IMAP Settings:
default_host...........: localhost
default_port...........: 143
junk_mbox..............: $SPAM_FOLDER_NAME
SMTP Settings:
smtp_server............: localhost
smtp_port..............: 25
smtp_user/smtp_pass....:
[ ] Use the current IMAP username and password for SMTP authentication
Display settings & user prefs:
language...............: de_DE
skin...................: larry
EOF
)"
echo ""
echo -e "After finished the installer setup procedure you can also ontinue with this script."
echo ""
echo -n "Type upper case 'YES' to continue: "
read OK
if [[ "$OK" = "YES" ]] ; then
echo ""
echo ""
echo -e "\t\033[1;32mGoing to configure Roundcube Webmailer \033[1;37m$network \033[m"
echo ""
else
warn "Abort by user request - Answer as not 'YES'"
echo ""
rm -f $log_file
clean_up 1
fi
echo -e "\n\n\t\033[37m\033[1mSome additional configuration ..\033[m\n"
# - After successfully installation, make a few changes
# - to file $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/config/main.inc.php
# -
# - Bereits via webinterface (installer) eingestellt:
# -
# - $rcmail_config['product_name'] = 'Webmail - IL';
# - $rcmail_config['imap_auth_type'] = 'LOGIN';
# - $rcmail_config['skin_logo'] = 'images/logo_il.png';
# - $rcmail_config['language'] = 'de_DE';
# - $rcmail_config['create_default_folders'] = false;
# - $rcmail_config['quota_zero_as_unlimited'] = false;
# - $rcmail_config['preview_pane'] = false;
# -
# - Sind schon die default werte:
# -
# - #$rcmail_config['password_charset'] = 'ISO-8859-1';
# - #$rcmail_config['plugins'] = array();
# - #$rcmail_config['message_sort_col'] = '';
# -
# - Ändern:
# -
# - $rcmail_config['login_autocomplete'] = 1;
# - $rcmail_config['logout_purge'] = true;
# - $rcmail_config['delete_always'] = true;
# - $rcmail_config['mime_magic'] = '/usr/share/misc/magic';
# -
echononl "\tCreate key for encrypting purposes.."
_des_key=$(tr -cd '[:alnum:]#_\!\%/=@-' < /dev/urandom | fold -w24 | head -n1)
if [[ -n "$_des_key" ]] && [[ ${#_des_key} -eq 24 ]]; then
echo_ok
else
echo_failed
fi
echononl "\tSet.. 'des_key', 'login_autocomplete', and more.."
cat <<EOF >>$WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/config/config.inc.php 2> $log_file
// ==================================
// Added after basic installation
// ==================================
// This key is used for encrypting purposes, like storing of imap password
// in the session. For historical reasons it's called DES_key, but it's used
// with any configured cipher_method (see below).
\$config['des_key'] = '$_des_key';
// ----------------------------------
// SYSTEM
// ----------------------------------
// THIS OPTION WILL ALLOW THE INSTALLER TO RUN AND CAN EXPOSE SENSITIVE CONFIG DATA.
// ONLY ENABLE IT IF YOU'RE REALLY SURE WHAT YOU'RE DOING!
\$config['enable_installer'] = false;
// Allow browser-autocompletion on login form.
// 0 - disabled, 1 - username and host only, 2 - username, host, password
\$config['login_autocomplete'] = 1;
// ----------------------------------
// USER PREFERENCES
// ----------------------------------
// Clear Trash on logout
\$config['logout_purge'] = true;
// 'Delete always'
// This setting reflects if mail should be always deleted
// when moving to Trash fails. This is necessary in some setups
// when user is over quota and Trash is included in the quota.
\$config['delete_always'] = true;
EOF
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echo -e "\n\n\t\033[37m\033[1mEnable Spellcheccking..\033[m\n"
echononl "\tInstall needed debian packages.."
needed_packages_spell=""
_needed_packages_spell="
aspell-en
aspell-de
aspell-da
aspell-es
aspell-fr
aspell-it"
for _pkg in $_needed_packages_spell ; do
if aptitude search "$_pkg" | grep " $_pkg " | grep -e "^i" > /dev/null 2>&1 ; then
continue
else
needed_packages_spell="$needed_packages_spell $_pkg"
fi
done
if [[ -n "$needed_packages_spell" ]]; then
DEBIAN_FRONTEND=noninteractive apt-get -y install $needed_packages_spell > /dev/null 2> "$log_file"
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tAdjust Roundcube Configuration for specclchecking"
cat <<EOF >>$WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/config/config.inc.php 2> $log_file
// ----------------------------------
// USER INTERFACE
// ----------------------------------
// Make use of the built-in spell checker. It is based on GoogieSpell.
// Since Google only accepts connections over https your PHP installatation
// requires to be compiled with Open SSL support
\$config['enable_spellcheck'] = true;
// Enables spellchecker exceptions dictionary.
// Setting it to 'shared' will make the dictionary shared by all users.
\$config['spellcheck_dictionary'] = false;
// Set the spell checking engine. Possible values:
// - 'googie' - the default
// - 'pspell' - requires the PHP Pspell module and aspell installed
// - 'enchant' - requires the PHP Enchant module
// - 'atd' - install your own After the Deadline server or check with the people at http://www.afterthedeadline.com before using their API
// Since Google shut down their public spell checking service, you need to
// connect to a Nox Spell Server when using 'googie' here. Therefore specify the 'spellcheck_uri'
\$config['spellcheck_engine'] = 'pspell';
// For locally installed Nox Spell Server or After the Deadline services,
// please specify the URI to call it.
// Get Nox Spell Server from http://orangoo.com/labs/?page_id=72 or
// the After the Deadline package from http://www.afterthedeadline.com.
// Leave empty to use the public API of service.afterthedeadline.com
\$config['spellcheck_uri'] = '';
// These languages can be selected for spell checking.
// Configure as a PHP style hash array: array('en'=>'English', 'de'=>'Deutsch');
// Leave empty for default set of available language.
//
// Take care tha dictionaries for aspell ar installed !
// for debian:
// apt-get install aspell-en aspell-de aspell-da aspell-es aspell-fr aspell-it
\$config['spellcheck_languages'] = array(
'en' => 'English',
'de' => 'Deutsch',
'da' => 'Dansk',
'fr' => 'Français',
'it' => 'Italiano',
'es' => 'Español',
);
// Makes that words with all letters capitalized will be ignored (e.g. GOOGLE)
\$config['spellcheck_ignore_caps'] = true;
// Makes that words with numbers will be ignored (e.g. g00gle)
\$config['spellcheck_ignore_nums'] = true;
// Makes that words with symbols will be ignored (e.g. g@@gle)
\$config['spellcheck_ignore_syms'] = true;
EOF
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echo -e "\n\n\t\033[37m\033[1mAdd/Configure Plugins..\033[m"
declare -a add_plugin_arr
# - acl
# -
if $INCLUDE_ACL_PLUGIN ; then
_plugin="acl"
add_plugin_arr+=("$_plugin")
echo -e "\n\t\033[32mPlugin '$_plugin'\033[m"
echononl "\tCopy default config file to 'config.inc.php'.."
cp -a ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php.dist \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tActivate advanced mode.."
_key="acl_advanced_mode"
_val="true"
perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.."
fi
# - archive
# -
_plugin="archive"
add_plugin_arr+=("$_plugin")
echo -e "\n\t\033[32mPlugin '$_plugin'\033[m"
echo -e "\tNothing to do here. Plugin '$_plugin' will be added to array plugins later.."
# - contextmenu
# -
_plugin="contextmenu"
add_plugin_arr+=("$_plugin")
echo -e "\n\t\033[32mPlugin '$_plugin'\033[m"
echononl "\tDownload Pluging '$_plugin'.."
wget -O ${WEBSITE_BASEDIR}/Roundcube-Plugin-Context-Menu-master.zip \
https://github.com/JohnDoh/Roundcube-Plugin-Context-Menu/archive/master.zip > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tUnpack archiv into Plugin Folder"
unzip -d ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/ \
${WEBSITE_BASEDIR}/Roundcube-Plugin-Context-Menu-master.zip > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCeate Symlink '$_pligin' in plugin folder.."
ln -s Roundcube-Plugin-Context-Menu-master \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin} > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.."
# - jqueryui
# -
_plugin="jqueryui"
add_plugin_arr+=("$_plugin")
echo -e "\n\t\033[32mPlugin '$_plugin'\033[m"
echononl "\tCopy default config file to 'config.inc.php'.."
cp -a ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php.dist \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.."
# - login_lang
# -
_plugin="login_lang"
add_plugin_arr+=("$_plugin")
echo -e "\n\t\033[32mPlugin '$_plugin'\033[m"
echononl "\tDownload Pluging '$_plugin' (roundcube-login-language-master)"
wget -O ${WEBSITE_BASEDIR}/roundcube-login-language-master.zip \
https://github.com/hassansin/roundcube-login-language/archive/master.zip > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tUnpack archiv into Plugin Folder"
unzip -d ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/ \
${WEBSITE_BASEDIR}/roundcube-login-language-master.zip > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCeate Symlink '$_pligin' in plugin folder.."
ln -s roundcube-login-language-master \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin} > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCopy default config file to 'config.inc.php'.."
cp -a ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php.dist \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tChange default language to 'de_DE'"
_key="language_dropdown_selected"
_val="'de_DE'"
perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.."
# - managesieve
# -
_plugin="managesieve"
add_plugin_arr+=("$_plugin")
echo -e "\n\t\033[32mPlugin '$_plugin'\033[m"
echononl "\tCopy default config file to 'config.inc.php'.."
cp -a ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php.dist \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key=managesieve_port
_val="4190"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key=managesieve_default
_val="'/usr/local/dovecot/etc/dovecot/sieve/move-spam.sieve'"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="managesieve_disabled_extensions"
_val="array('vacation')"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.."
# - markasjunk2
# -
_plugin="markasjunk2"
add_plugin_arr+=("$_plugin")
echo -e "\n\t\033[32mPlugin '$_plugin'\033[m"
echononl "\tDownload Pluging '$_plugin'.."
wget -O ${WEBSITE_BASEDIR}/Roundcube-Plugin-Mark-as-Junk-2-master.zip \
https://github.com/JohnDoh/Roundcube-Plugin-Mark-as-Junk-2/archive/master.zip > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tUnpack archiv into Plugin Folder"
unzip -d ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/ \
${WEBSITE_BASEDIR}/Roundcube-Plugin-Mark-as-Junk-2-master > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCeate Symlink '$_pligin' in plugin folder.."
ln -s Roundcube-Plugin-Mark-as-Junk-2-master \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin} > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.."
# - password
# -
_plugin="password"
add_plugin_arr+=("$_plugin")
echo -e "\n\t\033[32mPlugin '$_plugin'\033[m"
echononl "\tCopy default config file to 'config.inc.php'.."
cp -a ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php.dist \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="password_driver"
_val="'sql'"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="password_confirm_current"
_val="$PW_CONFIRM_CURRENT"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="password_minimum_length"
_val="$PW_MIN_LENGTH"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="password_require_nonalpha"
_val="$PW_REQUIRE_NONALPHA"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="password_algorithm"
_val="'$PW_PASSWD_ALGO'"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="password_algorithm_prefix"
_val="'$PW_PASSWD_ALGO_PREFIX'"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="password_dovecotpw"
_val="'$PW_DOVEADM_PW'"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="password_dovecotpw_method"
_val="'$PW_DOVECOT_PW_METHOD'"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="password_db_dsn"
_val="'${POSTFIX_DB_TYPE}://${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}\@${POSTFIX_DB_HOST}/${POSTFIX_DB_NAME}'"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="password_query"
_val="'$PW_DB_UPDATE_STRING'"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.."
# - vacation
# -
_plugin="vacation"
add_plugin_arr+=("$_plugin")
_config_file="${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php"
_backup_file="${_config_file}.$backup_date"
echo -e "\n\t\033[32mPlugin '$_plugin'\033[m"
echononl "\tDownload Pluging '$_plugin'.."
wget -O ${WEBSITE_BASEDIR}/rc-vacation-master.zip \
https://github.com/bhuisgen/rc-vacation/archive/master.zip > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tUnpack archiv into Plugin Folder"
unzip -d ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/ \
${WEBSITE_BASEDIR}/rc-vacation-master.zip > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCeate Symlink '$_pligin' in plugin folder.."
ln -s rc-vacation-master \
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin} > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCopy default config file to 'config.inc.php'.."
cp -a ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/plugins/${_plugin}/config.inc.php.dist \
$_config_file > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="vacation_gui_vacationdate"
_val="TRUE"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
$_config_file > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="vacation_subject_default"
_val="'Re: \\\$SUBJECT'"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
$_config_file > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="vacation_gui_vacationforwarder"
_val="$VAC_GUI_FORWARDER"
echononl "\tchange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
$_config_file > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="vacation_dateformat"
_val="'Y-m-d'"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
$_config_file > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="vacation_jquery_calendar"
_val="TRUE"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
$_config_file > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="vacation_jquery_dateformat"
_val="'yy-m-d'"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
$_config_file > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="vacation_forwarder_multiple"
_val="'FALSE'"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
$_config_file > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="vacation_forwarder_separator"
_val="','"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
$_config_file > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="vacation_driver"
_val="'sql'"
echononl "\tChange '$_key' to $_val"
perl -i -n -p -e "s#(^\s*\\\$(rcmail_)?config\['$_key'\].*)#//\!\1\n\\\$config['$_key'] = $_val;#" \
$_config_file > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
_key="vacation_sql_dsn"
_val="'${POSTFIX_DB_TYPE}://${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}@${POSTFIX_DB_HOST}/${POSTFIX_DB_NAME}'"
echononl "\tChange '$_key' to $_val"
failed=false
mv $_config_file $_backup_file > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
_found=false
_found_comment=false
while IFS='' read -r _line || [[ -n $_line ]] ; do
if echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]\s*=\s*'[^']*'\s*;" > /dev/null 2>&1 ; then
echo '//!'"$_line" >> $_config_file
echo "\$config['$_key'] = $_val;" >> $_config_file
continue
elif echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]" > /dev/null 2>&1 ; then
_found=true
echo "/*" >> $_config_file
echo "$_line" >> $_config_file
continue
fi
if $_found && echo "$_line" | grep -i -E "^\s*/\*.*" > /dev/null 2>&1 ; then
_found_comment=true
fi
if $_found_comment ; then
echo "$_line" >> $_config_file
if echo "$_line" | grep -i -E "\*/\s*$" > /dev/null 2>&1 ; then
echo "/*" >> $_config_file
_found_comment=false
fi
continue
fi
if $_found && echo "$_line" | grep -i -E "^\s*[^(//|/\*)]+'.+';$" > /dev/null 2>&1 ; then
echo "$_line" >> $_config_file
echo "*/" >> $_config_file
echo "\$config['$_key'] = $_val;" >> $_config_file
_found=false
continue
fi
echo "$_line" >> $_config_file
done < "$_backup_file"
if [[ $? -ne 0 ]]; then
_failed=true
fi
if $_failed ; then
echo_failed
else
echo_ok
fi
failed=false
mv $_config_file $_backup_file > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
_key="vacation_sql_read"
echononl "\tChange '$_key'.."
_found=false
_found_comment=false
while IFS='' read -r _line || [[ -n $_line ]] ; do
if echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]\s*=\s*array\s*\([^\)]*\)\s*;" > /dev/null 2>&1 ; then
echo '//!'"$_line" >> $_config_file
echo "\$config['$_key'] = array($;" >> $_config_file
continue
elif echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]" > /dev/null 2>&1 ; then
_found=true
echo "/*" >> $_config_file
echo "$_line" >> $_config_file
continue
fi
if $_found && echo "$_line" | grep -i -E "^\s*/\*.*" > /dev/null 2>&1 ; then
_found_comment=true
fi
if $_found_comment ; then
echo "$_line" >> $_config_file
if echo "$_line" | grep -i -E "\*/\s*$" > /dev/null 2>&1 ; then
echo "/*" >> $_config_file
_found_comment=false
fi
continue
fi
if $_found && echo "$_line" | grep -i -E "^\s*[^(//|/\*)]+\)\s*;$" > /dev/null 2>&1 ; then
echo "$_line" >> $_config_file
echo "*/" >> $_config_file
echo "\$config['${_key}'] = array(" >> $_config_file
if [[ "$POSTFIX_DB_TYPE" = "pgsql" ]]; then
cat <<EOF >> $_config_file 2>> $log_file
"SELECT
subject AS vacation_subject,
body AS vacation_message,
date(activefrom) AS vacation_start,
date(activeuntil) AS vacation_end,
CASE WHEN vacation.active = TRUE THEN true ELSE false END AS vacation_enable,
udf_forwarders_out(%username,'${AUTOREPLY_HOSTNAME}',',') AS vacation_forwarder
FROM vacation,alias
WHERE email=%username AND address=%username AND vacation.domain=%email_domain;"
EOF
else
cat <<EOF >> $_config_file 2>> $log_file
"SELECT subject AS vacation_subject, body AS vacation_message," .
"UNIX_TIMESTAMP(activefrom) AS vacation_start," .
"UNIX_TIMESTAMP(activeuntil) AS vacation_end," .
"vacation.active AS vacation_enable," .
"FORWARDERS_OUT(%username,'${AUTOREPLY_HOSTNAME}',',') AS vacation_forwarder " .
"FROM vacation,alias " .
"WHERE email=%username AND address=%username AND vacation.domain=%email_domain;"
EOF
fi
echo ");" >> $_config_file
_found=false
continue
fi
echo "$_line" >> $_config_file
done < "$_backup_file"
if [[ $? -ne 0 ]]; then
_failed=true
fi
if $_failed ; then
echo_failed
else
echo_ok
fi
failed=false
mv $_config_file $_backup_file > $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
_key="vacation_sql_write"
echononl "\tChange '$_key'.."
_found=false
_found_comment=false
while IFS='' read -r _line || [[ -n $_line ]] ; do
if echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]\s*=\s*array\s*\([^\)]*\)\s*;" > /dev/null 2>&1 ; then
echo '//!'"$_line" >> $_config_file
echo "\$config['$_key'] = array($;" >> $_config_file
continue
elif echo "$_line" | grep -i -E "^\s*\\\$(rcmail_)?config\['$_key'\]" > /dev/null 2>&1 ; then
_found=true
echo "/*" >> $_config_file
echo "$_line" >> $_config_file
continue
fi
if $_found && echo "$_line" | grep -i -E "^\s*/\*.*" > /dev/null 2>&1 ; then
_found_comment=true
fi
if $_found_comment ; then
echo "$_line" >> $_config_file
if echo "$_line" | grep -i -E "\*/\s*$" > /dev/null 2>&1 ; then
echo "/*" >> $_config_file
_found_comment=false
fi
continue
fi
if $_found && echo "$_line" | grep -i -E "^\s*[^(//|/\*)]+\)\s*;$" > /dev/null 2>&1 ; then
echo "$_line" >> $_config_file
echo "*/" >> $_config_file
echo "\$config['${_key}'] = array(" >> $_config_file
if [[ "$POSTFIX_DB_TYPE" = "pgsql" ]]; then
if $VAC_GUI_FORWARDER ; then
# - Database: PostgreSQL
# - Allow vacation forwarder: false
# -
cat <<EOF >> $_config_file 2>> $log_file
// Clean up vacation
"DELETE FROM vacation WHERE email=%email AND domain=%email_domain;",
// Cleanup notifications
"DELETE from vacation_notification WHERE on_vacation=%email;",
// Save entries to table vacation
"INSERT INTO vacation (email,domain,subject,body,activefrom,activeuntil,interval_time,created,active) " .
"VALUES (%email,%email_domain,%vacation_subject,%vacation_message," .
"to_timestamp(%vacation_start - extract(timezone from current_timestamp))," .
"to_timestamp(%vacation_end + 86399 - extract(timezone from current_timestamp))," .
"86400,NOW(),udf_set_active(%vacation_enable));",
// Update table alias
"UPDATE alias SET goto = udf_forwarders_in(udf_forwarders_out(%email,'${AUTOREPLY_HOSTNAME}',',')," .
"%email,'${AUTOREPLY_HOSTNAME}',',',udf_set_active(%vacation_enable))" .
", modified = NOW() " .
" WHERE address = %email"
EOF
else
# - Database: PostgreSQL
# - Allow vacation forwarder: true
# -
cat <<EOF >> $_config_file 2>> $log_file
// Clean up vacation
"DELETE FROM vacation WHERE email=%email AND domain=%email_domain;",
// Cleanup notifications
"DELETE from vacation_notification WHERE on_vacation=%email;",
// Save entries to table vacation
"INSERT INTO vacation (email,domain,subject,body,activefrom,activeuntil,interval_time,created,active) " .
"VALUES (%email,%email_domain,%vacation_subject,%vacation_message," .
"to_timestamp(%vacation_start - extract(timezone from current_timestamp))," .
"to_timestamp(%vacation_end + 86399 - extract(timezone from current_timestamp))," .
"86400,NOW(),udf_set_active(%vacation_enable));",
// Update table alias
"UPDATE alias SET goto = udf_forwarders_in(%vacation_forwarder," .
"%email,'${AUTOREPLY_HOSTNAME}',',',udf_set_active(%vacation_enable))" .
", modified = NOW() " .
" WHERE address = %email"
EOF
fi
else
if $VAC_GUI_FORWARDER ; then
# - Database: MySQL
# - Allow vacation forwarder: FALSE
# -
cat <<EOF >> $_config_file 2>> $log_file
// Clean up vacation
"DELETE FROM vacation WHERE email=%email AND domain=%email_domain;",
// Cleanup notifications
"DELETE from vacation_notification WHERE on_vacation=%email;",
// Save entries to table vacation
"INSERT INTO vacation (email,domain,subject,body,activefrom,activeuntil,interval_time,created,active) " .
"VALUES (%email,%email_domain,%vacation_subject,%vacation_message," .
"CONCAT(DATE(FROM_UNIXTIME(%vacation_start)), ' 00:00:00')," .
"CONCAT(DATE(FROM_UNIXTIME(%vacation_end)), ' 23:59:59')," .
"86400,NOW(),%vacation_enable);",
// Update table alias
"UPDATE alias SET goto = FORWARDERS_IN(FORWARDERS_OUT(%email,'${AUTOREPLY_HOSTNAME}',',')," .
"%email,'${AUTOREPLY_HOSTNAME}',',',%vacation_enable)" .
", modified = NOW() " .
" WHERE address = %email"
EOF
else
# - Database: MySQL
# - Allow vacation forwarder: TRUE
# -
cat <<EOF >> $_config_file 2>> $log_file
// Clean up vacation
"DELETE FROM vacation WHERE email=%email AND domain=%email_domain;",
// Cleanup notifications
"DELETE from vacation_notification WHERE on_vacation=%email;",
// Save entries to table vacation
"INSERT INTO vacation (email,domain,subject,body,activefrom,activeuntil,interval_time,created,active) " .
"VALUES (%email,%email_domain,%vacation_subject,%vacation_message," .
"CONCAT(DATE(FROM_UNIXTIME(%vacation_start)), ' 00:00:00')," .
"CONCAT(DATE(FROM_UNIXTIME(%vacation_end)), ' 23:59:59')," .
"86400,NOW(),%vacation_enable);",
// Update table alias
"UPDATE alias SET goto = FORWARDERS_IN(%vacation_forwarder," .
"%email,'${AUTOREPLY_HOSTNAME}',',',%vacation_enable)" .
", modified = NOW() " .
" WHERE address = %email"
EOF
fi
fi
echo ");" >> $_config_file
_found=false
continue
fi
echo "$_line" >> $_config_file
done < "$_backup_file"
if [[ $? -ne 0 ]]; then
_failed=true
fi
if $_failed ; then
echo_failed
else
echo_ok
fi
if [[ "$POSTFIX_DB_TYPE" = 'pgsql' ]] ; then
echononl "\tCreate postfix language plpgsql"
_pgpsql_exists=$(su - postgres -c "psql -t -c \"SELECT EXISTS ( SELECT 1 FROM pg_language WHERE lanname = 'plpgsql');\"")
if [[ "$_pgpsql_exists" =~ t ]]; then
echo_skipped
else
su - postgres -c "psql -t -c \"CREATE LANGUAGE plpgsql;\"" > $log_file 2>&1
if [[ $? -ne 0 ]] ; then
echo_failed
erro $(cat $log_file)
else
echo_ok
fi
fi
# - Create postfix trigger function udf_forwarders_out
# -
_trigger_function="udf_forwarders_out"
echononl "\tCreate postfix trigger function $_trigger_function"
if [[ -n "$(su - postgres -c"psql postfix -t -c \"\\df $_trigger_function\"" | awk '{print$3}')" ]]; then
echo_skipped
else
_psql_trigger_file="$(mktemp)"
echo "" > $log_file
echo "cat <<EOF > \$_psql_trigger_file" >> $log_file
echo ".." >> $log_file
echo "EOF" >> $log_file
cat <<EOF > $_psql_trigger_file 2>> $log_file
CREATE FUNCTION udf_forwarders_out(email_str text, vacation_domain text, list_seperator character) RETURNS text
LANGUAGE plpgsql
AS \$\$
DECLARE
forward_str text;
local_email_part TEXT;
domain_email_part TEXT;
BEGIN
-- get list of forwarders
--
SELECT goto INTO forward_str FROM alias WHERE address=email_str;
-- entferne mailbox emailadresse
--
forward_str = replace(forward_str, email_str, '' );
-- entferne vacation adresse
--
local_email_part = substring(email_str, 1, position('@' in email_str) - 1);
domain_email_part = substring(email_str, position('@' in email_str) + 1 );
forward_str = replace(forward_str, local_email_part || '#' || domain_email_part || '@' || vacation_domain, '');
-- enferne doppelte seperatorzeichen
--
WHILE position( list_seperator || list_seperator in forward_str ) > 0 LOOP
forward_str = replace(forward_str, list_seperator || list_seperator , '');
END LOOP;
-- entferne erstes zeichen wenn es das seperatorzeichen ist
--
IF substring(forward_str,1,1) = list_seperator THEN
forward_str = substring(forward_str from 2);
END IF;
-- entferne letztes zeichen wenn es das seperatorzeichen ist
--
IF substring(forward_str from char_length(forward_str)) = list_seperator THEN
forward_str = substring(forward_str, 1, char_length(forward_str) - 1);
END IF;
-- forward_str = substring(forward_str from char_length(forward_str));
RETURN forward_str;
END;
\$\$;
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
_pgppass_back_file="~/.pgpass.$backup_date"
_pgpass_was_present=false
if [[ -f "~/.pgpass" ]]; then
_pgpass_was_present=true
echo "" >> $log_file
echo "mv \"~/.pgpass\" \"$_pgppass_back_file\"" >> $log_file
mv "~/.pgpass" "$_pgppass_back_file" >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
fi
echo "" >> $log_file
echo "echo \"${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}\" > ~/.pgpass" >> $log_file 2>> $log_file
echo "${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}" > ~/.pgpass
if [[ $? -ne 0 ]]; then
_failed=true
fi
echo "" >> $log_file
echo "psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file" >> $log_file
psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
echo "" >> $log_file
echo "rm $_psql_trigger_file" >> $log_file
rm $_psql_trigger_file >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
if $_pgpass_was_present ; then
echo "" >> $log_file
echo "mv \"$_pgppass_back_file\" \"~/.pgpass\"" >> $log_file
mv \"$_pgppass_back_file\" \"~/.pgpass\" >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
fi
if $_failed ; then
echo_failed
erro $(cat $log_file)
else
echo_ok
fi
fi
# - Create postfix trigger function udf_set_active
# -
_trigger_function="udf_set_active"
echononl "\tCreate postfix trigger function $_trigger_function"
if [[ -n "$(su - postgres -c"psql postfix -t -c \"\\df $_trigger_function\"" | awk '{print$3}')" ]]; then
echo_skipped
else
_psql_trigger_file="$(mktemp)"
echo "" > $log_file
echo "cat <<EOF > \$_psql_trigger_file" >> $log_file
echo ".." >> $log_file
echo "EOF" >> $log_file
cat <<EOF > $_psql_trigger_file 2>> $log_file
CREATE FUNCTION udf_set_active(vacation_enable text) RETURNS boolean
LANGUAGE plpgsql
AS \$\$
DECLARE
return_val boolean;
BEGIN
return_val = 't';
IF vacation_enable = '' THEN
return_val = 'f';
END IF;
IF vacation_enable = '0' THEN
return_val = 'f';
END IF;
IF lower(vacation_enable) = 'false' THEN
return_val = 'f';
END IF;
RETURN return_val;
END;
\$\$;
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
_pgppass_back_file="~/.pgpass.$backup_date"
_pgpass_was_present=false
if [[ -f "~/.pgpass" ]]; then
_pgpass_was_present=true
echo "" >> $log_file
echo "mv \"~/.pgpass\" \"$_pgppass_back_file\"" >> $log_file
mv "~/.pgpass" "$_pgppass_back_file" >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
fi
echo "" >> $log_file
echo "echo \"${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}\" > ~/.pgpass" >> $log_file 2>> $log_file
echo "${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}" > ~/.pgpass
if [[ $? -ne 0 ]]; then
_failed=true
fi
echo "" >> $log_file
echo "psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file" >> $log_file
psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
echo "" >> $log_file
echo "rm $_psql_trigger_file" >> $log_file
rm $_psql_trigger_file >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
if $_pgpass_was_present ; then
echo "" >> $log_file
echo "mv \"$_pgppass_back_file\" \"~/.pgpass\"" >> $log_file
mv \"$_pgppass_back_file\" \"~/.pgpass\" >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
fi
if $_failed ; then
echo_failed
erro $(cat $log_file)
else
echo_ok
fi
fi
# - Create postfix trigger function udf_forwarders_in
# -
_trigger_function="udf_forwarders_in"
echononl "\tCreate postfix trigger function $_trigger_function"
if [[ -n "$(su - postgres -c"psql postfix -t -c \"\\df $_trigger_function\"" | awk '{print$3}')" ]]; then
echo_skipped
else
_psql_trigger_file="$(mktemp)"
echo "" > $log_file
echo "cat <<EOF > \$_psql_trigger_file" >> $log_file
echo ".." >> $log_file
echo "EOF" >> $log_file
cat <<EOF > $_psql_trigger_file 2>> $log_file
CREATE FUNCTION udf_forwarders_in(forewarders_str text, email_str text, vacation_domain text, list_seperator character, vacation_enable boolean) RETURNS text
LANGUAGE plpgsql
AS \$\$
DECLARE
return_str text;
local_email_part TEXT;
domain_email_part TEXT;
BEGIN
return_str = email_str;
IF vacation_enable THEN
local_email_part = substring(email_str, 1, position('@' in email_str) - 1);
domain_email_part = substring(email_str, position('@' in email_str) + 1 );
return_str = return_str || list_seperator || local_email_part || '#' || domain_email_part || '@' || vacation_domain;
END IF;
IF char_length(forewarders_str) > 7 THEN
return_str = return_str || list_seperator || forewarders_str;
END IF;
RETURN return_str;
END;
\$\$;
EOF
if [[ $? -ne 0 ]]; then
_failed=true
fi
_pgppass_back_file="~/.pgpass.$backup_date"
_pgpass_was_present=false
if [[ -f "~/.pgpass" ]]; then
_pgpass_was_present=true
echo "" >> $log_file
echo "mv \"~/.pgpass\" \"$_pgppass_back_file\"" >> $log_file
mv "~/.pgpass" "$_pgppass_back_file" >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
fi
echo "" >> $log_file
echo "echo \"${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}\" > ~/.pgpass" >> $log_file 2>> $log_file
echo "${POSTFIX_DB_HOST}:5432:${POSTFIX_DB_NAME}:${POSTFIX_DB_USER}:${POSTFIX_DB_PASSWD}" > ~/.pgpass
if [[ $? -ne 0 ]]; then
_failed=true
fi
echo "" >> $log_file
echo "psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file" >> $log_file
psql -w -U $POSTFIX_DB_USER $POSTFIX_DB_NAME < $_psql_trigger_file >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
echo "" >> $log_file
echo "rm $_psql_trigger_file" >> $log_file
rm $_psql_trigger_file >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
if $_pgpass_was_present ; then
echo "" >> $log_file
echo "mv \"$_pgppass_back_file\" \"~/.pgpass\"" >> $log_file
mv \"$_pgppass_back_file\" \"~/.pgpass\" >> $log_file 2>&1
if [[ $? -ne 0 ]]; then
_failed=true
fi
fi
if $_failed ; then
echo_failed
erro $(cat $log_file)
else
echo_ok
fi
fi
else
echononl "\tCreate function 'FORWARDERS_OUT'"
echo_skipped
echononl "\tCreate function 'FORWARDERS_IN'"
echo_skipped
warn "Create fubctions 'FORWARDERS_OUT' and 'FORWARDERS_IN' not yet implemented"
fi
echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.."
# - zipdownload
# -
_plugin="zipdownload"
add_plugin_arr+=("$_plugin")
echo -e "\n\t\033[32mPlugin '$_plugin'\033[m"
echo -e "\tNothing more to do here. Plugin '$_plugin' will be added to array plugins later.."
echo -e "\n\n\t\033[37m\033[1mActivate Plugins..\033[m"
echo ""
echononl "\tSet a comment bevor existing parameter '$config['plugins']'.."
perl -i -n -p -e "s#(^\s*\\\$config\['plugins'\].*)#//\n// !! Note: This parameter will be overwritten at the end of this file !!\n//\n\1#" $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/config/config.inc.php > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tSet parameter 'config['plugins']' to make plugin's available.."
if [[ ${#add_plugin_arr[@]} -gt 0 ]] ; then
cat <<EOF >>$WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/config/config.inc.php 2> $log_file
// ----------------------------------
// PLUGINS
// ----------------------------------
// List of active plugins (in plugins/ directory)
\$config['plugins'] = array(
EOF
for _plugin in ${add_plugin_arr[@]} ; do
echo " '$_plugin'," >> $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/config/config.inc.php
done
echo ");" >> $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/config/config.inc.php
echo "" >> $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/config/config.inc.php
echo_ok
else
echo_skipped
fi
echo -e "\n\n\t\033[37m\033[1mPost installation tasks\033[m"
echo ""
echononl "\tIndex build-in addressbook"
${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/bin/indexcontacts.sh > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echo ""
echononl "\tRemove installer Folder.."
rm -r $WEBSITE_BASEDIR/roundcubemail-${ROUNDCUBE_VERSION}/installer > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echo ""
clean_up 0