mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
* Update check-for-changes.sh * add postfix-aliases.cf and handling of runtime updates
This commit is contained in:
parent
53a344a056
commit
30ed8fbf0e
0
config/postfix-aliases.cf
Normal file
0
config/postfix-aliases.cf
Normal file
|
@ -15,13 +15,16 @@ if [ ! -f postfix-accounts.cf ]; then
|
|||
exit
|
||||
fi
|
||||
|
||||
# create an array of files to monitor (perhaps simple *.cf would be ok here)
|
||||
declare -a cf_files=()
|
||||
for file in postfix-accounts.cf postfix-virtual.cf postfix-aliases.cf; do
|
||||
[ -f "$file" ] && cf_files+=("$file")
|
||||
done
|
||||
|
||||
# Update / generate after start
|
||||
echo "${log_date} Makeing new checksum file."
|
||||
if [ -f postfix-virtual.cf ]; then
|
||||
sha512sum --tag postfix-accounts.cf --tag postfix-virtual.cf > chksum
|
||||
else
|
||||
sha512sum --tag postfix-accounts.cf > chksum
|
||||
fi
|
||||
sha512sum ${cf_files[@]/#/--tag } > chksum
|
||||
|
||||
# Run forever
|
||||
while true; do
|
||||
|
||||
|
@ -30,16 +33,18 @@ log_date=$(date +"%Y-%m-%d %H:%M:%S ")
|
|||
|
||||
# Get chksum and check it.
|
||||
chksum=$(sha512sum -c --ignore-missing chksum)
|
||||
resu_acc=${chksum:21:2}
|
||||
if [ -f postfix-virtual.cf ]; then
|
||||
resu_vir=${chksum:44:2}
|
||||
else
|
||||
resu_vir="OK"
|
||||
fi
|
||||
|
||||
if ! [ $resu_acc = "OK" ] || ! [ $resu_vir = "OK" ]; then
|
||||
echo "${log_date} Change detected"
|
||||
#regen postfix accounts.
|
||||
if [[ $chksum == *"FAIL"* ]]; then
|
||||
echo "${log_date} Change detected"
|
||||
|
||||
#regen postix aliases.
|
||||
echo "root: ${POSTMASTER_ADDRESS}" > /etc/aliases
|
||||
if [ -f /tmp/docker-mailserver/postfix-aliases.cf ]; then
|
||||
cat /tmp/docker-mailserver/postfix-aliases.cf>>/etc/aliases
|
||||
fi
|
||||
postalias /etc/aliases
|
||||
|
||||
#regen postfix accounts.
|
||||
echo -n > /etc/postfix/vmailbox
|
||||
echo -n > /etc/dovecot/userdb
|
||||
if [ -f /tmp/docker-mailserver/postfix-accounts.cf -a "$ENABLE_LDAP" != 1 ]; then
|
||||
|
@ -126,8 +131,8 @@ if ! [ $resu_acc = "OK" ] || ! [ $resu_vir = "OK" ]; then
|
|||
chmod 0600 /etc/postfix/relayhost_map
|
||||
fi
|
||||
if [ -f postfix-virtual.cf ]; then
|
||||
# regen postfix aliases
|
||||
echo -n > /etc/postfix/virtual
|
||||
# regen postfix aliases
|
||||
echo -n > /etc/postfix/virtual
|
||||
echo -n > /etc/postfix/regexp
|
||||
if [ -f /tmp/docker-mailserver/postfix-virtual.cf ]; then
|
||||
# Copying virtual file
|
||||
|
@ -137,7 +142,7 @@ if ! [ $resu_acc = "OK" ] || ! [ $resu_vir = "OK" ]; then
|
|||
# Setting variables for better readability
|
||||
uname=$(echo ${from} | cut -d @ -f1)
|
||||
domain=$(echo ${from} | cut -d @ -f2)
|
||||
# if they are equal it means the line looks like: "user1 other@domain.tld"
|
||||
# if they are equal it means the line looks like: "user1 other@domain.tld"
|
||||
test "$uname" != "$domain" && echo ${domain} >> /tmp/vhost.tmp
|
||||
done < /tmp/docker-mailserver/postfix-virtual.cf
|
||||
fi
|
||||
|
@ -150,30 +155,26 @@ if ! [ $resu_acc = "OK" ] || ! [ $resu_vir = "OK" ]; then
|
|||
}' /etc/postfix/main.cf
|
||||
fi
|
||||
fi
|
||||
# Set vhost
|
||||
# Set vhost
|
||||
if [ -f /tmp/vhost.tmp ]; then
|
||||
cat /tmp/vhost.tmp | sort | uniq > /etc/postfix/vhost && rm /tmp/vhost.tmp
|
||||
fi
|
||||
|
||||
# Set right new if needed
|
||||
|
||||
# Set right new if needed
|
||||
if [ `find /var/mail -maxdepth 3 -a \( \! -user 5000 -o \! -group 5000 \) | grep -c .` != 0 ]; then
|
||||
chown -R 5000:5000 /var/mail
|
||||
fi
|
||||
|
||||
# Restart of the postfix
|
||||
supervisorctl restart postfix
|
||||
|
||||
# Prevent restart of dovecot when smtp_only=1
|
||||
if [ ! $SMTP_ONLY = 1 ]; then
|
||||
supervisorctl restart dovecot
|
||||
fi
|
||||
|
||||
# Restart of the postfix
|
||||
supervisorctl restart postfix
|
||||
|
||||
# Prevent restart of dovecot when smtp_only=1
|
||||
if [ ! $SMTP_ONLY = 1 ]; then
|
||||
supervisorctl restart dovecot
|
||||
fi
|
||||
|
||||
echo "${log_date} Update checksum"
|
||||
if [ -f postfix-virtual.cf ]; then
|
||||
sha512sum --tag postfix-accounts.cf --tag postfix-virtual.cf > chksum
|
||||
else
|
||||
sha512sum --tag postfix-accounts.cf > chksum
|
||||
fi
|
||||
echo "${log_date} Update checksum"
|
||||
sha512sum ${cf_files[@]/#/--tag } > chksum
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
|
|
|
@ -751,7 +751,7 @@ function _setup_postfix_aliases() {
|
|||
echo -n > /etc/postfix/virtual
|
||||
echo -n > /etc/postfix/regexp
|
||||
if [ -f /tmp/docker-mailserver/postfix-virtual.cf ]; then
|
||||
# fixing old virtual user file
|
||||
# fixing old virtual user file
|
||||
[[ $(grep ",$" /tmp/docker-mailserver/postfix-virtual.cf) ]] && sed -i -e "s/, /,/g" -e "s/,$//g" /tmp/docker-mailserver/postfix-virtual.cf
|
||||
# Copying virtual file
|
||||
cp -f /tmp/docker-mailserver/postfix-virtual.cf /etc/postfix/virtual
|
||||
|
@ -778,6 +778,12 @@ function _setup_postfix_aliases() {
|
|||
|
||||
notify 'inf' "Configuring root alias"
|
||||
echo "root: ${POSTMASTER_ADDRESS}" > /etc/aliases
|
||||
if [ -f /tmp/docker-mailserver/postfix-aliases.cf ]; then
|
||||
cat /tmp/docker-mailserver/postfix-aliases.cf>>/etc/aliases
|
||||
else
|
||||
notify 'inf' "'config/postfix-aliases.cf' is not provided and will be auto created."
|
||||
echo -n >/tmp/docker-mailserver/postfix-aliases.cf
|
||||
fi
|
||||
postalias /etc/aliases
|
||||
}
|
||||
|
||||
|
@ -805,8 +811,8 @@ function _setup_dkim() {
|
|||
else
|
||||
notify 'warn' "No DKIM key provided. Check the documentation to find how to get your keys."
|
||||
|
||||
local _f_keytable="/etc/opendkim/KeyTable"
|
||||
[ ! -f "$_f_keytable" ] && touch "$_f_keytable"
|
||||
local _f_keytable="/etc/opendkim/KeyTable"
|
||||
[ ! -f "$_f_keytable" ] && touch "$_f_keytable"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue