feature(scripts): allow providing own config
This commit is contained in:
parent
713c5fa2ad
commit
3f8ab5d378
132
entrypoint.sh
132
entrypoint.sh
@ -8,70 +8,86 @@ convertCase () {
|
|||||||
printf "%s" "$1" | tr "[:lower:]" "[:upper:]"
|
printf "%s" "$1" | tr "[:lower:]" "[:upper:]"
|
||||||
}
|
}
|
||||||
|
|
||||||
printf "\nVerifying environment variables... "
|
if [ -f "/etc/postfix/main.cf.override" ]; then
|
||||||
|
# use provided configuration file
|
||||||
|
printf "\nAppending provided MAIN configuration... "
|
||||||
|
cat /etc/postfix/main.cf.override >> /etc/postfix/main.cf
|
||||||
|
\rm -f /tmp/main.cf.insert
|
||||||
|
else
|
||||||
|
# process auto-setup
|
||||||
|
printf "\nVerifying environment variables... "
|
||||||
|
|
||||||
# check for missing environment variable values
|
# check for missing environment variable values
|
||||||
if [ -z "$SMARTHOST" ]; then
|
if [ -z "$SMARTHOST" ]; then
|
||||||
printf "\nYou must specify the hostname or IP address of a smarthost where mail should be relayed.\n\n"
|
printf "\nYou must specify the hostname or IP address of a smarthost where mail should be relayed.\n\n"
|
||||||
fi
|
fi
|
||||||
if [ -z "$SMARTHOST_USERNAME" ]; then
|
if [ -z "$SMARTHOST_USERNAME" ]; then
|
||||||
printf "\nYou must provide a username for smarthost authentication.\n\n"
|
printf "\nYou must provide a username for smarthost authentication.\n\n"
|
||||||
fi
|
fi
|
||||||
if [ -z "$SMARTHOST_PASSWORD" ]; then
|
if [ -z "$SMARTHOST_PASSWORD" ]; then
|
||||||
printf "\nYou must provide a password for smarthost authentication.\n\n"
|
printf "\nYou must provide a password for smarthost authentication.\n\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# set failsafes
|
# set failsafes
|
||||||
[ -z "$SMARTHOST_PORT" ] && SMARTHOST_PORT=587
|
[ -z "$SMARTHOST_PORT" ] && SMARTHOST_PORT=587
|
||||||
[ -z "$LOCAL_HOSTNAME" ] && LOCAL_HOSTNAME="smarthost"
|
[ -z "$LOCAL_HOSTNAME" ] && LOCAL_HOSTNAME="smarthost"
|
||||||
[ -z "$LOCAL_DOMAINNAME" ] && LOCAL_DOMAINNAME="${LOCAL_HOSTNAME#*.}"
|
[ -z "$LOCAL_DOMAINNAME" ] && LOCAL_DOMAINNAME="${LOCAL_HOSTNAME#*.}"
|
||||||
|
|
||||||
|
printf "done\n"
|
||||||
|
printf "updating configuration files... "
|
||||||
|
|
||||||
|
# update main.cf
|
||||||
|
sed -i "s/{LOCAL_HOSTNAME}/${LOCAL_HOSTNAME}/" /tmp/main.cf.insert
|
||||||
|
sed -i "s/{LOCAL_DOMAINNAME}/${LOCAL_DOMAINNAME}/" /tmp/main.cf.insert
|
||||||
|
sed -i "s/{SMARTHOST}/${SMARTHOST}/" /tmp/main.cf.insert
|
||||||
|
sed -i "s/{SMARTHOST_PORT}/${SMARTHOST_PORT}/" /tmp/main.cf.insert
|
||||||
|
sed -i "s/{SMARTHOST_USERNAME}/${SMARTHOST_USERNAME}/" /tmp/main.cf.insert
|
||||||
|
sed -i "s/{SMARTHOST_PASSWORD}/${SMARTHOST_PASSWORD}/" /tmp/main.cf.insert
|
||||||
|
|
||||||
|
LOCAL_ENCRYPTION="$(convertCase "$LOCAL_ENCRYPTION")"
|
||||||
|
case "$LOCAL_ENCRYPTION" in
|
||||||
|
OPT*)
|
||||||
|
sed -i 's/{LOCAL_ENCRYPTION}/may/' /tmp/main.cf.insert
|
||||||
|
sed -i 's/#smtpd_/smtpd_/g' /tmp/main.cf.insert
|
||||||
|
;;
|
||||||
|
TRUE)
|
||||||
|
sed -i 's/{LOCAL_ENCRYPTION}/encrypt/' /tmp/main.cf.insert
|
||||||
|
sed -i 's/#smtpd_/smtpd_/g' /tmp/main.cf.insert
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
sed -i 's/{LOCAL_ENCRYPTION}//' /tmp/main.cf.insert
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
SMARTHOST_ENCRYPTION="$(convertCase "$SMARTHOST_ENCRYPTION")"
|
||||||
|
case "$SMARTHOST_ENCRYPTION" in
|
||||||
|
OPT*)
|
||||||
|
sed -i 's/{SMARTHOST_ENCRYPTION}/may/' /tmp/main.cf.insert
|
||||||
|
;;
|
||||||
|
TRUE)
|
||||||
|
sed -i 's/{SMARTHOST_ENCRYPTION}/secure/' /tmp/main.cf.insert
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
sed -i 's/{SMARTHOST_ENCRYPTION}/none/' /tmp/main.cf.insert
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# append configuration and remove temp file
|
||||||
|
cat /tmp/main.cf.insert >> /etc/postfix/main.cf
|
||||||
|
\rm -f /tmp/main.cf.insert
|
||||||
|
fi
|
||||||
printf "done\n"
|
printf "done\n"
|
||||||
printf "updating configuration files... "
|
|
||||||
|
|
||||||
# update main.cf
|
|
||||||
sed -i "s/{LOCAL_HOSTNAME}/${LOCAL_HOSTNAME}/" /tmp/main.cf.insert
|
|
||||||
sed -i "s/{LOCAL_DOMAINNAME}/${LOCAL_DOMAINNAME}/" /tmp/main.cf.insert
|
|
||||||
sed -i "s/{SMARTHOST}/${SMARTHOST}/" /tmp/main.cf.insert
|
|
||||||
sed -i "s/{SMARTHOST_PORT}/${SMARTHOST_PORT}/" /tmp/main.cf.insert
|
|
||||||
sed -i "s/{SMARTHOST_USERNAME}/${SMARTHOST_USERNAME}/" /tmp/main.cf.insert
|
|
||||||
sed -i "s/{SMARTHOST_PASSWORD}/${SMARTHOST_PASSWORD}/" /tmp/main.cf.insert
|
|
||||||
|
|
||||||
LOCAL_ENCRYPTION="$(convertCase "$LOCAL_ENCRYPTION")"
|
|
||||||
case "$LOCAL_ENCRYPTION" in
|
|
||||||
OPT*)
|
|
||||||
sed -i 's/{LOCAL_ENCRYPTION}/may/' /tmp/main.cf.insert
|
|
||||||
sed -i 's/#smtpd_/smtpd_/g' /tmp/main.cf.insert
|
|
||||||
;;
|
|
||||||
TRUE)
|
|
||||||
sed -i 's/{LOCAL_ENCRYPTION}/encrypt/' /tmp/main.cf.insert
|
|
||||||
sed -i 's/#smtpd_/smtpd_/g' /tmp/main.cf.insert
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
sed -i 's/{LOCAL_ENCRYPTION}//' /tmp/main.cf.insert
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
SMARTHOST_ENCRYPTION="$(convertCase "$SMARTHOST_ENCRYPTION")"
|
|
||||||
case "$SMARTHOST_ENCRYPTION" in
|
|
||||||
OPT*)
|
|
||||||
sed -i 's/{SMARTHOST_ENCRYPTION}/may/' /tmp/main.cf.insert
|
|
||||||
;;
|
|
||||||
TRUE)
|
|
||||||
sed -i 's/{SMARTHOST_ENCRYPTION}/secure/' /tmp/main.cf.insert
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
sed -i 's/{SMARTHOST_ENCRYPTION}/none/' /tmp/main.cf.insert
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
cat /tmp/main.cf.insert >> /etc/postfix/main.cf
|
|
||||||
rm -f /tmp/main.cf.insert
|
|
||||||
|
|
||||||
# update master.cf
|
|
||||||
sed -i 's/#tlsproxy/tlsproxy/' /etc/postfix/master.cf
|
|
||||||
|
|
||||||
|
if [ -f "/etc/postfix/master.cf.override" ]; then
|
||||||
|
# use provided configuration file
|
||||||
|
printf "\nUsing provided MASTER configuration... "
|
||||||
|
\cp --force /etc/postfix/master.cf.override /etc/postfix/master.cf
|
||||||
|
else
|
||||||
|
# update master.cf
|
||||||
|
sed -i 's/#tlsproxy/tlsproxy/' /etc/postfix/master.cf
|
||||||
|
fi
|
||||||
printf "done\n"
|
printf "done\n"
|
||||||
|
|
||||||
printf "container setup complete!\n"
|
printf "container setup complete!\n"
|
||||||
|
|
||||||
# run CMD passed to this container
|
# run CMD passed to this container
|
||||||
|
Loading…
Reference in New Issue
Block a user