mailsystem/install_roundcube.sh

3435 lines
105 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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))"
script_name="$(basename $(realpath $0))"
script_dir="$(dirname $(realpath $0))"
conf_dir="${script_dir}/conf"
#conf_file="${_src_base_dir}/conf/install_upgrade_roundcube.conf"
declare -a unsorted_website_arr
declare -a website_arr
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 ]"
}
is_number() {
return $(test ! -z "${1##*[!0-9]*}" > /dev/null 2>&1);
# - also possible
# -
#[[ ! -z "${1##*[!0-9]*}" ]] && return 0 || return 1
#return $([[ ! -z "${1##*[!0-9]*}" ]])
}
trim() {
local var="$*"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
echo -n "$var"
}
trap clean_up SIGHUP SIGINT SIGTERM
# - Is 'systemd' supported on this system
# -
systemd_supported=false
systemd=$(which systemd)
systemctl=$(which systemctl)
if [[ -n "$systemd" ]] && [[ -n "$systemctl" ]] ; then
systemd_supported=true
fi
# - Look for systemd service file or sysv init script for apache2 webservice
# -
APACHE_SERVICE_FILE=""
APACHE_INIT_SCRIPT=""
if $systemd_supported ; then
# - Is Service exclusive controlled by systemd
# -
if systemctl -t service list-unit-files \
| grep -e "^apache2.service" \
| grep -q -E "(enabled|disabled)" 2> /dev/null ; then
APACHE_SERVICE_FILE=$(systemctl -t service list-unit-files \
| grep -e "^apache2.service" \
| awk '{print$1}')
fi
fi
if [[ -z "$APACHE_SERVICE_FILE" ]] ; then
if [ -x "/etc/init.d/apache2" ]; then
APACHE_INIT_SCRIPT="/etc/init.d/apache2"
elif [ -x "/etc/init.d/apachectl" ]; then
APACHE_INIT_SCRIPT="/etc/init.d/apachectl"
fi
fi
while IFS='' read -r -d '' _conf_file ; do
WEBSITE_NAME="$(grep -E "^WEBSITE_NAME" "${_conf_file}" 2>/dev/null | cut -d"=" -f2)"
#Remove leading / trailling double quotes
WEBSITE_NAME="${WEBSITE_NAME#"${WEBSITE_NAME%%[!\"]*}"}"
WEBSITE_NAME="${WEBSITE_NAME%"${WEBSITE_NAME##*[!\"]}"}"
#Remove leading / trailling single quotes
WEBSITE_NAME="${WEBSITE_NAME#"${WEBSITE_NAME%%[!\']*}"}"
WEBSITE_NAME="${WEBSITE_NAME%"${WEBSITE_NAME##*[!\']}"}"
#Remove leading / trailling space
WEBSITE_NAME="${WEBSITE_NAME#"${WEBSITE_NAME%%[![:space:]]*}"}"
WEBSITE_NAME="${WEBSITE_NAME%"${WEBSITE_NAME##*[![:space:]]}"}"
if [[ -n "$WEBSITE_NAME" ]] ; then
unsorted_website_arr+=("${WEBSITE_NAME}:$_conf_file")
fi
WEBSITE_NAME=""
done < <(find "${conf_dir}" -maxdepth 1 -type f -name "install_upgrade_roundcube*.conf" -print0)
if [[ ${#unsorted_website_arr} -eq 0 ]]; then
fatal "No configuration files found in '${script_dir}/conf' or no website configured!"
fi
# - Sort array
# -
IFS=$'\n' website_arr=($(sort <<<"${unsorted_website_arr[*]}"))
IFS=' '
WEBSITE_NAME=
_OK=false
echo ""
echo "Which site would you like to update?"
echo ""
declare -i i=0
for _site in ${website_arr[@]} ; do
IFS=':' read -a _arr <<< ${_site}
echo " [$i] ${_arr[0]}"
((i++))
done
echo
echononl " Eingabe: "
while ! $_OK ; do
read _IN
if is_number "$_IN" && [[ -n ${website_arr[$_IN]} ]]; then
IFS=':' read -a _arr <<< ${website_arr[$_IN]}
conf_file=${_arr[1]}
_OK=true
else
echo ""
echo -e "\tFalsche Eingabe !"
echo ""
echononl " Eingabe: "
fi
done
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 ""
VACATION_PLUGIN=false
VACATION_SIEVE=false
_OK=false
echo ""
echo "With which method should an E-Mail Responder be realized?"
echo ""
echo " [1] Plugin 'vacation'"
echo " [2] With a sive script using managesieve plugin"
echo ""
echononl " Eingabe: "
while ! $_OK ; do
read _IN
if is_number "$_IN" && ( [[ $_IN -eq 1 ]] || [[ $_IN -eq 2 ]] ) ; then
if [[ $_IN -eq 1 ]] ; then
VACATION_PLUGIN=true
VACATION_SIEVE=false
else
VACATION_PLUGIN=false
VACATION_SIEVE=true
fi
_OK=true
else
echo ""
echo -e "\tFalsche Eingabe !"
echo ""
echononl " Eingabe: "
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_SKIN_LOGO="images/oopen-logo.png"
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"
if [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then
DEFAULT_MYSQL_CREDENTIALS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
elif [[ -f "/etc/mysql/debian.cnf" ]] ; then
DEFAULT_MYSQL_CREDENTIALS="--defaults-file=/etc/mysql/debian.cnf"
else
DEFAULT_MYSQL_CREDENTIALS=""
fi
DEFAULT_DEBIAN_MYSQL_CREDENTIALS="--defaults-file=/etc/mysql/debian.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##*.}
HOSTNAME_SHORT=${_tmp_string%%.*}
[[ -n "$WEBMASTER_EMAIL" ]] || WEBMASTER_EMAIL="admin@${MAIN_DOMAIN}.$TLD"
[[ -n "$ROUNDCUBE_TMPDIR" ]] || ROUNDCUBE_TMPDIR="$DEFAULT_ROUNDCUBE_TMPDIR"
[[ -n "$SKIN_LOGO" ]] || SKIN_LOGO="$DEFAULT_SKIN_LOGO"
if [[ -z "$IPV4" ]] && [[ -z "$IPV6" ]] ; then
fatal "Neither an IPv4 nor an IPv6 address are given.!"
else
[[ -n "$IPV4" ]] || warn "IPv4 Address not present!"
[[ -n "$IPV6" ]] || warn "IPv6 Address not present!"
fi
[[ -n "$APACHE_DEBIAN_INSTALLATION" ]] || APACHE_DEBIAN_INSTALLATION=false
[[ -n "$PHP_DEBIAN_INSTALLATION" ]] || PHP_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 '"'`"
# - 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 "$HTTP_USER" ]] || HTTP_USER=$DEFAULT_HTTP_USER
[[ -n "$HTTP_GROUP" ]] || HTTP_GROUP=$DEFAULT_HTTP_GROUP
[[ -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=12
[[ -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="{SHA512-CRYPT}"
[[ -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='SHA512-CRYPT'
# - Plugin vacation
# -
[[ -n "$VAC_GUI_FORWARDER" ]] || VAC_GUI_FORWARDER=false
# - Determin PHP of all installed versions
# -
if $PHP_DEBIAN_INSTALLATION ; then
echononl "\tGet major version of installed PHP"
php_major_version="$(php --version | head -1 | cut -d' ' -f2 | cut -d '-' -f1 | cut -d'.' -f1,2)"
if [[ -z "$php_major_version" ]]; then
echo_failed
error "Getting major version of installed PHP versions failed! No installed PHP versiond found!"
else
echo_ok
fi
else
echononl "\tGet major version of all installed PHP versions"
IFS=$'\n' 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
fi
# - Get the latest PHP version
# -
echononl "\tGet major version of latest installed PHP version"
php_latest_ver=""
if $PHP_DEBIAN_INSTALLATION ; then
echo_skipped
else
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
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 ""
if $PHP_DEBIAN_INSTALLATION ; then
echo -e "\tInstalled PHP version................: $php_major_version"
else
declare -i index=1
for _ver in $php_major_versions ; do
if [[ $index -eq 1 ]] ; then
echo -en "\tInstalled PHP versions...............: $_ver"
else
echo -en " $_ver"
fi
((index++))
done
echo ""
echo -e "\tNewest PHP Version...................: $php_latest_ver"
fi
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 ""
if $VACATION_PLUGIN ; then
echo -e "\tUse 'vacation'-plugin................: $VACATION_PLUGIN"
echo -e "\tHostname for Vacation Messages.......: $AUTOREPLY_HOSTNAME"
fi
if $VACATION_SIEVE ; then
echo -e "\tUse sieve script as autoresponder....: $VACATION_SIEVE"
fi
echo ""
echo -e "\tName of Junk Folder..................: $SPAM_FOLDER_NAME"
echo ""
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)
declare -a needed_php_pear_module_arrs=()
_needed_php_pear_modules="
MDB2
Mail_Mime
Mail_mimeDecode
Net_SMTP
Net_IDNA2
Auth_SASL
"
for _module in $_needed_php_pear_modules ; do
[[ -n "$(trim $_module)" ]] && needed_php_pear_module_arrs+=("$(trim $_module)")
_module="$(trim $_module)"
needed_php_pear_modules="$needed_php_pear_modules $_module"
done
if [[ "$DB_TYPE" = "pgsql" ]]; then
needed_php_pear_module_arrs+=("MDB2_Driver_pgsql")
needed_php_pear_modules="$needed_php_pear_modules MDB2_Driver_pgsql"
else
needed_php_pear_module_arrs+=("MDB2_Driver_mysql")
needed_php_pear_module_arrs+=("MDB2_Driver_mysqli")
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/..)
## -
echo -e "\n\n\t\033[37m\033[1mInstall modules for PHP Version ${_version}..\033[m\n"
if $PHP_DEBIAN_INSTALLATION ; then
echononl "\tUpdate protocols of channel \"pear.php.net\" .."
pear channel-update pear.php.net > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
#for _module in $needed_php_pear_modules ; do
for _module in "${needed_php_pear_module_arrs[@]}" ; do
_module="$(trim $_module)"
echononl "\tInstall Module '$_module'.."
if ! pear list | grep -q "$_module" 2> /dev/null ; then
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 .."
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
else
for _version in $php_major_versions ; do
echononl "\tUpdate protocols of channel \"pear.php.net\" .."
pear channel-update pear.php.net > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
#for _module in $needed_php_pear_modules ; do
for _module in "${needed_php_pear_module_arrs[@]}" ; do
_module="$(trim $_module)"
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
fi
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 [[ ! -s "$_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
fatal "$(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 "\tChange ownership of ${HTTP_USER}'s home directory"
if [[ "$(stat -c "%U" "/var/www")" != "$HTTP_USER" ]]; then
chown $HTTP_USER:${HTTP_GROUP} "/var/www" > $log_file 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
echononl "\tInstall PHP dependencies.."
if $PHP_DEBIAN_INSTALLATION ; then
su ${HTTP_USER} -c"cd ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}
php /usr/local/bin/composer install --no-interaction --no-dev" -s /bin/bash \
> $log_file 2>&1
else
su ${HTTP_USER} -c"cd ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}
/usr/local/php-${php_latest_ver}/bin/php /usr/local/bin/composer --no-interaction install --no-dev" -s /bin/bash \
> $log_file 2>&1
fi
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 * * * su - www-data -c \"${WEBSITE_BASEDIR}/htdocs/bin/cleandb.sh > /dev/null\" -s /bin/bash" >> /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
_create_vhost_config=true
if [[ -n "$IPV6" ]] && [[ -n "$IPV4" ]] ; then
_vhost_ip_string_80="$IPV4:80 [$IPV6]:80"
_vhost_ip_string_443="$IPV4:443 [$IPV6]:443"
elif [[ -n "$IPV4" ]] ; then
_vhost_ip_string_80="$IPV4:80"
_vhost_ip_string_443="$IPV4:443"
elif [[ -n "$IPV6" ]] ; then
_vhost_ip_string_80=" [$IPV6]:80"
_vhost_ip_string_443=" [$IPV6]:443"
else
echo_failed
error "Neither an ipv4 nor an ipv6 address are given.!"
_create_vhost_config=false
fi
if $_create_vhost_config ; then
cat <<EOF > ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
# -- $WEBSITE_NAME -- #
<VirtualHost ${_vhost_ip_string_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 ${_vhost_ip_string_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$>
EOF
if $PHP_DEBIAN_INSTALLATION ; then
php_socket_file="/run/php/php${php_major_version}-fpm.sock"
if [[ -S "/run/php$(echo $php_major_version | cut -d'.' -f1)-fpm.sock" ]]; then
php_socket_file="/run/php$(echo $php_major_version | cut -d'.' -f1)-fpm.sock"
fi
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
SetHandler "proxy:unix:${php_socket_file}|fcgi://127.0.0.1"
EOF
else
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
SetHandler "proxy:unix:/run/php/php-${php_latest_ver}-fpm.www.sock|fcgi://127.0.0.1"
EOF
fi
cat <<EOF >> ${APACHE_VHOST_DIR}/${WEBSITE_NAME}.conf 2>> $log_file
</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
# ==========
# - HTTP security Headers
# ==========
# - X-Frame-Options
# -
# - The X-Frame-Options header (RFC), or XFO header, protects your visitors
# - against clickjacking attacks. An attacker can load up an iframe on their
# - site and set your site as the source, it's quite easy:
# -
# - <iframe src="https://scotthelme.co.uk"></iframe>
# -
# - Using some crafty CSS they can hide your site in the background and create some
# - genuine looking overlays. When your visitors click on what they think is a harmless
# - link, they're actually clicking on links on your website in the background. That
# - might not seem so bad until we realise that the browser will execute those requests
# - in the context of the user, which could include them being logged in and authenticated
# - to your site!
# -
# - Troy Hunt has a great blog on 'Clickjack attack the hidden threat right in front :
# - of you':
# -
# - http://www.troyhunt.com/2013/05/clickjack-attack-hidden-threat-right-in.html
# -
# - Valid values include DENY meaning your site can't be framed, SAMEORIGIN which allows
# - you to frame your own site or ALLOW-FROM https://example.com/ which lets you specify
# -sites that are permitted to frame your own site.
# -
Header always set X-Frame-Options "SAMEORIGIN"
# - X-Xss-Protection
# -
# - This header is used to configure the built in reflective XSS protection found
# - in Internet Explorer, Chrome and Safari (Webkit). Valid settings for the header
# - are 0, which disables the protection, 1 which enables the protection
# - and 1; mode=block which tells the browser to block the response if it
# - detects an attack rather than sanitising the script.
# -
Header always set X-Xss-Protection "1; mode=block"
# - X-Content-Type-Options
# -
# - Nice and easy to configure, this header only has one valid value, nosniff.
# - It prevents Google Chrome and Internet Explorer from trying to mime-sniff
# - the content-type of a response away from the one being declared by the server.
# - It reduces exposure to drive-by downloads and the risks of user uploaded content
# - that, with clever naming, could be treated as a different content-type, like
# - an executable.
# -
Header always set X-Content-Type-Options "nosniff"
# - Content Security Policy
# -
# - The CSP header allows you to define a whitelist of approved sources of content
# - for your site. By restricting the assets that a browser can load for your site,
# - like js and css, CSP can act as an effective countermeasure to XSS attacks. I
# - have covered CSP in a lot more detail in my blog Content Security Policy - An
# - Introduction (https://scotthelme.co.uk/content-security-policy-an-introduction/).
# -
# - Here is a basic policy to enforce TLS on all assets and prevent
# - mixed content warnings.
# -
# - Allow Google Analytics, Google AJAX CDN and Same Origin
# - script-src 'self' www.google-analytics.com ajax.googleapis.com;
# -
# - Emmbedding Google Fonts
# - style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
# -
# - Allow YouTube Videos (iframe embedded)
# - frame-src 'self' https://www.youtube.com
# -
#Header always set Content-Security-Policy "default-src https: data: 'unsafe-inline' 'unsafe-eval' ; object-src 'none'"
Header always set Content-Security-Policy "default-src 'none'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' ; img-src 'self' data: https: ; connect-src 'self'; font-src 'self'; object-src 'self'; media-src 'self' ; frame-src 'self'; worker-src 'self'; form-action 'self'; base-uri 'self'; frame-ancestors 'self'; upgrade-insecure-requests"
# - Referrer-Policy
# -
# - The HTTP referer (originally a misspelling of referrer[1]) is an HTTP header
# - field that identifies the address of the webpage (i.e. the URI or IRI) that
# - linked to the resource being requested. By checking the referrer, the new
# - webpage can see where the request originated.
# -
Header set Referrer-Policy "strict-origin-when-cross-origin"
# - 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"
SSLEngine on
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
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
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 [[ -n "$APACHE_SERVICE_FILE" ]] || [[ -n "$APACHE_INIT_SCRIPT" ]] ; then
if [[ -n "$APACHE_SERVICE_FILE" ]] ; then
systemctl restart $APACHE_SERVICE_FILE > $log_file 2>&1
echo "systemctl restart $APACHE_SERVICE_FILE > $log_file 2>&1"
else
$APACHE_INIT_SCRIPT restart > $log_file 2>&1
fi
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
warn "Neither an init-script nor a service file for 'apache2' webservice found!"
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.."
cat <<EOF > /etc/logrotate.d/roundcube-${HOSTNAME_SHORT} 2> $log_file
$WEBSITE_BASEDIR/logs/*.log {
daily
start 0
rotate 7
missingok
notifempty
compress
delaycompress
create 640 www-data www-data
copytruncate
postrotate
# Maybe apache2 logrotating sets wron file permissions..
#
if ls /var/www/${WEBSITE_BASEDIR}/logs/*.log > /dev/null 2>&1 ; then
chown www-data:www-data /var/www/${WEBSITE_BASEDIR}/logs/*.log
fi
endscript
}
EOF
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
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 $MYSQL_CREDENTIALS -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 $MYSQL_CREDENTIALS -N -s -e \
"GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASS'"
if [[ $? -ne 0 ]]; then
_failed=true
fi
mysql $MYSQL_CREDENTIALS -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 $MYSQL_CREDENTIALS --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_host..............: tls://$(hostname -f):587
smtp_user/smtp_pass....:
[x] 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
// ==================================
\$config['skin_logo'] = '${SKIN_LOGO}';
// use this folder to store log files
// must be writeable for the user who runs PHP process (Apache user if mod_php is being used)
// This is used by the 'file' log driver.
\$config['log_dir'] = '${WEBSITE_BASEDIR}/logs';
// Location of temporary saved files such as attachments and cache files
// must be writeable for the user who runs PHP process (Apache user if mod_php is being used)
\$config['temp_dir'] = '${ROUNDCUBE_TMPDIR}';
// provide an URL where a user can get support for this Roundcube installation
// PLEASE DO NOT LINK TO THE ROUNDCUBE.NET WEBSITE HERE!
\$config['support_url'] = '${SUPPORT_URL}';
// 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;
// ----------------------------------
// SMTP
// ----------------------------------
// SMTP server host (and optional port number) for sending mails.
// Enter hostname with prefix ssl:// to use Implicit TLS, or use
// prefix tls:// to use STARTTLS.
// If port number is omitted it will be set to 465 (for ssl://) or 587 otherwise.
// Supported replacement variables:
// %h - user's IMAP hostname
// %n - hostname (\$_SERVER['SERVER_NAME'])
// %t - hostname without the first part
// %d - domain (http hostname \$_SERVER['HTTP_HOST'] without the first part)
// %z - IMAP domain (IMAP hostname without the first part)
// For example %n = mail.domain.tld, %t = domain.tld
// To specify different SMTP servers for different IMAP hosts provide an array
// of IMAP host (no prefix or port) and SMTP server e.g. ['imap.example.com' => 'smtp.example.net']
\$config['smtp_host'] = 'tls://$(hostname -f):587';
// SMTP username (if required) if you use %u as the username Roundcube
// will use the current username for login
\$config['smtp_user'] = '%u';
// SMTP password (if required) if you use %p as the password Roundcube
// will use the current user's password for login
\$config['smtp_pass'] = '%p';
// ----------------------------------
// IMAP (further settings)
// ----------------------------------
// Log successful/failed logins to <log_dir>/userlogins or to syslog
\$config['log_logins'] = true;
// IMAP AUTH type (DIGEST-MD5, CRAM-MD5, LOGIN, PLAIN or null to use
// best server supported one)
\$config['imap_auth_type'] = 'LOGIN';
// ----------------------------------
// 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"
# - Synchronise package index files with the repository
# -
echononl "\tSynchronise package index files with the repository.."
apt-get update > "$log_file" 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
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
_pkg="$(trim $_pkg)"
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-contextmenu-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-contextmenu-master.zip > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCeate Symlink '$_plugin' in plugin folder.."
ln -s roundcube-contextmenu-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 '$_plugin' 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
_key="managesieve_vacation"
if $VACATION_SIEVE ; then
_val="2"
else
_val="0"
fi
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_vacation_interval"
_val="1"
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-markasjunk2-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-markasjunk2-master.zip > $log_file 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
echononl "\tCeate Symlink '$_plugin' in plugin folder.."
ln -s roundcube-markasjunk2-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
# -
if $VACATION_PLUGIN ; then
_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 '$_plugin' 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
error $(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
chmod 600 ~/.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
error $(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
chmod 600 ~/.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
error $(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
chmod 600 ~/.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
error $(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 functions '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.."
fi # if $VACATION_PLUGIN
# - 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