#!/bin/bash # # vmail-webmail # https://git.stack-source.com/msb/vmail-webmail # Copyright (c) 2022 Matthew Saunders Brown # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # # must be root if [ "${EUID}" -ne 0 ]; then echo "You must be root to run this installer." exit fi # Check for vmail-stack & vhost-stack installs & required configs if [ -f "/usr/local/bin/vhost.sh" ] && [ -d "/srv/www/html" ] && [ -f "/usr/local/bin/vmail.sh" ] && [ -f "/var/vmail/.my.cnf" ]; then # check for existing roundcube webmail install if [ -d "/srv/www/html/roundcube" ]; then echo "Roundcube webmail app is already installed." exit fi else echo "Missing required installs/configurations." echo "You must install vhost-stack & vmail-stack first." exit fi # get current working dir, so we can come back here later installer_dir=$(dirname $(readlink -f $0)) cd /usr/local/src/ wget https://github.com/roundcube/roundcubemail/releases/download/1.6.7/roundcubemail-1.6.7-complete.tar.gz tar zxf roundcubemail-1.6.7-complete.tar.gz mv roundcubemail-1.6.7 /srv/www/html/roundcube cd /usr/local/src/ wget https://github.com/johndoh/roundcube-sauserprefs/archive/refs/tags/1.20.1.tar.gz -O roundcube-sauserprefs-1.20.1.tar.gz tar zxf roundcube-sauserprefs-1.20.1.tar.gz mv roundcube-sauserprefs-1.20.1 /srv/www/html/roundcube/plugins/sauserprefs cd $installer_dir cp config/config.inc.php /srv/www/html/roundcube/config/config.inc.php # get vmail db settings and set db connection info dbhost=`grep -m 1 host /var/vmail/.my.cnf |cut -d = -f 2|cut -d ' ' -f 2` dbdatabase=`grep -m 1 database /var/vmail/.my.cnf |cut -d = -f 2|cut -d ' ' -f 2` dbuser=`grep -m 1 user /var/vmail/.my.cnf |cut -d = -f 2|cut -d ' ' -f 2` dbpass=`grep -m 1 password /var/vmail/.my.cnf |cut -d = -f 2|cut -d ' ' -f 2` sed -i "s|.*db_dsnw.*|\$config['db_dsnw'] = 'mysql://$dbuser:$dbpass@$dbhost/$dbdatabase';|g" /srv/www/html/roundcube/config/config.inc.php DEBIAN_FRONTEND=noninteractive apt-get -y update # make sure pwgen is installed DEBIAN_FRONTEND=noninteractive apt-get -qq -y install pwgen # create random key des_key=`pwgen -1 24` sed -i "s|.*des_key.*|\$config['des_key'] = '$des_key';|g" /srv/www/html/roundcube/config/config.inc.php # install plugin configs cp -a plugins/* /srv/www/html/roundcube/plugins/ sed -i "s|.*sauserprefs_db_dsnw.*|\$config['sauserprefs_db_dsnw'] = 'mysql://$dbuser:$dbpass@$dbhost/$dbdatabase';|g" /srv/www/html/roundcube/plugins/sauserprefs/config.inc.php # create tmp files storage dir install --owner=www-data --group=www-data --mode=750 --directory /var/tmp/roundcube # load roundcube database tables /srv/www/html/roundcube/bin/initdb.sh --dir=/srv/www/html/roundcube/SQL # set permissions rm -r /srv/www/html/roundcube/installer/ chown -R vhost:vhost /srv/www/html/roundcube find /srv/www/html/roundcube -type d -exec chmod 755 {} + find /srv/www/html/roundcube -type f -exec chmod 644 {} + chmod 755 /srv/www/html/roundcube/bin/*.sh # install & enable rc systemd cron if [[ ! -d /usr/local/lib/systemd/system ]]; then mkdir -p /usr/local/lib/systemd/system fi cp sbin/rc-cron.sh /usr/local/sbin/ chmod 755 /usr/local/sbin/rc-cron.sh cp systemd/rc-cron.* /usr/local/lib/systemd/system/ chmod 644 /usr/local/lib/systemd/system/rc-cron.* systemctl enable rc-cron.timer systemctl start rc-cron.timer echo echo "Roundcube webmail installed." echo "You can optionally set the vars 'product_name' & 'support_url' in /srv/www/html/roundcube/config/config.inc.php"