ports/mail/mailman/files/pkg-install.in
Matthias Andree 4412b82121 Fix up DEFAULT_URL_HOST/DEFAULT_MAIL_HOST for jailed or external builds.
If the package is built in, for instance, poudriere, or on a computer other
than the one it is later installed on, the DEFAULT_MAIL_HOST and
DEFAULT_URL_HOST variables in the Mailman/Defaults.py file were unsuitable.

Leverage pkg-install to fix these up to be the same as hostname -f at
install time.

[The MFH would require the intermediate update to 2.1.24 to be included.]

MFH:		2017Q3
2017-09-10 16:53:56 +00:00

128 lines
4 KiB
Bash

#! /bin/sh
#
# $FreeBSD$
PATH=/bin:/usr/bin:/usr/sbin
check_rcfile_fix_perms() {
(
. /etc/rc.subr
name="mailman"
rcvar=mailman_enable
load_rc_config $name
: ${mailman_fix_perms="YES"}
checkyesno mailman_fix_perms
)
}
set -e
case "$2" in
POST-INSTALL)
echo "---> Starting post-install script"
LC_ALL=C
export LC_ALL
MYTMP="$(mktemp -d "${TMPDIR-/tmp}/mminstall.XXXXXXXXXX")"
trap "rm -rf \"$MYTMP\"" EXIT
# fix up permissions - this is under investigation; pkg or libarchive
# goof up the group writable and/or setgid bits
/usr/bin/find "%%MAILMANDIR%%/qfiles" -maxdepth 1 -type d -exec \
/bin/chmod u+rwx,g+rwsx,o-w "{}" +
/bin/chmod 02775 "%%MAILMANDIR%%" \
"%%MAILMANDIR%%/Mailman" \
"%%MAILMANDIR%%/bin" \
"%%MAILMANDIR%%/cgi-bin" \
"%%MAILMANDIR%%/icons" \
"%%MAILMANDIR%%/mail" \
"%%MAILMANDIR%%/scripts" \
"%%MAILMANDIR%%/tests" \
"%%MAILMANDIR%%/pythonlib" \
"%%MAILMANDIR%%/spam" \
"%%MAILMANDIR%%/locks" \
"%%MAILMANDIR%%/Mailman/Archiver" \
"%%MAILMANDIR%%/Mailman/Bouncers" \
"%%MAILMANDIR%%/Mailman/Cgi" \
"%%MAILMANDIR%%/Mailman/Commands" \
"%%MAILMANDIR%%/Mailman/Gui" \
"%%MAILMANDIR%%/Mailman/Handlers" \
"%%MAILMANDIR%%/Mailman/Logging" \
"%%MAILMANDIR%%/Mailman/MTA" \
"%%MAILMANDIR%%/Mailman/Queue" \
"%%MAILMANDIR%%/tests/bounces" \
"%%MAILMANDIR%%/tests/msgs" \
"%%MAILMANDIR%%/cron" \
"%%MAILMANDIR%%/data" \
"%%MAILMANDIR%%/lists" \
"%%MAILMANDIR%%/archives" \
"%%MAILMANDIR%%/archives/public"
# this can be 2770 or 2771 but should not be stomped over
test -d "%%MAILMANDIR%%/archives/private" \
|| /usr/bin/install -m 02771 -g "%%GROUP%%" \
-d "%%MAILMANDIR%%/archives/private"
/bin/chmod u+rwx,g+srwx "%%MAILMANDIR%%/archives/private"
/bin/chmod u+rwx,g+srwx,o+rx "%%MAILMANDIR%%/logs"
/usr/bin/find "%%MAILMANDIR%%/messages" "%%MAILMANDIR%%/templates" -type d \
-exec chmod 02775 '{}' +
echo "---> Running update"
LC_ALL=C "%%MAILMANDIR%%/bin/update"
echo "---> Checking crontab(5) file for user \"%%USER%%\""
if [ -e /var/cron/allow ]; then
grep -q "^%%USER%%\$" /var/cron/allow || \
printf '%s\n' "%%USER%%" >> /var/cron/allow
fi
if /usr/bin/crontab -u "%%USER%%" -l >"$MYTMP/crontab" 2>&1 ; then
if test -s "$MYTMP/crontab"; then
echo "---> \"%%USER%%\" already has a crontab. Not overwriting it"
echo "---> Please merge any changes from the standard crontab file"
echo "---> %%MAILMANDIR%%/cron/crontab.in"
else
echo "---> Installing crontab(5) file for user \"%%USER%%\""
/usr/bin/crontab -u "%%USER%%" "%%MAILMANDIR%%/cron/crontab.in"
fi
else
echo "---> Creating crontab(5) file for user \"%%USER%%\""
/usr/bin/crontab -u "%%USER%%" "%%MAILMANDIR%%/cron/crontab.in"
fi
rm -f "$MYTMP/crontab"
if check_rcfile_fix_perms ; then
echo "---> Checking (and fixing) file and directory permissions"
output="$("%%MAILMANDIR%%/bin/check_perms" -f 2>&1)" || :
printf '%s\n' "$output" | egrep -v '^Re-run' || :
else
echo "---> rcfile sets mailman_fix_perms to no, skipping check_perms"
fi
echo "---> Fixing up default host names (MAILHOST, URLHOST)"
sed -Ee "s}^(DEFAULT_(EMAIL|URL)_HOST) = '//'}\1 = '`hostname -f`'}" -i '' "%%MAILMANDIR%%/Mailman/Defaults.py"
echo "---> Running assorted other checks"
if egrep -q "^[ \t]*MTA.*=.*Postfix" "%%MAILMANDIR%%/Mailman/mm_cfg.py" ; then
# run Postfix-specific checks
POSTCONF=$(PATH="${PKG_PREFIX}/sbin:/usr/sbin:/sbin:$PATH" which postconf)
if [ "x`${POSTCONF} -h myhostname`" != "xlocalhost" ] \
&& ! egrep -q "^[ \t]*SMTPHOST.*=.*`${POSTCONF} -h myhostname`" \
"%%MAILMANDIR%%/Mailman/mm_cfg.py"
then
echo ""
echo "Your Postfix hostname is non-default."
echo -n "You must add \"SMTPHOST = '`${POSTCONF} -h myhostname`'"
echo "\" to the bottom of mm_cfg.py (without quotes)."
echo ""
fi
fi
;;
esac