mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
69 lines
1.4 KiB
Bash
Executable file
69 lines
1.4 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
do_pre_regen() {
|
|
pending_dir=$1
|
|
|
|
cd /usr/share/yunohost/templates/dovecot
|
|
|
|
dovecot_dir="${pending_dir}/etc/dovecot"
|
|
mkdir -p "${dovecot_dir}/global_script"
|
|
|
|
# copy simple conf files
|
|
cp dovecot-ldap.conf "${dovecot_dir}/dovecot-ldap.conf"
|
|
cp dovecot.sieve "${dovecot_dir}/global_script/dovecot.sieve"
|
|
|
|
# prepare dovecot.conf conf file
|
|
main_domain=$(cat /etc/yunohost/current_host)
|
|
cat dovecot.conf \
|
|
| sed "s/{{ main_domain }}/${main_domain}/g" \
|
|
> "${dovecot_dir}/dovecot.conf"
|
|
|
|
# adapt it for IPv4-only hosts
|
|
if [ ! -f /proc/net/if_inet6 ]; then
|
|
sed -i \
|
|
's/^\(listen =\).*/\1 */' \
|
|
"${dovecot_dir}/dovecot.conf"
|
|
fi
|
|
}
|
|
|
|
do_post_regen() {
|
|
regen_conf_files=$1
|
|
|
|
# create vmail user
|
|
id vmail > /dev/null 2>&1 \
|
|
|| sudo adduser --system --ingroup mail --uid 500 vmail
|
|
|
|
# fix permissions
|
|
sudo chown -R vmail:mail /etc/dovecot/global_script
|
|
sudo chmod 770 /etc/dovecot/global_script
|
|
|
|
[ -z "$regen_conf_files" ] && exit 0
|
|
|
|
# compile sieve script
|
|
[[ "$regen_conf_files" =~ dovecot\.sieve ]] && {
|
|
sudo sievec /etc/dovecot/global_script/dovecot.sieve
|
|
sudo chown -R vmail:mail /etc/dovecot/global_script
|
|
}
|
|
|
|
sudo service dovecot restart
|
|
}
|
|
|
|
FORCE=${2:-0}
|
|
DRY_RUN=${3:-0}
|
|
|
|
case "$1" in
|
|
pre)
|
|
do_pre_regen $4
|
|
;;
|
|
post)
|
|
do_post_regen $4
|
|
;;
|
|
*)
|
|
echo "hook called with unknown argument \`$1'" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
exit 0
|