2014-10-20 20:20:24 +00:00
|
|
|
#!/bin/bash
|
2014-09-21 20:05:11 +00:00
|
|
|
# Webmail with Roundcube
|
|
|
|
# ----------------------
|
2013-09-07 20:53:25 +00:00
|
|
|
|
2014-06-03 11:12:38 +00:00
|
|
|
source setup/functions.sh # load our functions
|
2014-03-17 00:46:59 +00:00
|
|
|
source /etc/mailinabox.conf # load global vars
|
|
|
|
|
2014-09-21 20:05:11 +00:00
|
|
|
# ### Installing Roundcube
|
|
|
|
|
|
|
|
# We install Roundcube from sources, rather than from Ubuntu, because:
|
|
|
|
#
|
|
|
|
# 1. Ubuntu's `roundcube-core` package has dependencies on Apache & MySQL, which we don't want.
|
2014-07-08 00:37:53 +00:00
|
|
|
#
|
2014-09-21 20:05:11 +00:00
|
|
|
# 2. The Roundcube shipped with Ubuntu is consistently out of date.
|
2014-07-08 00:37:53 +00:00
|
|
|
#
|
2014-09-21 20:05:11 +00:00
|
|
|
# 3. It's packaged incorrectly --- it seems to be missing a directory of files.
|
2014-07-08 00:37:53 +00:00
|
|
|
#
|
|
|
|
# So we'll use apt-get to manually install the dependencies of roundcube that we know we need,
|
|
|
|
# and then we'll manually install roundcube from source.
|
2014-04-25 12:25:47 +00:00
|
|
|
|
2014-09-21 20:05:11 +00:00
|
|
|
# These dependencies are from `apt-cache showpkg roundcube-core`.
|
2015-08-19 19:58:35 +00:00
|
|
|
echo "Installing Roundcube (webmail)..."
|
2014-05-01 19:13:00 +00:00
|
|
|
apt_install \
|
2015-02-12 19:53:17 +00:00
|
|
|
dbconfig-common \
|
2015-07-21 10:25:10 +00:00
|
|
|
php5 php5-sqlite php5-mcrypt php5-intl php5-json php5-common php-auth php-net-smtp php-net-socket php-net-sieve php-mail-mime php-mail-mimedecode php-crypt-gpg php5-gd php5-pspell \
|
2014-04-25 12:25:47 +00:00
|
|
|
tinymce libjs-jquery libjs-jquery-mousewheel libmagic1
|
2013-09-07 20:53:25 +00:00
|
|
|
|
2014-10-04 21:57:26 +00:00
|
|
|
# We used to install Roundcube from Ubuntu, without triggering the dependencies #NODOC
|
|
|
|
# on Apache and MySQL, by downloading the debs and installing them manually. #NODOC
|
|
|
|
# Now that we're beyond that, get rid of those debs before installing from source. #NODOC
|
|
|
|
apt-get purge -qq -y roundcube* #NODOC
|
2013-09-07 20:53:25 +00:00
|
|
|
|
2014-09-24 12:46:42 +00:00
|
|
|
# Install Roundcube from source if it is not already present or if it is out of date.
|
2015-03-08 19:02:49 +00:00
|
|
|
# Combine the Roundcube version number with the commit hash of vacation_sieve to track
|
|
|
|
# whether we have the latest version.
|
2015-06-17 10:59:52 +00:00
|
|
|
VERSION=1.1.2
|
|
|
|
HASH=df88deae691da3ecf3e9f0aee674c1f3042ea1eb
|
2015-04-16 11:45:15 +00:00
|
|
|
VACATION_SIEVE_VERSION=91ea6f52216390073d1f5b70b5f6bea0bfaee7e5
|
2015-06-17 10:59:52 +00:00
|
|
|
PERSISTENT_LOGIN_VERSION=117fbd8f93b56b2bf72ad055193464803ef3bc36
|
2015-09-06 08:20:36 +00:00
|
|
|
HTML5_NOTIFIER_VERSION=968f570d46dd95fb86a14c69796a27e9f9ddaf6b
|
2015-09-06 08:22:08 +00:00
|
|
|
UPDATE_KEY=$VERSION:$VACATION_SIEVE_VERSION:$PERSISTENT_LOGIN_VERSION
|
2014-09-24 12:46:42 +00:00
|
|
|
needs_update=0 #NODOC
|
|
|
|
if [ ! -f /usr/local/lib/roundcubemail/version ]; then
|
2014-10-04 21:57:26 +00:00
|
|
|
# not installed yet #NODOC
|
2014-09-24 12:46:42 +00:00
|
|
|
needs_update=1 #NODOC
|
2015-05-30 14:07:36 +00:00
|
|
|
elif [[ "$UPDATE_KEY" != `cat /usr/local/lib/roundcubemail/version` ]]; then
|
2014-09-24 12:46:42 +00:00
|
|
|
# checks if the version is what we want
|
|
|
|
needs_update=1 #NODOC
|
|
|
|
fi
|
|
|
|
if [ $needs_update == 1 ]; then
|
2015-03-08 19:02:49 +00:00
|
|
|
# install roundcube
|
2015-04-11 19:21:38 +00:00
|
|
|
wget_verify \
|
2015-07-18 00:27:35 +00:00
|
|
|
https://mailinabox.email/mirror/roundcubemail-$VERSION.tar.gz \
|
2015-04-11 19:21:38 +00:00
|
|
|
$HASH \
|
|
|
|
/tmp/roundcube.tgz
|
2014-07-08 00:37:53 +00:00
|
|
|
tar -C /usr/local/lib -zxf /tmp/roundcube.tgz
|
2014-10-20 12:48:12 +00:00
|
|
|
rm -rf /usr/local/lib/roundcubemail
|
2014-09-24 12:46:42 +00:00
|
|
|
mv /usr/local/lib/roundcubemail-$VERSION/ /usr/local/lib/roundcubemail
|
2014-07-08 00:37:53 +00:00
|
|
|
rm -f /tmp/roundcube.tgz
|
2013-09-07 20:53:25 +00:00
|
|
|
|
2015-03-08 19:02:49 +00:00
|
|
|
# install roundcube autoreply/vacation plugin
|
2015-02-12 19:53:17 +00:00
|
|
|
git_clone https://github.com/arodier/Roundcube-Plugins.git $VACATION_SIEVE_VERSION plugins/vacation_sieve /usr/local/lib/roundcubemail/plugins/vacation_sieve
|
2015-02-21 15:01:27 +00:00
|
|
|
|
2015-05-29 19:49:40 +00:00
|
|
|
# install roundcube persistent_login plugin
|
|
|
|
git_clone https://github.com/mfreiholz/Roundcube-Persistent-Login-Plugin.git $PERSISTENT_LOGIN_VERSION '' /usr/local/lib/roundcubemail/plugins/persistent_login
|
|
|
|
|
2015-09-05 21:33:19 +00:00
|
|
|
# install roundcube html5_notifier plugin
|
2015-09-06 08:20:36 +00:00
|
|
|
git_clone https://github.com/kitist/html5_notifier.git $HTML5_NOTIFIER_VERSION '' /usr/local/lib/roundcubemail/plugins/html5_notifier
|
2015-09-05 21:33:19 +00:00
|
|
|
|
2015-03-08 19:02:49 +00:00
|
|
|
# record the version we've installed
|
2015-05-30 14:07:36 +00:00
|
|
|
echo $UPDATE_KEY > /usr/local/lib/roundcubemail/version
|
2014-07-08 00:37:53 +00:00
|
|
|
fi
|
2013-09-07 20:53:25 +00:00
|
|
|
|
2014-09-21 20:05:11 +00:00
|
|
|
# ### Configuring Roundcube
|
|
|
|
|
2014-07-08 00:37:53 +00:00
|
|
|
# Generate a safe 24-character secret key of safe characters.
|
2014-08-26 20:16:31 +00:00
|
|
|
SECRET_KEY=$(dd if=/dev/random bs=1 count=18 2>/dev/null | base64 | fold -w 24 | head -n 1)
|
2014-07-08 00:37:53 +00:00
|
|
|
|
|
|
|
# Create a configuration file.
|
|
|
|
#
|
|
|
|
# For security, temp and log files are not stored in the default locations
|
|
|
|
# which are inside the roundcube sources directory. We put them instead
|
|
|
|
# in normal places.
|
2014-09-21 20:05:11 +00:00
|
|
|
cat > /usr/local/lib/roundcubemail/config/config.inc.php <<EOF;
|
2014-07-08 00:37:53 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Do not edit. Written by Mail-in-a-Box. Regenerated on updates.
|
|
|
|
*/
|
|
|
|
\$config = array();
|
|
|
|
\$config['log_dir'] = '/var/log/roundcubemail/';
|
|
|
|
\$config['temp_dir'] = '/tmp/roundcubemail/';
|
|
|
|
\$config['db_dsnw'] = 'sqlite:///$STORAGE_ROOT/mail/roundcube/roundcube.sqlite?mode=0640';
|
|
|
|
\$config['default_host'] = 'ssl://localhost';
|
|
|
|
\$config['default_port'] = 993;
|
|
|
|
\$config['imap_timeout'] = 15;
|
|
|
|
\$config['smtp_server'] = 'tls://localhost';
|
|
|
|
\$config['smtp_port'] = 587;
|
|
|
|
\$config['smtp_user'] = '%u';
|
|
|
|
\$config['smtp_pass'] = '%p';
|
|
|
|
\$config['support_url'] = 'https://mailinabox.email/';
|
|
|
|
\$config['product_name'] = 'Mail-in-a-Box/Roundcube Webmail';
|
|
|
|
\$config['des_key'] = '$SECRET_KEY';
|
2015-09-05 21:33:19 +00:00
|
|
|
\$config['plugins'] = array('html5_notifier', 'archive', 'zipdownload', 'password', 'managesieve', 'jqueryui', 'vacation_sieve', 'persistent_login');
|
2014-07-11 21:52:46 +00:00
|
|
|
\$config['skin'] = 'classic';
|
2014-07-08 00:37:53 +00:00
|
|
|
\$config['login_autocomplete'] = 2;
|
|
|
|
\$config['password_charset'] = 'UTF-8';
|
|
|
|
\$config['junk_mbox'] = 'Spam';
|
|
|
|
?>
|
|
|
|
EOF
|
|
|
|
|
2015-03-08 19:02:49 +00:00
|
|
|
# Configure vaction_sieve.
|
2015-02-21 15:01:27 +00:00
|
|
|
cat > /usr/local/lib/roundcubemail/plugins/vacation_sieve/config.inc.php <<EOF;
|
|
|
|
<?php
|
2015-03-08 19:02:49 +00:00
|
|
|
/* Do not edit. Written by Mail-in-a-Box. Regenerated on updates. */
|
2015-02-21 15:01:27 +00:00
|
|
|
\$rcmail_config['vacation_sieve'] = array(
|
|
|
|
'date_format' => 'd/m/Y',
|
|
|
|
'working_hours' => array(8,18),
|
|
|
|
'msg_format' => 'text',
|
|
|
|
'logon_transform' => array('#([a-z])[a-z]+(\.|\s)([a-z])#i', '\$1\$3'),
|
|
|
|
'transfer' => array(
|
|
|
|
'mode' => 'managesieve',
|
|
|
|
'ms_activate_script' => true,
|
|
|
|
'host' => 'localhost',
|
|
|
|
'port' => '4190',
|
|
|
|
'usetls' => false,
|
|
|
|
'path' => 'vacation',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
EOF
|
|
|
|
|
2014-07-08 00:37:53 +00:00
|
|
|
# Create writable directories.
|
|
|
|
mkdir -p /var/log/roundcubemail /tmp/roundcubemail $STORAGE_ROOT/mail/roundcube
|
|
|
|
chown -R www-data.www-data /var/log/roundcubemail /tmp/roundcubemail $STORAGE_ROOT/mail/roundcube
|
2013-09-07 20:53:25 +00:00
|
|
|
|
2014-04-30 17:07:15 +00:00
|
|
|
# Password changing plugin settings
|
|
|
|
# The config comes empty by default, so we need the settings
|
|
|
|
# we're not planning to change in config.inc.dist...
|
2014-07-08 00:37:53 +00:00
|
|
|
cp /usr/local/lib/roundcubemail/plugins/password/config.inc.php.dist \
|
|
|
|
/usr/local/lib/roundcubemail/plugins/password/config.inc.php
|
2014-04-30 17:07:15 +00:00
|
|
|
|
2014-07-08 00:37:53 +00:00
|
|
|
tools/editconf.py /usr/local/lib/roundcubemail/plugins/password/config.inc.php \
|
|
|
|
"\$config['password_minimum_length']=6;" \
|
|
|
|
"\$config['password_db_dsn']='sqlite:///$STORAGE_ROOT/mail/users.sqlite';" \
|
|
|
|
"\$config['password_query']='UPDATE users SET password=%D WHERE email=%u';" \
|
|
|
|
"\$config['password_dovecotpw']='/usr/bin/doveadm pw';" \
|
|
|
|
"\$config['password_dovecotpw_method']='SHA512-CRYPT';" \
|
|
|
|
"\$config['password_dovecotpw_with_method']=true;"
|
2013-09-07 20:53:25 +00:00
|
|
|
|
2014-07-08 00:37:53 +00:00
|
|
|
# so PHP can use doveadm, for the password changing plugin
|
2014-04-30 17:07:15 +00:00
|
|
|
usermod -a -G dovecot www-data
|
|
|
|
|
|
|
|
# set permissions so that PHP can use users.sqlite
|
|
|
|
# could use dovecot instead of www-data, but not sure it matters
|
|
|
|
chown root.www-data $STORAGE_ROOT/mail
|
|
|
|
chmod 775 $STORAGE_ROOT/mail
|
2014-04-30 18:50:11 +00:00
|
|
|
chown root.www-data $STORAGE_ROOT/mail/users.sqlite
|
|
|
|
chmod 664 $STORAGE_ROOT/mail/users.sqlite
|
2014-04-30 17:07:15 +00:00
|
|
|
|
2014-04-18 00:17:24 +00:00
|
|
|
# Enable PHP modules.
|
|
|
|
php5enmod mcrypt
|
2014-08-12 11:00:54 +00:00
|
|
|
restart_service php5-fpm
|