2021-04-20 14:26:46 -07:00
|
|
|
#!/bin/bash
|
2022-08-22 13:59:06 -07:00
|
|
|
#
|
|
|
|
# vmail-webmail
|
|
|
|
# https://git.stack-source.com/msb/vmail-webmail
|
|
|
|
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
#
|
2021-04-20 14:26:46 -07:00
|
|
|
# must be root
|
|
|
|
if [ "$USER" != "root" ]; 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/
|
2022-08-29 15:37:49 -07:00
|
|
|
wget https://github.com/roundcube/roundcubemail/releases/download/1.6.0/roundcubemail-1.6.0-complete.tar.gz
|
|
|
|
tar zxf roundcubemail-1.6.0-complete.tar.gz
|
|
|
|
mv roundcubemail-1.6.0 /srv/www/html/roundcube
|
2021-04-20 14:26:46 -07:00
|
|
|
|
|
|
|
cd /usr/local/src/
|
2022-08-29 15:37:49 -07:00
|
|
|
wget https://github.com/johndoh/roundcube-sauserprefs/archive/refs/tags/1.20.tar.gz -O roundcube-sauserprefs-1.20.tar.gz
|
|
|
|
tar zxf roundcube-sauserprefs-1.20.tar.gz
|
|
|
|
mv roundcube-sauserprefs-1.20 /srv/www/html/roundcube/plugins/sauserprefs
|
2021-04-20 14:26:46 -07:00
|
|
|
|
|
|
|
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`
|
2021-04-21 12:38:54 -07:00
|
|
|
sed -i "s|.*db_dsnw.*|\$config['db_dsnw'] = 'mysql://$dbuser:$dbpass@$dbhost/$dbdatabase';|g" /srv/www/html/roundcube/config/config.inc.php
|
2021-04-20 14:26:46 -07:00
|
|
|
|
2021-04-21 11:17:21 -07:00
|
|
|
apt-get update
|
|
|
|
|
2021-04-20 14:26:46 -07:00
|
|
|
# make sure pwgen is installed
|
|
|
|
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
|
|
|
|
|
2022-08-29 15:37:49 -07:00
|
|
|
# install plugin configs
|
2021-04-20 14:26:46 -07:00
|
|
|
cp -a plugins/* /srv/www/html/roundcube/plugins/
|
2021-04-21 12:51:55 -07:00
|
|
|
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
|
2021-04-20 14:26:46 -07:00
|
|
|
|
|
|
|
# create tmp files storage dir
|
|
|
|
install --owner=www-data --group=www-data --mode=750 --directory /var/tmp/roundcube
|
|
|
|
|
2022-08-29 15:37:49 -07:00
|
|
|
# prefix roundcubemail mysql tables with rc_
|
|
|
|
cp /srv/www/html/roundcube/installer/SQL/mysql.initial.sql $installer_dir/rc.sql
|
|
|
|
tables=(`grep TABLE rc.sql |cut -d \\\` -f 2`)
|
|
|
|
for table in "${!tables[@]}"
|
|
|
|
do
|
|
|
|
table=${tables[$table]}
|
|
|
|
sed -i "s|\`$table\`|\`rc_$table\`|g" rc.sql
|
|
|
|
done
|
|
|
|
# load roundcube database tables
|
|
|
|
mysql vmail < rc.sql
|
|
|
|
|
2021-04-20 14:26:46 -07:00
|
|
|
# set permissions
|
2021-12-27 16:01:46 -08:00
|
|
|
rm -r /srv/www/html/roundcube/installer/
|
2021-05-06 13:36:41 -07:00
|
|
|
chown -R vhost:vhost /srv/www/html/roundcube
|
2021-04-20 14:26:46 -07:00
|
|
|
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
|
|
|
|
|
2021-04-20 14:34:15 -07:00
|
|
|
# install & enable rc systemd cron
|
|
|
|
cp sbin/rc-cron.sh /usr/local/sbin/
|
|
|
|
chmod 755 /usr/local/sbin/rc-cron.sh
|
|
|
|
cp systemd/rc-cron.* /usr/lib/systemd/system/
|
|
|
|
chmod 644 /usr/lib/systemd/system/rc-cron.*
|
2022-03-28 09:47:01 -07:00
|
|
|
systemctl enable rc-cron.timer
|
2021-04-20 14:34:15 -07:00
|
|
|
systemctl start rc-cron.timer
|
|
|
|
|
2021-04-20 14:26:46 -07:00
|
|
|
echo "Roundcube webmail installed."
|
|
|
|
echo "You can optionally set the vars 'product_name' & 'support_url' in /srv/www/html/roundcube/config/config.inc.php"
|