mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Update postfix conf_regen hook and simplify plain conf files copy
This commit is contained in:
parent
2d28006c83
commit
c09abeaec1
10 changed files with 53 additions and 56 deletions
|
@ -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
|
53
data/hooks/conf_regen/19-postfix
Executable file
53
data/hooks/conf_regen/19-postfix
Executable file
|
@ -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
|
Loading…
Add table
Reference in a new issue