94 lines
3.5 KiB
Bash
94 lines
3.5 KiB
Bash
#!/bin/bash
|
|
#
|
|
# 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)
|
|
#
|
|
# 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/
|
|
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
|
|
|
|
cd /usr/local/src/
|
|
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
|
|
|
|
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
|
|
|
|
apt-get update
|
|
|
|
# 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
|
|
|
|
# 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
|
|
|
|
# prefix roundcubemail mysql tables with rc_
|
|
cp /srv/www/html/roundcube/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
|
|
|
|
# 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
|
|
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.*
|
|
systemctl enable rc-cron.timer
|
|
systemctl start rc-cron.timer
|
|
|
|
echo "Roundcube webmail installed."
|
|
echo "You can optionally set the vars 'product_name' & 'support_url' in /srv/www/html/roundcube/config/config.inc.php"
|