#!/bin/sh
# WARNING: This file was auto-generated. Do not edit!
fqdn="$1"
echo Your fully qualified host name is "$fqdn".

echo Putting "$fqdn" into control/me...
echo "$fqdn" > /usr/pkg/etc/qmail/.pkgsrc-defaults-do-not-edit/me
chmod 644 /usr/pkg/etc/qmail/.pkgsrc-defaults-do-not-edit/me

( echo "$fqdn" | sed 's/^\([^\.]*\)\.\([^\.]*\)\./\2\./' | (
  read ddom
  echo Putting "$ddom" into control/defaultdomain...
  echo "$ddom" > /usr/pkg/etc/qmail/.pkgsrc-defaults-do-not-edit/defaultdomain
  chmod 644 /usr/pkg/etc/qmail/.pkgsrc-defaults-do-not-edit/defaultdomain
) )

( echo "$fqdn" | sed 's/^.*\.\([^\.]*\)\.\([^\.]*\)$/\1.\2/' | (
  read pdom
  echo Putting "$pdom" into control/plusdomain...
  echo "$pdom" > /usr/pkg/etc/qmail/.pkgsrc-defaults-do-not-edit/plusdomain
  chmod 644 /usr/pkg/etc/qmail/.pkgsrc-defaults-do-not-edit/plusdomain
) )

echo Putting "$fqdn" into control/locals...
echo "$fqdn" >> /usr/pkg/etc/qmail/.pkgsrc-defaults-do-not-edit/locals
chmod 644 /usr/pkg/etc/qmail/.pkgsrc-defaults-do-not-edit/locals

echo Putting "$fqdn" into control/rcpthosts...
echo "$fqdn" >> /usr/pkg/etc/qmail/.pkgsrc-defaults-do-not-edit/rcpthosts
chmod 644 /usr/pkg/etc/qmail/.pkgsrc-defaults-do-not-edit/rcpthosts
echo "Now qmail will refuse to accept SMTP messages except to $fqdn."
echo 'Make sure to change rcpthosts if you add hosts to locals or virtualdomains!'
# $NetBSD: config-fast-pkgsrc-defaults.sh,v 1.2 2023/04/24 17:22:59 schmonz Exp $

SORT="/usr/bin/sort"
MV="mv -f"
CP="/bin/cp"

PKG_SYSCONFDIR="/usr/pkg/etc/qmail"
QMAIL_QUEUE_EXTRA=""

cd ${PKG_SYSCONFDIR}/.pkgsrc-defaults-do-not-edit
for i in locals rcpthosts; do
	${SORT} -u ${i} > ${i}.tmp && ${MV} ${i}.tmp ${i}
done

cd ${PKG_SYSCONFDIR}
for i in defaultdomain locals me plusdomain rcpthosts; do
	[ -f control/${i} ] \
		|| ${CP} .pkgsrc-defaults-do-not-edit/${i} control
done

cd ${PKG_SYSCONFDIR}/alias
for i in mailer-daemon postmaster root ${QMAIL_QUEUE_EXTRA}; do
	[ -s .qmail-${i} ] \
		|| echo '# pkgsrc says: replace this comment with your config' \
		> .qmail-${i}
	chmod 644 .qmail-${i}
done
