yunohost/data/hooks/conf_regen/19-postfix

53 lines
965 B
Bash
Executable file

#!/bin/bash
set -e
do_pre_regen() {
pending_dir=$1
cd /usr/share/yunohost/templates/postfix
postfix_dir="${pending_dir}/etc/postfix"
mkdir -p "$postfix_dir"
# install plain conf files
cp plain/* "$postfix_dir"
# prepare main.cf conf file
main_domain=$(cat /etc/yunohost/current_host)
cat main.cf \
| sed "s/{{ main_domain }}/${main_domain}/g" \
> "${postfix_dir}/main.cf"
# adapt it to IPv4-only hosts
if [ ! -f /proc/net/if_inet6 ]; then
sed -i \
's/ \[::ffff:127.0.0.0\]\/104 \[::1\]\/128//g' \
"${postfix_dir}/main.cf"
sed -i \
's/inet_interfaces = all/&\ninet_protocols = ipv4/' \
"${postfix_dir}/main.cf"
fi
}
do_post_regen() {
# TODO: only restart if conf changed
sudo service postfix restart
}
FORCE=$2
case "$1" in
pre)
do_pre_regen $3
;;
post)
do_post_regen
;;
*)
echo "hook called with unknown argument \`$status'" >&2
exit 1
;;
esac
exit 0