2020-10-21 16:16:32 +00:00
|
|
|
#! /bin/bash
|
2020-09-05 14:19:12 +00:00
|
|
|
|
2021-01-16 09:16:05 +00:00
|
|
|
function _generate_secret { ( umask 0077 ; dd if=/dev/urandom bs=24 count=1 2>/dev/null | base64 -w0 > "${1}" ; ) ; }
|
2020-09-05 14:19:12 +00:00
|
|
|
|
2020-09-06 10:27:40 +00:00
|
|
|
if [[ -n ${SRS_DOMAINNAME} ]]
|
2020-09-05 14:19:12 +00:00
|
|
|
then
|
2020-09-06 10:27:40 +00:00
|
|
|
NEW_DOMAIN_NAME="${SRS_DOMAINNAME}"
|
|
|
|
elif [[ -n ${OVERRIDE_HOSTNAME} ]]
|
2020-09-05 14:19:12 +00:00
|
|
|
then
|
|
|
|
NEW_DOMAIN_NAME="${OVERRIDE_HOSTNAME#*.}"
|
2020-09-06 10:27:40 +00:00
|
|
|
elif [[ -n ${DOMAINNAME} ]]
|
2020-09-05 14:19:12 +00:00
|
|
|
then
|
2020-09-06 10:27:40 +00:00
|
|
|
NEW_DOMAIN_NAME="${DOMAINNAME}"
|
2018-06-19 06:17:32 +00:00
|
|
|
else
|
2020-09-05 14:19:12 +00:00
|
|
|
NEW_DOMAIN_NAME=$(hostname -d)
|
2018-06-19 06:17:32 +00:00
|
|
|
fi
|
|
|
|
|
2020-09-05 14:19:12 +00:00
|
|
|
sed -i -e "s/localdomain/${NEW_DOMAIN_NAME}/g" /etc/default/postsrsd
|
2018-02-06 07:11:57 +00:00
|
|
|
|
2020-09-05 14:19:12 +00:00
|
|
|
POSTSRSD_SECRET_FILE='/etc/postsrsd.secret'
|
|
|
|
POSTSRSD_STATE_DIR='/var/mail-state/etc-postsrsd'
|
|
|
|
POSTSRSD_STATE_SECRET_FILE="${POSTSRSD_STATE_DIR}/postsrsd.secret"
|
2018-03-10 12:41:20 +00:00
|
|
|
|
2020-09-06 10:27:40 +00:00
|
|
|
if [[ -n ${SRS_SECRET} ]]
|
2020-09-05 14:19:12 +00:00
|
|
|
then
|
2021-01-16 09:16:05 +00:00
|
|
|
( umask 0077 ; echo "${SRS_SECRET}" | tr ',' '\n' > "${POSTSRSD_SECRET_FILE}" ; )
|
2018-03-10 12:41:20 +00:00
|
|
|
else
|
2020-09-06 10:27:40 +00:00
|
|
|
if [[ ${ONE_DIR} -eq 1 ]]
|
2020-09-05 14:19:12 +00:00
|
|
|
then
|
2020-09-06 10:27:40 +00:00
|
|
|
if [[ ! -f ${POSTSRSD_STATE_SECRET_FILE} ]]
|
2020-09-05 14:19:12 +00:00
|
|
|
then
|
2020-09-06 10:27:40 +00:00
|
|
|
install -d -m 0775 "${POSTSRSD_STATE_DIR}"
|
|
|
|
_generate_secret "${POSTSRSD_STATE_SECRET_FILE}"
|
2018-03-10 12:41:20 +00:00
|
|
|
fi
|
2020-09-05 14:19:12 +00:00
|
|
|
|
2020-09-06 10:27:40 +00:00
|
|
|
install -m 0400 "${POSTSRSD_STATE_SECRET_FILE}" "${POSTSRSD_SECRET_FILE}"
|
|
|
|
elif [[ ! -f ${POSTSRSD_SECRET_FILE} ]]
|
2020-09-05 14:19:12 +00:00
|
|
|
then
|
2020-09-06 10:27:40 +00:00
|
|
|
_generate_secret "${POSTSRSD_SECRET_FILE}"
|
2018-03-10 12:41:20 +00:00
|
|
|
fi
|
2018-03-08 21:51:10 +00:00
|
|
|
fi
|
|
|
|
|
2020-09-06 10:27:40 +00:00
|
|
|
if [[ -n ${SRS_EXCLUDE_DOMAINS} ]]
|
2020-09-05 14:19:12 +00:00
|
|
|
then
|
2020-09-06 10:27:40 +00:00
|
|
|
sed -i -e "s/^#\?SRS_EXCLUDE_DOMAINS=.*$/SRS_EXCLUDE_DOMAINS=${SRS_EXCLUDE_DOMAINS}/g" /etc/default/postsrsd
|
2018-02-18 19:53:13 +00:00
|
|
|
fi
|
|
|
|
|
2018-02-06 07:11:57 +00:00
|
|
|
/etc/init.d/postsrsd start
|