2016-12-15 17:07:09 +08:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2017-01-13 03:16:37 +08:00
|
|
|
# Hard-code env vars to imapsync due to cron not passing them to the perl script
|
|
|
|
sed -i "/^\$DBUSER/c\\\$DBUSER='${DBUSER}';" /usr/local/bin/imapsync_cron.pl
|
|
|
|
sed -i "/^\$DBPASS/c\\\$DBPASS='${DBPASS}';" /usr/local/bin/imapsync_cron.pl
|
|
|
|
sed -i "/^\$DBNAME/c\\\$DBNAME='${DBNAME}';" /usr/local/bin/imapsync_cron.pl
|
|
|
|
|
|
|
|
# Set Dovecot config parameters, escape " in db password
|
2016-12-19 22:19:35 +08:00
|
|
|
DBPASS=$(echo ${DBPASS} | sed 's/"/\\"/g')
|
2016-12-15 17:07:09 +08:00
|
|
|
sed -i "/^connect/c\connect = \"host=mysql dbname=${DBNAME} user=${DBUSER} password=${DBPASS}\"" /etc/dovecot/sql/*
|
|
|
|
|
2016-12-19 22:19:35 +08:00
|
|
|
[[ ! -d /var/vmail/sieve ]] && mkdir -p /var/vmail/sieve
|
2017-01-13 03:16:37 +08:00
|
|
|
[[ ! -d /etc/sogo ]] && mkdir -p /etc/sogo
|
2016-12-19 22:19:35 +08:00
|
|
|
cat /etc/dovecot/sieve_after > /var/vmail/sieve/global.sieve
|
|
|
|
sievec /var/vmail/sieve/global.sieve
|
|
|
|
chown -R vmail:vmail /var/vmail/sieve
|
|
|
|
|
|
|
|
# Do not do this every start-up, it may take a very long time. So we use a stat check here.
|
2016-12-18 03:31:59 +08:00
|
|
|
if [[ $(stat -c %U /var/vmail/) != "vmail" ]] ; then chown -R vmail:vmail /var/vmail ; fi
|
|
|
|
|
2016-12-21 15:25:47 +08:00
|
|
|
# Create random master for SOGo sieve features
|
2016-12-23 14:07:50 +08:00
|
|
|
RAND_USER=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 16 | head -n 1)
|
|
|
|
RAND_PASS=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 24 | head -n 1)
|
|
|
|
echo ${RAND_USER}:$(doveadm pw -s SHA1 -p ${RAND_PASS}) > /etc/dovecot/dovecot-master.passwd
|
2016-12-21 15:25:47 +08:00
|
|
|
echo ${RAND_USER}:${RAND_PASS} > /etc/sogo/sieve.creds
|
|
|
|
|
2016-12-15 17:07:09 +08:00
|
|
|
exec "$@"
|