#! /bin/sh

##  $Id: fixconfig.in,v 1.1 2003/12/26 03:23:30 rra Exp $
##
##  Make variable substitutions in configuration files.
##
##  This script does something very similar to what config.status does, but
##  it fully resolves the various path variables (prefix, exec_prefix, etc.)
##  so that they don't contain any variable substitutions.  It's easier to
##  do this in a separate script than try to use eval or the like to resolve
##  the variable names inside configure, particularly since prefix and
##  exec_prefix aren't set until the end of the script.

# The paths set by configure.
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
libexecdir=@libexecdir@
sbindir=@sbindir@
sysconfdir=@sysconfdir@

# Additional paths specific to INN.
CONTROLDIR=@CONTROLDIR@
DBDIR=@DBDIR@
FILTERDIR=@FILTERDIR@
LOGDIR=@LOGDIR@
RUNDIR=@RUNDIR@
SPOOLDIR=@SPOOLDIR@
tmpdir=@tmpdir@

# Additional variables that are substituted into configuration files.
DO_PGPVERIFY=@DO_PGPVERIFY@
HOSTNAME=@HOSTNAME@
SENDMAIL=@SENDMAIL@

# We can probably just assume sed is on the path, but since we have it, we may
# as well use it.
SED=@SED@

input="$1"
if [ -z "$input" ] ; then
    echo "No input file specified" >&2
    exit 1
fi

output="$2"
if [ -z "$output" ] ; then
    output=`echo "$input" | sed 's/\.in$//'`
fi
if [ x"$input" = x"$output" ] ; then
    echo "No output file specified and input file doesn't end in .in" >&2
    exit 1
fi

$SED -e "s,@prefix\@,$prefix," \
     -e "s,@bindir\@,$bindir," \
     -e "s,@libexecdir\@,$libexecdir," \
     -e "s,@sbindir\@,$sbindir," \
     -e "s,@sysconfdir\@,$sysconfdir," \
     -e "s,@CONTROLDIR\@,$CONTROLDIR," \
     -e "s,@DBDIR\@,$DBDIR," \
     -e "s,@FILTERDIR\@,$FILTERDIR," \
     -e "s,@LOGDIR\@,$LOGDIR," \
     -e "s,@RUNDIR\@,$RUNDIR," \
     -e "s,@SPOOLDIR\@,$SPOOLDIR," \
     -e "s,@tmpdir\@,$tmpdir," \
     -e "s,@DO_PGPVERIFY\@,$DO_PGPVERIFY," \
     -e "s,@HOSTNAME\@,$HOSTNAME," \
     -e "s,@SENDMAIL\@,$SENDMAIL," < "$input" > "$output"
