* Update check-for-changes.sh * add postfix-aliases.cf and handling of runtime updates
This commit is contained in:
parent
53a344a056
commit
30ed8fbf0e
|
@ -15,13 +15,16 @@ if [ ! -f postfix-accounts.cf ]; then
|
||||||
exit
|
exit
|
||||||
fi
|
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
|
# Update / generate after start
|
||||||
echo "${log_date} Makeing new checksum file."
|
echo "${log_date} Makeing new checksum file."
|
||||||
if [ -f postfix-virtual.cf ]; then
|
sha512sum ${cf_files[@]/#/--tag } > chksum
|
||||||
sha512sum --tag postfix-accounts.cf --tag postfix-virtual.cf > chksum
|
|
||||||
else
|
|
||||||
sha512sum --tag postfix-accounts.cf > chksum
|
|
||||||
fi
|
|
||||||
# Run forever
|
# Run forever
|
||||||
while true; do
|
while true; do
|
||||||
|
|
||||||
|
@ -30,16 +33,18 @@ log_date=$(date +"%Y-%m-%d %H:%M:%S ")
|
||||||
|
|
||||||
# Get chksum and check it.
|
# Get chksum and check it.
|
||||||
chksum=$(sha512sum -c --ignore-missing chksum)
|
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
|
if [[ $chksum == *"FAIL"* ]]; then
|
||||||
echo "${log_date} Change detected"
|
echo "${log_date} Change detected"
|
||||||
#regen postfix accounts.
|
|
||||||
|
#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/postfix/vmailbox
|
||||||
echo -n > /etc/dovecot/userdb
|
echo -n > /etc/dovecot/userdb
|
||||||
if [ -f /tmp/docker-mailserver/postfix-accounts.cf -a "$ENABLE_LDAP" != 1 ]; then
|
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
|
chmod 0600 /etc/postfix/relayhost_map
|
||||||
fi
|
fi
|
||||||
if [ -f postfix-virtual.cf ]; then
|
if [ -f postfix-virtual.cf ]; then
|
||||||
# regen postfix aliases
|
# regen postfix aliases
|
||||||
echo -n > /etc/postfix/virtual
|
echo -n > /etc/postfix/virtual
|
||||||
echo -n > /etc/postfix/regexp
|
echo -n > /etc/postfix/regexp
|
||||||
if [ -f /tmp/docker-mailserver/postfix-virtual.cf ]; then
|
if [ -f /tmp/docker-mailserver/postfix-virtual.cf ]; then
|
||||||
# Copying virtual file
|
# Copying virtual file
|
||||||
|
@ -137,7 +142,7 @@ if ! [ $resu_acc = "OK" ] || ! [ $resu_vir = "OK" ]; then
|
||||||
# Setting variables for better readability
|
# Setting variables for better readability
|
||||||
uname=$(echo ${from} | cut -d @ -f1)
|
uname=$(echo ${from} | cut -d @ -f1)
|
||||||
domain=$(echo ${from} | cut -d @ -f2)
|
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
|
test "$uname" != "$domain" && echo ${domain} >> /tmp/vhost.tmp
|
||||||
done < /tmp/docker-mailserver/postfix-virtual.cf
|
done < /tmp/docker-mailserver/postfix-virtual.cf
|
||||||
fi
|
fi
|
||||||
|
@ -150,30 +155,26 @@ if ! [ $resu_acc = "OK" ] || ! [ $resu_vir = "OK" ]; then
|
||||||
}' /etc/postfix/main.cf
|
}' /etc/postfix/main.cf
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# Set vhost
|
# Set vhost
|
||||||
if [ -f /tmp/vhost.tmp ]; then
|
if [ -f /tmp/vhost.tmp ]; then
|
||||||
cat /tmp/vhost.tmp | sort | uniq > /etc/postfix/vhost && rm /tmp/vhost.tmp
|
cat /tmp/vhost.tmp | sort | uniq > /etc/postfix/vhost && rm /tmp/vhost.tmp
|
||||||
fi
|
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
|
if [ `find /var/mail -maxdepth 3 -a \( \! -user 5000 -o \! -group 5000 \) | grep -c .` != 0 ]; then
|
||||||
chown -R 5000:5000 /var/mail
|
chown -R 5000:5000 /var/mail
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Restart of the postfix
|
# Restart of the postfix
|
||||||
supervisorctl restart postfix
|
supervisorctl restart postfix
|
||||||
|
|
||||||
# Prevent restart of dovecot when smtp_only=1
|
# Prevent restart of dovecot when smtp_only=1
|
||||||
if [ ! $SMTP_ONLY = 1 ]; then
|
if [ ! $SMTP_ONLY = 1 ]; then
|
||||||
supervisorctl restart dovecot
|
supervisorctl restart dovecot
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${log_date} Update checksum"
|
echo "${log_date} Update checksum"
|
||||||
if [ -f postfix-virtual.cf ]; then
|
sha512sum ${cf_files[@]/#/--tag } > chksum
|
||||||
sha512sum --tag postfix-accounts.cf --tag postfix-virtual.cf > chksum
|
|
||||||
else
|
|
||||||
sha512sum --tag postfix-accounts.cf > chksum
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
|
@ -751,7 +751,7 @@ function _setup_postfix_aliases() {
|
||||||
echo -n > /etc/postfix/virtual
|
echo -n > /etc/postfix/virtual
|
||||||
echo -n > /etc/postfix/regexp
|
echo -n > /etc/postfix/regexp
|
||||||
if [ -f /tmp/docker-mailserver/postfix-virtual.cf ]; then
|
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
|
[[ $(grep ",$" /tmp/docker-mailserver/postfix-virtual.cf) ]] && sed -i -e "s/, /,/g" -e "s/,$//g" /tmp/docker-mailserver/postfix-virtual.cf
|
||||||
# Copying virtual file
|
# Copying virtual file
|
||||||
cp -f /tmp/docker-mailserver/postfix-virtual.cf /etc/postfix/virtual
|
cp -f /tmp/docker-mailserver/postfix-virtual.cf /etc/postfix/virtual
|
||||||
|
@ -778,6 +778,12 @@ function _setup_postfix_aliases() {
|
||||||
|
|
||||||
notify 'inf' "Configuring root alias"
|
notify 'inf' "Configuring root alias"
|
||||||
echo "root: ${POSTMASTER_ADDRESS}" > /etc/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
|
||||||
|
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
|
postalias /etc/aliases
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -805,8 +811,8 @@ function _setup_dkim() {
|
||||||
else
|
else
|
||||||
notify 'warn' "No DKIM key provided. Check the documentation to find how to get your keys."
|
notify 'warn' "No DKIM key provided. Check the documentation to find how to get your keys."
|
||||||
|
|
||||||
local _f_keytable="/etc/opendkim/KeyTable"
|
local _f_keytable="/etc/opendkim/KeyTable"
|
||||||
[ ! -f "$_f_keytable" ] && touch "$_f_keytable"
|
[ ! -f "$_f_keytable" ] && touch "$_f_keytable"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue