# @configure_input@                                     -*- shell-script -*-
# Configurable variable values for tar test suite.
# Copyright (C) 2007-2020 Sergey Poznyakoff

PATH=@abs_builddir@:@abs_top_builddir@/src:@abs_top_builddir@/mtasim:@abs_top_srcdir@/build-aux:$top_srcdir:$srcdir:$PATH
MAILFROMD=@abs_top_builddir@/src/mailfromd
MF_IPV6_SUPPORT=@MF_IPV6_SUPPORT@

XFAILFILE=$abs_builddir/.badversion

STATEDIR=/tmp/mailfromd-$$

checkstatedir() {
  if test ! -d $STATEDIR; then
    mkdir $STATEDIR || exit 1
  fi
  MFADDOPTS="--state-directory=$STATEDIR"
}

cleanup() {
  rm -rf $STATEDIR
}

trap "cleanup; test -r $XFAILFILE && cat $XFAILFILE; exit $?" 1 2 13 15

MFOPTS="-I@abs_builddir@ -I@abs_builddir@/etc -I@abs_top_srcdir@/tests/etc -I@abs_top_srcdir@/src -I@abs_top_srcdir@/mflib --no-preprocess --no-config"
MFADDOPTS=
TESTDIR=@abs_builddir@
ETCDIR=@abs_top_srcdir@/tests/etc

PORT="unix:$STATEDIR/socket"
MTAOPTS="-X$PORT --stdio"
PIDFILE=$STATEDIR/pid

mailfromd_start() {
  checkstatedir
  mailfromd $MFOPTS $MFADDOPTS \
    --port=$PORT \
    --pidfile=$PIDFILE \
    --debug=100\
    --daemon \
    $ETCDIR/$1  
}

mailfromd_stop() {
  if test -r $PIDFILE; then
	kill -TERM `head -n 1 $PIDFILE`
  fi
  cleanup
}

cleardb() {
  checkstatedir
}

: ${MF_TOPDOMAIN:=mf.gnu.org.ua}
: ${MF_NAMESERVER:=$(resolv -qq soa -ip $MF_TOPDOMAIN)}
export MF_TOPDOMAIN MF_NAMESERVER

at_resolv_conf() {
    if [ -n "$MF_NAMESERVER" ] && resolv -h$MF_NAMESERVER -qqq soa -ip 2.0.192.in-addr.arpa; then
	cat > resolv.conf <<EOF
nameserver $MF_NAMESERVER
EOF
	MFOPTS="$MFOPTS --resolv-conf=resolv.conf"
    fi
    test -f resolv.conf
}

export RES_CONF_TEXT
