#!/usr/bin/env bash clear echo -e "\n \033[32mStart script for upgrading Roundcube Webmailer..\033[m" CUR_IFS="$IFS" ## ----------------------------------------------------------------- ## ---------------------------------------------------------------- ## --- ## --- For configurations see file conf/install_upgrade_roundcube.conf ## --- ## --- Dont make changes here! ## --- ## ----------------------------------------------------------------- ## ----------------------------------------------------------------- # ------------- # - Settings # ------------- _src_base_dir="$(realpath $(dirname $0))" #conf_file="${_src_base_dir}/conf/install_upgrade_roundcube.conf" script_name="$(basename $(realpath $0))" script_dir="$(dirname $(realpath $0))" conf_dir="${script_dir}/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)" crontab_backup_file="/root/crontab-root.${backup_date}" # ------------- # - 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 "" } 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]*}" ]]) } echo_ok() { echo -e "\033[85G[ \033[32mok\033[m ]" } echo_failed(){ echo -e "\033[85G[ \033[1;31mfailed\033[m ]" } echo_skipped() { echo -e "\033[85G[ \033[30m\033[1mskipped\033[m ]" } echo_not_yet_implemented(){ echo -e "\033[85G[ \033[30m\033[1mnot yet implemented\033[m ]" } detect_mysql_version () { _MYSQLD_VERSION="$(mysqld -V 2>/dev/null)" if [[ -z "$_MYSQLD_VERSION" ]]; then fatal "No installed MySQL server or distribution found!" elif [[ -d "/usr/local/mysql" ]] && [[ "$(basename "$(realpath "/usr/local/mysql")")" =~ percona- ]]; then MYSQL_CUR_DISTRIBUTION="Percona" elif [[ "$_MYSQLD_VERSION" =~ MariaDB ]]; then MYSQL_CUR_DISTRIBUTION="MariaDB" elif [[ "$_MYSQLD_VERSION" =~ MySQL ]]; then MYSQL_CUR_DISTRIBUTION="MySQL" elif [[ -d "/usr/local/mysql" ]] && [[ "$(basename "$(realpath "/usr/local/mysql")")" =~ mysql- ]]; then MYSQL_CUR_DISTRIBUTION="MySQL" elif [[ -d "/usr/local/mysql" ]] && [[ "$(basename "$(realpath "/usr/local/mysql")")" =~ mariadb- ]]; then MYSQL_CUR_DISTRIBUTION="MariaDB" else error "MySQL Instalation found, but cannot determin the distribution!" MYSQL_CUR_DISTRIBUTION= echo "" echo " Select the installed MySQL distribution." echo "" echo " [1] MySQL (the original community edition)" echo " [2] Percona Server for MySQL" echo " [3] MariaDB" echo "" echononl " Eingabe [1/2/3]: " while [ "$MYSQL_CUR_DISTRIBUTION" != "MySQL" -a "$MYSQL_CUR_DISTRIBUTION" != "MariaDB" -a "$MYSQL_CUR_DISTRIBUTION" != "Percona" ];do read OPTION case $OPTION in 1) MYSQL_CUR_DISTRIBUTION="MySQL" ;; 2) MYSQL_CUR_DISTRIBUTION="Percona" ;; 3) MYSQL_CUR_DISTRIBUTION="MariaDB" ;; *) echo "" echo -e "\tFalsche Eingabe ! [ 1 = MySQL ; 2 = Percona ; 3 = MariaDB ]" echo "" echononl " Eingabe:" ;; esac done fi MYSQL_VERSION="$(echo $_MYSQLD_VERSION | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?" | head -n 1)" MYSQL_MAJOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1)" MYSQL_MINOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f2)" MYSQL_PATCH_LEVEL="$(echo $MYSQL_VERSION | cut -d '.' -f3)" MYSQL_MAIN_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1,2)" } trap clean_up SIGHUP SIGINT SIGTERM # - Support systemd ? # - 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 DEFAULT_DB_HOST="localhost" DEFAULT_DB_NAME="roundcubemail" DEFAULT_DB_USER="roundcube" 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) IFS="$CUR_IFS" 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="$CUR_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 IFS="$CUR_IFS" 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 IFS="$CUR_IFS" echo "" echononl " Include Configuration file.." if [[ ! -f $conf_file ]]; then echo_failed fatal "Missing configuration file '$conf_file'" else source $conf_file echo_ok fi [[ -n "$WEBSITE_NAME" ]] || fatal "Website's name (WEBSITE_NAME) not present!" DEFAULT_WEBSITE_BASEDIR="/var/www/${WEBSITE_NAME}" [[ -n "$WEBSITE_BASEDIR" ]] || WEBSITE_BASEDIR=$DEFAULT_WEBSITE_BASEDIR CUR_INSTALL_DIR="$(realpath "${WEBSITE_BASEDIR}/htdocs")" if [[ ! -d "$CUR_INSTALL_DIR" ]] ; then fatal "No current installation of roundcube found!" fi [[ -n "$PHP_DEBIAN_INSTALLATION" ]] || PHP_DEBIAN_INSTALLATION=false [[ -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 "$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 "$MYSQL_DEBIAN_INSTALLATION" ]] || MYSQL_DEBIAN_INSTALLATION=false if [ "$DB_TYPE" = "postgres" -o "$DB_TYPE" = "postgresql" -o "$DB_TYPE" = "pgsql" -o "$DB_TYPE" = "psql" ];then DB_TYPE="pgsql" fi if [[ "$DB_TYPE" = "mysql" ]] ; then if [[ -z ${MYSQL_CREDENTIALS} ]] ; then detect_mysql_version if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MYSQL_MAJOR_VERSION -gt 10 ]] \ || ( [[ $MYSQL_MAJOR_VERSION -eq 10 ]] && [[ $MYSQL_MINOR_VERSION -gt 3 ]] )) ; then if [[ -S "/tmp/mysql.sock" ]]; then MYSQL_CREDENTIALS="-u root -S /tmp/mysql.sock" elif [[ -S "/run/mysqld/mysqld.sock" ]]; then MYSQL_CREDENTIALS="-u root -S /run/mysqld/mysqld.sock" elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then MYSQL_CREDENTIALS="-u root -S /var/run/mysqld/mysqld.sock" else fatal "Parameter 'MYSQL_CREDENTIALS' cannot be determined automated. Use configuration file "$conf_file" to set parameter manually." fi else echononl "\tGet MySQL command.." mysql_command="$(which mysql)" if [[ $? -eq 0 ]]; then echo_ok else if [[ -x "/usr/local/mysql/bin/mysql" ]]; then mysql_command="/usr/local/mysql/bin/mysql" echo_ok else echo_failed fatal "$(cat $tmp_log_file)" fi fi if $(${mysql_command} --login-path=local -e ";" > /dev/null 2>&1) ; then MYSQL_CREDENTIALS="--login-path=local" elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then MYSQL_CREDENTIALS="--defaults-file=/usr/local/mysql/sys-maint.cnf" elif [[ -f "/etc/mysql/debian.cnf" ]] ; then MYSQL_CREDENTIALS="--defaults-file=/etc/mysql/debian.cnf" else fatal "Parameter 'MYSQL_CREDENTIALS' cannot be determined automated. Use configuration file "$conf_file" to set parameter manually." fi fi #if $MYSQL_DEBIAN_INSTALLATION ; then # [[ -n "$MYSQL_CREDENTIALS" ]] || MYSQL_CREDENTIALS="$DEFAULT_DEBIAN_MYSQL_CREDENTIALS" #else # [[ -n "$MYSQL_CREDENTIALS" ]] || MYSQL_CREDENTIALS="$DEFAULT_MYSQL_CREDENTIALS" #fi fi else #[[ "$POSTFIX_DB_TYPE" = "pgsql" ]] || fatal "Unknown Database Type '$POSTFIX_DB_TYPE' (POSTFIX_DB_TYPE)" [[ "$DB_TYPE" = "pgsql" ]] || fatal "Unknown Database Type '$DB_TYPE' (DB_TYPE)" fi if [[ "$DB_TYPE" = "mysql" ]]; then echononl " Get MySQL command.." mysql_command="$(which mysql)" if [[ $? -eq 0 ]]; then echo_ok else if [[ -x "/usr/local/mysql/bin/mysql" ]]; then mysql_command="/usr/local/mysql/bin/mysql" echo_ok else echo_failed fatal "$(cat $tmp_log_file)" fi fi elif [[ "$DB_TYPE" = "pgsql" ]] ; then echononl " Get PostgreSQL command.." psql_command="$(which psql)" if [[ $? -eq 0 ]]; then echo_ok else echo_failed fi 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 "" NEW_INSTALL_DIR="${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" if [[ "$NEW_INSTALL_DIR" = "$CUR_INSTALL_DIR" ]] ; then warn "Version '${ROUNDCUBE_VERSION}' is already installed" echononl "Type uppercase \"yes\" to proceed with upgrading: " read _proceed [[ "${_proceed^^}" = "YES" ]] || fatal "Exiting by user request.." fi # - Determin PHP of all installed versions # - if $PHP_DEBIAN_INSTALLATION ; then echononl " Get get major version 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 version numbers of installed PHP versions failed! No installed PHP versiond found!" else echo_ok fi else echononl " Get 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 version numbers of installed PHP versions failed! No installed PHP versiond found!" else echo_ok fi IFS="$CUR_IFS" 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 # - Get activ PHP version, means that on which is part of $PATH environment # - echononl "\tGet PHP version in PATH environment.." if $(which php > /dev/null 2>&1) ; then php_version_in_path="$(php --version 2> /dev/null | head -1 | cut -d' ' -f2 | cut -d '-' -f1 2> /dev/null)" if [[ $? -eq 0 ]] && [[ -n "${php_version_in_path}" ]]; then echo_ok else echo_failed fatal "Failed getting PHP Version.." fi else echo_skipped fatal "No PHP binary found in PATH environment.." fi # - Log directory containing upgrade log files # - _log_dir=${script_dir}/log-upgrade-roundcube-${ROUNDCUBE_VERSION} echo "" echo "" echo -e "\033[1;32mSettings for upgrading \033[1;37mRoundcube Webmail\033[m" echo "" echo -e "\tRoundcube Version....................: $ROUNDCUBE_VERSION" echo "" echo -e "\tName of the Website..................: $WEBSITE_NAME" 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 [[ "$POSTFIX_DB_TYPE" = "mysql" ]]; then echo -e "\tDatabase type of Postfix Database....: MySQL" echo -e "\tMySQL from Debian Package System.....: $MYSQL_DEBIAN_INSTALLATION" else echo -e "\tDatabase type of Postfix Database....: PostgreSQL" fi echo -e "\tHost of Roundcube Database...........: $POSTFIX_DB_HOST" echo -e "\tName of Roundcube Database...........: $POSTFIX_DB_NAME" echo -e "\tUser of Roundcube Database...........: $POSTFIX_DB_USER" echo -e "\tPassword of Roundcube Database.......: $POSTFIX_DB_PASSWD" if [[ "$DB_TYPE" = "mysql" ]]; then echo -e "\tMySQL Credentials (root access)......: $MYSQL_CREDENTIALS" fi 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" echo -e "\tPHP Version of php binary in PATH....: $php_version_in_path" fi echo "" echo -e "\tCrontab backup file..................: $crontab_backup_file" echo "" echo -n "Type upper case 'YES' to continue executing with this parameters: " read OK if [[ "$OK" = "YES" ]] ; then echo "" echo "" echo -e " \033[1;32mGoing to upgrade Roundcube Webmailer \033[1;37m$network \033[m" echo "" else fatal "Abort by user request - Answer as not 'YES'" fi echononl "\tCheck Database connection .." if [[ "$DB_TYPE" = "mysql" ]]; then ${mysql_command} $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 if [[ "$?" = "0" ]]; then echo_ok else echo_failed error "$(cat $log_file)" echononl "continue anyway [yes/no]: " read OK OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Abbruch durch User" fi elif [[ "$DB_TYPE" = "pgsql" ]]; then count=$(su - postgres -c "${psql_command} -q -A -t -l" | grep -c -e "^$DB_NAME") if [[ $count -eq 0 ]];then echo_failed error "$(cat $log_file)" echononl "continue anyway [yes/no]: " read OK OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Abbruch durch User" else echo_ok fi else fatal "Cannot detect database type (value of DB_TYPE is neither 'mysql' nor 'pgsql')" fi echononl "\tInstall/Update composer to /usr/local/bin" echononl "\tDownload composer from 'getcomposer.org'.." php -r "copy('https://getcomposer.org/installer', '${script_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 ${script_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 \033[37m\033[1mCreate some Backups..\033[m\n" echononl " Backup existing upgrade log directory \033[37m\033[1m$(basename "${_log_dir}")\033[m" if [[ -d "${_log_dir}" ]] ; then mv "${_log_dir}" "${_log_dir}.${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 " Backup existing Database '$DB_NAME'" if [[ "$DB_TYPE" = "mysql" ]]; then echo -n " (MySQL).." mysqldump $MYSQL_CREDENTIALS --opt $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 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 echononl " Backup existing Database '$POSTFIX_DB_NAME'" if [[ "$POSTFIX_DB_TYPE" = "mysql" ]]; then echo -n " (MySQL).." mysqldump $MYSQL_CREDENTIALS --opt $POSTFIX_DB_NAME > ${WEBSITE_BASEDIR}/${POSTFIX_DB_NAME}.$backup_date.sql 2> $log_file if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi elif [[ "$POSTFIX_DB_TYPE" = "pgsql" ]]; then echo -n " (PostgreSQL).." su - postgres -c "pg_dump -c $POSTFIX_DB_NAME" > ${WEBSITE_BASEDIR}/${POSTFIX_DB_NAME}.$backup_date.sql 2> $log_file if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi fi echononl " Backup existing web-directory .." if [[ -d "$CUR_INSTALL_DIR" ]]; then mv "$CUR_INSTALL_DIR" "${CUR_INSTALL_DIR}.$backup_date" > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi else fatal "No current installation of roundcube found!" fi echo -e "\n\n \033[37m\033[1mDownloud/Unpack source archive..\033[m\n" echononl " Download 'roundcubemail-${ROUNDCUBE_VERSION}'.." if [[ ! -f "$script_dir/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz" ]]; then wget -O ${script_dir}/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz https://github.com/roundcube/roundcubemail/releases/download/${ROUNDCUBE_VERSION}/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi else echo_skipped fi echononl " Remove existing source directory" if [[ -d "${script_dir}/roundcubemail-${ROUNDCUBE_VERSION}" ]]; then rm -rf "${script_dir}/roundcubemail-${ROUNDCUBE_VERSION}" > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi else echo_skipped fi echononl " Unpack roundcube source archive.." gunzip < ${script_dir}/roundcubemail-${ROUNDCUBE_VERSION}.tar.gz | tar -C ${script_dir} -xf - > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi echo -e "\n\n \033[37m\033[1mSome pre-installation tasks..\033[m\n" ## - Disable crontab for user root ## - echononl " Backup crontab" crontab -u root -l >> $crontab_backup_file 2> $log_file if [[ "$?" = "0" ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi echononl " Disable crontab for user root" crontab -r -u root > $log_file 2>&1 if [[ "$?" = "0" ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi echononl " Stop Apache Webserver.." if [[ -n "$APACHE_SERVICE_FILE" ]] || [[ -n "$APACHE_INIT_SCRIPT" ]] ; then if [[ -n "$APACHE_SERVICE_FILE" ]] ; then systemctl stop $APACHE_SERVICE_FILE > $log_file 2>&1 else $APACHE_INIT_SCRIPT stop > $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 # - Stop all PHP FPM engines # - if [[ -n "$php_major_versions" ]]; then for _ver in $php_major_versions ; do echononl " Stop PHP FPM engine v${_ver}.." if [[ -f "/etc/init.d/php-${_ver}-fpm" ]]; then /etc/init.d/php-${_ver}-fpm stop > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi elif [[ -f "/etc/systemd/system/php-${_ver}-fpm.service" ]] ; then systemctl stop php-${_ver}-fpm > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi else echo_skipped fi done else if $PHP_DEBIAN_INSTALLATION ; then echononl " Stop PHP FPM engine v${php_major_version}.." if [[ -f "/etc/init.d/php$(echo $php_major_version | cut -d'.' -f1)-fpm" ]] ; then /etc/init.d/php$(echo $php_major_version | cut -d'.' -f1)-fpm stop > $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 fi echo -e "\n\n \033[37m\033[1mUgrade Roundcube Webmail..\033[m\n" echononl " Copy current web-directory into a the new one.." cp -a "${CUR_INSTALL_DIR}.$backup_date" "${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi echononl " Set actual timestamp to the new web-directory" touch -t "$(date +%Y%m%d%H%M.%S)" "${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi echononl " Change into new roundcube source directory" cd "${script_dir}/roundcubemail-${ROUNDCUBE_VERSION}" > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi echononl " Create log-directory for update log file" if [[ ! -d "${_log_dir}" ]]; then mkdir "${_log_dir}" > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi else echo_skipped 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 ${script_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('${script_dir}/composer-setup.php');" > $log_file 2>&1 if [[ "$?" = "0" ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi echo "" echo " Update the the roundcube web-directory to version '${ROUNDCUBE_VERSION}'" echononl " See: ${_log_dir}/update_roundcube-${ROUNDCUBE_VERSION}.${backup_date}.log" echo "y" | ${script_dir}/roundcubemail-${ROUNDCUBE_VERSION}/bin/installto.sh "${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" > ${_log_dir}/update_roundcube-${ROUNDCUBE_VERSION}.${backup_date}.log 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fi echo "" echononl " Change into new roundcube web directory" cd "${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}" > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed fatal "$(cat $log_file)" fi echo "" echo "" echo "You might want to deactivate some plugins in the configuration file, e.g. the plugin 'carddav'.." echo "" echononl "continue [yes/no]: " read OK OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Abbruch durch User" echononl " Update dependencies by running 'php composer.phar update --no-dev'" php composer.phar --no-interaction update --no-dev > ${_log_dir}/update_roundcube-${ROUNDCUBE_VERSION}-dependencies.${backup_date}.log 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "command was:\n\t # cd "${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}"\n\t #php composer.phar --no-interaction update --no-dev\n\n$(cat ${_log_dir}/update_roundcube-${ROUNDCUBE_VERSION}-dependencies.${backup_date}.log)" echononl "continue anyway [yes/no]: " read OK OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Abbruch durch User" fi echononl " Index 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 "command was:\n\t # ${WEBSITE_BASEDIR}/roundcubemail-${ROUNDCUBE_VERSION}/bin/indexcontacts.sh\n\n$(cat $log_file)" echononl "continue anyway [yes/no]: " read OK OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do echononl "Wrong entry! - repeat [yes/no]: " read OK done [[ $OK = "yes" ]] || fatal "Abbruch durch User" fi _failed=false echononl " Symlink DocumentRoot to the new installation directory.." if [[ -h "${WEBSITE_BASEDIR}/htdocs" ]]; then rm "${WEBSITE_BASEDIR}/htdocs" > $log_file 2>&1 if [[ $? -ne 0 ]]; then _failed=true fi elif [[ -f "${WEBSITE_BASEDIR}/htdocs" ]]; then mv "${WEBSITE_BASEDIR}/htdocs" "${WEBSITE_BASEDIR}/htdocs/.$backup_date" > $log_file 2>&1 if [[ $? -ne 0 ]]; then _failed=true fi fi ln -s "roundcubemail-${ROUNDCUBE_VERSION}" "${WEBSITE_BASEDIR}/htdocs" >> $log_file 2>&1 if [[ $? -ne 0 ]]; then _failed=true fi if $_failed ; then echo_failed error "$(cat $log_file)" else echo_ok fi echo -e "\n\n \033[37m\033[1mSome post-installation tasks..\033[m\n" # - Start all PHP FPM engines # - if [[ -n "$php_major_versions" ]]; then for _ver in $php_major_versions ; do echononl " Start PHP FPM engine v${_ver}.." if [[ -f "/etc/init.d/php-${_ver}-fpm" ]]; then /etc/init.d/php-${_ver}-fpm start > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi elif [[ -f "/etc/systemd/system/php-${_ver}-fpm.service" ]] ; then systemctl start php-${_ver}-fpm > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi else echo_skipped fi done else if $PHP_DEBIAN_INSTALLATION ; then echononl " Start PHP FPM engine v${php_major_version}.." if [[ -f "/etc/init.d/php$(echo $php_major_version | cut -d'.' -f1)-fpm" ]] ; then /etc/init.d/php$(echo $php_major_version | cut -d'.' -f1)-fpm start > $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 fi # - Start Apache Webserver # - echononl " Start Apache Webserver.." if [[ -n "$APACHE_SERVICE_FILE" ]] || [[ -n "$APACHE_INIT_SCRIPT" ]] ; then if [[ -n "$APACHE_SERVICE_FILE" ]] ; then systemctl start $APACHE_SERVICE_FILE > $log_file 2>&1 else $APACHE_INIT_SCRIPT start > $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 echononl " Renstall previously saved crontab from '$crontab_backup_file'.." crontab $crontab_backup_file > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi echononl " Delete previously saved crontab file '$crontab_backup_file'.." rm "$crontab_backup_file" > $log_file 2>&1 if [[ $? -eq 0 ]]; then echo_ok else echo_failed error "$(cat $log_file)" fi echo "" clean_up 0