diff --git a/data/hooks/conf_regen-old/19-postfix b/data/hooks/conf_regen-old/19-postfix deleted file mode 100644 index 1e37e6752..000000000 --- a/data/hooks/conf_regen-old/19-postfix +++ /dev/null @@ -1,56 +0,0 @@ -set -e - -force=$1 - -function safe_copy () { - if [[ "$force" == "True" ]]; then - sudo yunohost service safecopy \ - -s postfix \ - $1 $2 \ - --force - else - sudo yunohost service safecopy \ - -s postfix \ - $1 $2 - fi -} - -cd /usr/share/yunohost/templates/postfix - -# Copy plain single configuration files -files="header_checks -ldap-accounts.cf -ldap-aliases.cf -ldap-domains.cf -master.cf -sender_canonical -smtp_reply_filter" - -for file in $files; do - safe_copy $file /etc/postfix/$file -done - -main_domain=$(cat /etc/yunohost/current_host) - -# Replace main domain in the main configuration file -cat main.cf.sed \ - | sed "s/{{ main_domain }}/$main_domain/g" \ - | sudo tee main.cf - -# And adapt it to IPv4-only hosts -if [ ! -f /proc/net/if_inet6 ]; then - sudo sed -i \ - 's/ \[::ffff:127.0.0.0\]\/104 \[::1\]\/128//g' \ - main.cf - - sudo sed -i \ - 's/inet_interfaces = all/inet_interfaces = all\ninet_protocols = ipv4/' \ - main.cf -fi - -if [[ $(safe_copy main.cf /etc/postfix/main.cf) == "True" ]]; then - sudo service postfix restart -else - sudo service postfix reload \ - || sudo service postfix restart -fi diff --git a/data/hooks/conf_regen/19-postfix b/data/hooks/conf_regen/19-postfix new file mode 100755 index 000000000..2f1ffb283 --- /dev/null +++ b/data/hooks/conf_regen/19-postfix @@ -0,0 +1,53 @@ +#!/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 diff --git a/data/templates/postfix/main.cf.sed b/data/templates/postfix/main.cf similarity index 100% rename from data/templates/postfix/main.cf.sed rename to data/templates/postfix/main.cf diff --git a/data/templates/postfix/header_checks b/data/templates/postfix/plain/header_checks similarity index 100% rename from data/templates/postfix/header_checks rename to data/templates/postfix/plain/header_checks diff --git a/data/templates/postfix/ldap-accounts.cf b/data/templates/postfix/plain/ldap-accounts.cf similarity index 100% rename from data/templates/postfix/ldap-accounts.cf rename to data/templates/postfix/plain/ldap-accounts.cf diff --git a/data/templates/postfix/ldap-aliases.cf b/data/templates/postfix/plain/ldap-aliases.cf similarity index 100% rename from data/templates/postfix/ldap-aliases.cf rename to data/templates/postfix/plain/ldap-aliases.cf diff --git a/data/templates/postfix/ldap-domains.cf b/data/templates/postfix/plain/ldap-domains.cf similarity index 100% rename from data/templates/postfix/ldap-domains.cf rename to data/templates/postfix/plain/ldap-domains.cf diff --git a/data/templates/postfix/master.cf b/data/templates/postfix/plain/master.cf similarity index 100% rename from data/templates/postfix/master.cf rename to data/templates/postfix/plain/master.cf diff --git a/data/templates/postfix/sender_canonical b/data/templates/postfix/plain/sender_canonical similarity index 100% rename from data/templates/postfix/sender_canonical rename to data/templates/postfix/plain/sender_canonical diff --git a/data/templates/postfix/smtp_reply_filter b/data/templates/postfix/plain/smtp_reply_filter similarity index 100% rename from data/templates/postfix/smtp_reply_filter rename to data/templates/postfix/plain/smtp_reply_filter