#!/bin/sh
#	$Header: /a/cvs/386BSD/ports/flexfax/configure,v 1.1 1993/08/31 20:52:25 ljo Exp $
#
# FlexFAX Facsimile Software
#
# Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993 Sam Leffler
# Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
# 
# Permission to use, copy, modify, distribute, and sell this software and 
# its documentation for any purpose is hereby granted without fee, provided
# that (i) the above copyright notices and this permission notice appear in
# all copies of the software and related documentation, and (ii) the names of
# Sam Leffler and Silicon Graphics may not be used in any advertising or
# publicity relating to the software without the specific, prior written
# permission of Sam Leffler and Silicon Graphics.
# 
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
# 
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
# OF THIS SOFTWARE.
#

# Configuration script for FlexFAX 2.1

#
# Shell script to setup machine-dependent files in
# preparation for building flexfax source.
#
RM="rm -f"

PATH=/bin:/usr/bin:/etc
test -d /usr/ccs/bin && PATH=$PATH:/usr/ccs/bin		# SVR4/Solaris2
test -d /usr/sbin && PATH=$PATH:/usr/sbin		# SGI and others
test -d /usr/bsd && PATH=$PATH:/usr/bsd			# SGI
test -d /usr/ucb && PATH=$PATH:/usr/ucb			# Sun and others
test -d /usr/5bin && PATH=/usr/5bin:$PATH:/usr/etc	# Sun and others

applyEdits()
{
    file=$1; shift
    (for i
     do
	echo "$i";
     done; echo w; echo q) | ed - $file >/dev/null
}

editFile()
{
    if [ ! -w $1 ]; then
	chmod +w $1
	applyEdits "$@"
	chmod -w $1
    else
	applyEdits "$@"
    fi
}

identifyTarget()
{
    random=`date | awk '{print $4}' | sed -e 's/.*://'` 2>/dev/null
    case "$random" in
    1*)	echo "Wow, you've got a $1 system!";;
    2*)	echo "Hmm, looks like a $1 system.";;
    3*)	echo "Oh no, not another $1 system...";;
    4*)	echo "Well I'll be, a $1 system.";;
    5*)	echo "Fee, fie, foe, this smells like a $1 system.";;
    *)	echo "Gosh, aren't you lucky to have a $1 system!";;
    esac
}

#
# If no target is specified, try to deduce the system.
#
TARGET=$1
if [ -z "$TARGET" ]; then
    SYS=`uname -s` 2>/dev/null
    case @"$SYS" in
    @IRIX)	TARGET=sgi;;
    @UNIX_SV)	TARGET=svr4;;
    @Linux)	TARGET=linux;;
    @SunOS)	if [ -d /etc/saf ]; then
		    TARGET=solaris2 SYS="Solaris 2.x"
		else
		    TARGET=sun4
		fi
		;;
    @BSD/386)	TARGET=bsdi;;
    @4.4BSD)	TARGET=4.4bsd;;
    @386BSD)	TARGET=386bsd;;
    @FreeBSD)	TARGET=freebsd;;
    @)		echo "Sorry, no target specified and no uname command!";exit 1;;
    *)		if [ -d /etc/saf ]; then
		    TARGET=svr4 SYS=SVR4
		else
		    echo "Sorry, I don't grok a $SYS system."
		    exit 1
		fi
		;;
    esac
    identifyTarget $SYS
fi

warnUnfinished()
{
    echo "This configuration is unfinished; read port/$1/README for more info."
}

case $TARGET in
sgi|sgi-cc)
    TARGET=sgi COMPILER=cc
    ;;
sgi-gcc)
    TARGET=sgi COMPILER=gcc
    ;;
sun|sun-gcc|sun3|sun3-gcc|sun4|sun4-gcc)
    TARGET=sun COMPILER=gcc
    ;;
svr4|svr4-gcc)
    TARGET=svr4 COMPILER=gcc
    warnUnfinished $TARGET
    ;;
sco|sco-gcc)
    TARGET=sco COMPILER=gcc
    warnUnfinished $TARGET
    ;;
solaris2|solaris2-gcc)
    TARGET=solaris2 COMPILER=gcc
    warnUnfinished $TARGET
    ;;
bsdi|bsdi-gcc)
    TARGET=bsdi COMPILER=gcc
    warnUnfinished $TARGET
    ;;
linux)
    TARGET=linux COMPILER=gcc
    warnUnfinished $TARGET
    ;;
386bsd|386bsd-gcc)
    TARGET=386bsd COMPILER=gcc
    warnUnfinished $TARGET
    ;;
freebsd|freebsd-gcc)
    TARGET=freebsd COMPILER=gcc
    warnUnfinished $TARGET
    ;;
4.4bsd|4.4bsd-gcc)
    TARGET=4.4bsd COMPILER=gcc
    warnUnfinished $TARGET
    ;;
*)
    echo "$TARGET: Unsupported configuration."
    exit 1;;
esac

if [ "$TARGET" = linux ] ; then
    ed()
    {
        sed -e '/^w$/d' -e '/^q$/d' > /tmp/ed.$$
        cp $2 /tmp/file.$$
        sed -f /tmp/ed.$$ /tmp/file.$$ > $2
        $RM /tmp/ed.$$ /tmp/file.$$
    }
fi

#
# Setup make-related files.
#
setupConfig()
{
    if [ -f port/$TARGET/Makefile.flexfax ]; then
	M=port/$TARGET/Makefile.flexfax
    elif [ -f port/$TARGET/Makefile ]; then
	M=port/$TARGET/Makefile
    else
	echo "Help, no Makefile for building FlexFAX!"; exit 1
    fi
    if [ -f port/$TARGET/defs.$COMPILER ]; then
	D=port/$TARGET/defs.$COMPILER
    elif [ -f port/$TARGET/defs ]; then
	D=port/$TARGET/defs
    else
	echo "Help, no defs for building FlexFAX!"; exit 1
    fi
    echo "Installing $M as Makefile."
    $RM Makefile; cp $M Makefile
    echo "Installing $D as defs."
    $RM defs; cp $D defs
}
getConfigTag()
{
    param=`grep "$1:" $2 | sed -e 's/.*:[ 	]*\([^ 	]*\).*/\1/'`
}

echo "Setting up make-related files."
if [ -f defs -a -f Makefile ]; then
    getConfigTag TARGET defs;	target="$param"
    getConfigTag COMPILER defs;	compiler="$param"
    if [ "$target" != "$TARGET" -o "$compiler" != "$COMPILER" ]; then
	echo "Replacing configuration for \"$target\" & \"$compiler\"."
	setupConfig
    else
	#
	# We should figure out if only localized changes were
	# done to defs and/or Makefile and leave things unchanged;
	# but for now that's too hard so we just cloberr things
	# under the assumption that folks don't configure very
	# often and doing something simpleminded can lead to problems.
	#
	echo "Updating configuration for \"$target\" & \"$compiler\"."
	setupConfig
    fi
else
    setupConfig
fi

#
# Verify that defs has correct C++ and C compiler definitions.
#
(cat defs; echo 'test: ${C++} ${CC}') | make -f - test >/dev/null 2>&1 || {
    echo ""
    echo "Something is wrong in the \"defs\" file, check the definitions of"
    echo "the C++ and CC macros:"
    echo ""
    grep '^C++[ 	]*=' defs; grep '^CC[ 	]*=' defs
    echo ""
    echo "they do not appear to reflect the locations of your compilers."
    exit 1
}

if [ $COMPILER = gcc ]; then
    version=`(cat defs; echo 'version: ${C++}; ${C++} -v') | \
	make -f - version 2>&1 | \
	sed -n -e '/version/s/.* //p'`
    if expr "$version" \< 2.3.3 >/dev/null 2>&1; then
	echo ""
	echo "You appear to have gcc version $version; beware that you"
	echo "may need to apply the patch in port/sun/GCC-PATCH before you"
	echo "compile this software."
	echo ""
    else
	# NB: /^GC++DEFS/ does not work under BSDi
	editFile defs '/^GC[+][+]DEFS/s/$/ -DNEW_FIXED/'
    fi
fi

if [ $TARGET != "sgi" ]; then
    echo "Setting up make dependency files."
    #
    # Setup null make dependency files so that we can include
    # it w/o problem.  Some systems have conditional include
    # support in their make, but others do not, so we use an
    # unconditional include and setup everthing as null here
    #
    DEPEND="Makedepend		\
	fax2ps/Makedepend	\
	faxalter/Makedepend	\
	faxcover/Makedepend	\
	faxd/Makedepend		\
	faxmail/Makedepend	\
	faxrm/Makedepend	\
	faxstat/Makedepend	\
	iv/Makedepend		\
	recvfax/Makedepend	\
	sendfax/Makedepend	\
	sgi2fax/Makedepend	\
	util/Makedepend		\
	man/Makedepend		\
	doc/Makedepend		\
	etc/Makedepend		\
	relnotes/Makedepend	\
	libtiff/Makedepend	\
	port/$TARGET/Makedepend	\
	"
    $RM $DEPEND; tee $DEPEND </dev/null
    editFile rules '/^sinclude/s//include/'
fi

#
# Install appropriate TIFF library Makefile: look first
# in the port area, then for a Makefile that is part of
# the standard TIFF distribution.  The priority is:
#
# port/<target>/Makefile.libtiff.<compiler>
# port/<target>/Makefile.libtiff
# port/generic/Makefile.libtiff.<compiler>
# port/libtiff/Makefile.<target>-<compiler>
# port/libtiff/Makefile.<target>
# port/libtiff/Makefile.<compiler>
#
if [ -f port/$TARGET/Makefile.libtiff.$COMPILER ]; then
    M=port/$TARGET/Makefile.libtiff.$COMPILER
elif [ -f port/$TARGET/Makefile.libtiff ]; then
    M=port/$TARGET/Makefile.libtiff
elif [ -f port/generic/Makefile.libtiff.$COMPILER ]; then
    M=port/generic/Makefile.libtiff.$COMPILER
elif [ -f libtiff/Makefile.$TARGET-$COMPILER ]; then
    M=libtiff/Makefile.$TARGET-$COMPILER
elif [ -f libtiff/Makefile.$TARGET ]; then
    M=libtiff/Makefile.$TARGET
elif [ -f libtiff/Makefile.$COMPILER ]; then
    M=libtiff/Makefile.$COMPILER
else
    echo "Can not locate Makefile for building the TIFF software."
    exit 1
fi
echo "Installing $M as libtiff/Makefile."
$RM libtiff/Makefile; cp $M libtiff/Makefile

#
# Some makes can not deal with certain types of
# whitespace-filled lines that occasionally creep
# in--so purge anything strange before compiling.
#
badMakefiles=`grep -l '^	$' Makefile */Makefile`
if [ "$badMakefiles" ]; then
    #
    # This bizarre stuff is used instead of just doing
    # editFile $m '^<tab>$/s///' because some shells
    # appear to convert the tab to a blank!
    #
    echo '/^	$/s///' | tr ' ' '\011' >/tmp/$$ed
    echo w >>/tmp/$$ed; echo q >>/tmp/$$ed
    echo "Fixing up bad make files:"
    for m in $badMakefiles; do
	echo "  $m"
	chmod +w $m; cat /tmp/$$ed | ed - $m >/dev/null; chmod -w $m
    done
    $RM /tmp/$$ed
fi

patchForBogusIncludeSyntax()
{
    echo "Warning, patching Makefile stuff to use bogus include syntax."
    for i
    do
	editFile $i "g/^include/s/^include[  ]*\(.*\)$/.include <\1>/"
    done
}

case "$TARGET-$COMPILER" in
386bsd*|freebsd)
    echo "Warning, patching etc/faxaddmodem.sh to use bash"
    editFile etc/faxaddmodem.sh "/^#! /s;/bin/sh;/bin/bash;"
    ;;
bsdi-gcc)
    $RM port/$TARGET/stdio.h; cp /usr/include/stdio.h port/$TARGET
    editFile port/$TARGET/stdio.h '/static inline int/s//static int/'
    ;;
sgi-cc)
    #
    # Patch C++ options to remove -v2 option that forces
    # the CC frontend to use the old 2.1 compiler.
    #
    VERS=`versions 'c++.sw' | \
	grep 'c++' | sed -e 's/.*C++,[ ]*//;q'`
    case "$VERS" in
    3.0|2.*)
	;;
    *)  VERS=`versions 'maint_c++.c++_sw' | \
	grep 'c++' | sed -e 's/.*C++,[ ]*//;q'`
	;;
    esac
    if [ -z "$VERS" ]; then
	VERS="2.1"
    fi
    case "$VERS" in
    3.0)
	echo "You look to have a $VERS C++ compiler; using"
	echo "the -v2 option to get the 2.1 version compiler."
	;;
    2.*)
	echo "You've got a $VERS compiler; removing the -v2"
	echo "option used with the 3.0 compiler system."
	editFile defs '/^GC++OPTS=/s/[ ]*-v2//'
    	;;
    *)
	echo "I can't figure out what version of the compiler you have!"
	exit 1
	;;
    esac
    ;;
4.4bsd*)
    patchForBogusIncludeSyntax Makefile rules */Makefile
    ;;
esac

#
# Figure out if certain system-specific interfaces are
# supported and modify defs accordingly.  This whole part
# of the configuration process needs lots of work.  At the
# very least, it should be done dynamically rather than
# according to the target system.
#
sysopts=
case $TARGET in
sco*)	sysopts="-DSYS_FCHOWN=0 -DSYS_FCHMOD=0";;
*)	sysopts="-DSYS_FCHOWN=1 -DSYS_FCHMOD=1";;
esac
echo "Patching defs to reflect system support."
editFile defs "/^GC++DEFS=/s/\$/ $sysopts/" "/^GCDEFS=/s/\$/ $sysopts/"

#
# Figure out which brand of echo we have and define
# prompt and print shell functions accordingly.
#
if [ `echo foo\\\c`@ = "foo@" ]; then
    prompt()
    {
       echo "$* \\c"
    }
elif [ "`echo -n foo`@" = "foo@" ]; then
    prompt()
    {
       echo -n "$* "
    }
else
    prompt()
    {
	echo "$*"
    }
fi

#
# Prompt the user for a string that can not be null.
#
promptForNonNullStringParameter()
{
    x=""
    while [ -z "$x" ]; do
	prompt "$2 [$1]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	else
	    x="$1"
	fi
    done
    param="$x"
}

#
# Prompt the user for a numeric value.
#
promptForNumericParameter()
{
    x=""
    while [ -z "$x" ]; do
	prompt "$2 [$1]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    match=`expr "$x" : "\([0-9]*\)"`
	    if [ "$match" != "$x" ]; then
		echo ""
		echo "This must be entirely numeric; please correct it."
		echo ""
		x="";
	    fi
	else
	    x="$1"
	fi
    done
    param="$x"
}

promptForLockType()
{
    x=""
    while [ -z "$x" ]; do
	prompt "Type of uucp lock files [$UUCP_LOCKTYPE]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    if [ "$x" != "ascii" -a "$x" != "binary" ]; then
cat <<EOF

"$x" is not a uucp lock type; choose either "ascii"
for System V-style lock files with ascii contents or
"binary" for BSD-style lock files with binary contents.
EOF
		x=""
	    fi
	else
	    x="$UUCP_LOCKTYPE"
	fi
    done
    UUCP_LOCKTYPE="$x"
}

promptForImager()
{
    x=""
    while [ -z "$x" ]; do
	prompt "Type of PostScript imager [$PSIMAGER]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    case "$x" in
	    [dD]ps|DPS)			x="dps";;
	    [gG]s|[gG]host[sS]cript)	x="gs";;
	    *)
cat <<EOF

"$x" is not a PostScript imager; choose either "dps"
for Display PostScript on a Silicon Graphics machine
or "gs" for Ghostscript.
EOF
		x="";;
	    esac
	else
	    x="$PSIMAGER"
	fi
    done
    PSIMAGER="$x"
}

promptForPageSize()
{
    x=""
    while [ -z "$x" ]; do
	prompt "Default page size [$PAGESIZE]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    # search pagesizes file for an entry
	    y=`sed -e '/^#/d' $1 | grep -i "$x" | sed -e 's/	.*//;q`
	    if [ -z "$y" ]; then
		cat<<EOF

"$x" is not a known page size; the following are known page sizes:

Name			Abbrev	Width	Height	Width	Height	Top	Left
EOF
		sed -e '/^#/d' -e '/^default/d' $1
		echo ""
		x=""
	    else
		x="$y"
	    fi
	else
	    x="$PAGESIZE"
	fi
    done
    PAGESIZE="$x"
}

#
# Prompt the user for a numeric value.
#
promptForVRes()
{
    x=""
    while [ -z "$x" ]; do
	prompt "Default vertical res (lpi) [$FAX_DEFVRES]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    case "$x" in
	    98|low|med*)	x="98";;
	    196|high|fine)	x="196";;
	    *)
cat <<EOF

"$x" is not a valid vertical resolution; choose either "98" lines/inch
(low resolution) or "196" lines/inch (often called fine resolution).

EOF
		x="";;
	    esac
	else
	    x="$FAX_DEFVRES"
	fi
    done
    FAX_DEFVRES="$x"
}

getParameter()
{
    param=`grep "^$1[ 	]*=" $2 | \
	sed -e 's/#.*//' -e 's/.*=[ 	]*//' -e 's/[ 	]*$//'`
}
getPageSizeInfo()
{
    pat=`grep '^default' $1 | \
	sed -e 's/default[	 ]*//' -e 's/[ 	][ 	]*/\[ 	\]*/g'`
    param=`grep "$pat" $1 | sed -e 's/	.*//;q'`
}
getUtilParameter()
{
    param=`grep "$1" $2 | sed -e "s/.*$1[ 	]*\([^	 ]*\).*/\1/"`
}

getProtoParameters()
{
    getParameter BIN $1; 			FAX_BINDIR="$param"
    getParameter LIBDATA $1; 			FAX_LIBDATA="$param"
    getParameter LIBEXEC $1; 			FAX_LIBEXEC="$param"
    getParameter SPOOL $1; 			FAX_SPOOLDIR="$param"
    getParameter USRETC $1;			USRETC="$param"
    getParameter MAN $1; 			MAN="$param"
    getParameter DOC $1; 			DOC="$param"
    getParameter PSIMAGER $1;			PSIMAGER="$param"
    getParameter AFMDIR $1;			AFMDIR="$param"
    getParameter UUCP_LOCKTYPE $1;		UUCP_LOCKTYPE="$param"
    getParameter UUCP_LOCKMODE $1;		UUCP_LOCKMODE="$param"
    getParameter UUCP_LOCKDIR $1;		UUCP_LOCKDIR="$param"
    getParameter PS util/ps2fax.$PSIMAGER.sh;	PS="$param"
    getParameter SENDMAIL $1;			SENDMAIL="$param"
    getPageSizeInfo util/pagesizes;		PAGESIZE="$param"
    getUtilParameter FAX_DEFVRES util/config.h;	FAX_DEFVRES="$param"
}

saveProtoParameters()
{
    protoFAX_BINDIR="$FAX_BINDIR"
    protoFAX_LIBDATA="$FAX_LIBDATA"
    protoFAX_LIBEXEC="$FAX_LIBEXEC"
    protoFAX_LIBFILTER="$FAX_LIBFILTER"
    protoFAX_SPOOLDIR="$FAX_SPOOLDIR"
    protoUSRETC="$USRETC"
    protoMAN="$MAN"
    protoDOC="$DOC"
    protoPSIMAGER="$PSIMAGER"
    protoAFMDIR="$AFMDIR"
    protoUUCP_LOCKTYPE="$UUCP_LOCKTYPE"
    protoUUCP_LOCKMODE="$UUCP_LOCKMODE"
    protoUUCP_LOCKDIR="$UUCP_LOCKDIR"
    protoSENDMAIL="$SENDMAIL"
    protoPAGESIZE="$PAGESIZE"
    protoFAX_DEFVRES="$FAX_DEFVRES"
}

printConfig()
{
    cat<<EOF

FlexFAX configuration parameters are:

Directory for applications:	$FAX_BINDIR
Directory for lib data files:	$FAX_LIBDATA
Directory for lib executables:	$FAX_LIBEXEC
Directory for servers:		$USRETC
Directory for manual pages:	$MAN
Directory for documentation:	$DOC
Directory for spooling:		$FAX_SPOOLDIR
Type of uucp lock files:	$UUCP_LOCKTYPE
Directory for uucp lock files:	$UUCP_LOCKDIR
Mode for uucp lock files:	$UUCP_LOCKMODE
Type of PostScript imager:	$PSIMAGER
PostScript imager program:	$PS
Default page size:		$PAGESIZE
Default vertical res (lpi):	$FAX_DEFVRES
Directory for font metrics:	$AFMDIR
Location of sendmail program:	$SENDMAIL

EOF
}

#
# Gag, this is because BSDi Gamma 4 does not implement test -x!
#
checkForExecutable()
{
    if [ $TARGET = "bsdi" ]; then
	# work around BSDi not implementing test -x!
	if [ ! -f $1 ]; then
	    echo ""
	    echo "Warning, $1 does not seem to be an executable program;"
	    echo "you will need to correct this before starting up the fax server."
	fi
    elif [ ! -x $1 ]; then
	echo ""
	echo "Warning, $1 does not seem to be an executable program;"
	echo "you'll need to correct this before starting up the fax server."
    fi
}

checkDirectory()
{
    if [ ! -d $1 ]; then
	echo ""
	echo "Warning, $1 does not seem to be a directory;"
	shift;
	for i
	do
	    echo "$i"
	done
    fi
}

#
# Setup general configuration parameters.
#
getProtoParameters defs
saveProtoParameters

# convert uucp lock type to something understandable
case "$UUCP_LOCKTYPE" in
1) UUCP_LOCKTYPE="binary";;
*) UUCP_LOCKTYPE="ascii";;	# default
esac

ok=skip
while [ "$ok" != "" -a "$ok" != "y" -a "$ok" != "yes" ]; do
    if [ "$ok" != "skip" ]; then
	promptForNonNullStringParameter "$FAX_BINDIR" \
	    "Directory to install applications";	FAX_BINDIR="$param"
	promptForNonNullStringParameter "$FAX_LIBDATA" \
	    "Directory to install library data files";	FAX_LIBDATA="$param"
	promptForNonNullStringParameter "$FAX_LIBEXEC" \
	    "Directory to install library executables";	FAX_LIBEXEC="$param"
	promptForNonNullStringParameter "$USRETC" \
	    "Directory to install server programs";	USRETC="$param"
	promptForNonNullStringParameter "$MAN" \
	    "Directory to install manual pages";	MAN="$param"
	promptForNonNullStringParameter "$DOC" \
	    "Directory to install documentation";	DOC="$param"
	promptForNonNullStringParameter "$FAX_SPOOLDIR" \
	    "Directory to setup server spooling area";	FAX_SPOOLDIR="$param"
	promptForLockType;
	promptForNonNullStringParameter "$UUCP_LOCKDIR" \
	    "Directory for uucp lock files";		UUCP_LOCKDIR="$param"
	promptForNumericParameter "$UUCP_LOCKMODE" \
	    "Protection mode for uucp lock files";	UUCP_LOCKMODE=$param;
	promptForImager;
	getParameter PS util/ps2fax.$PSIMAGER.sh;	PS="$param"
	promptForNonNullStringParameter "$PS" \
	    "PostScript imager program";		PS="$param"
	promptForPageSize util/pagesizes;
	promptForVRes;
	promptForNonNullStringParameter "$AFMDIR" \
	    "Directory to find Adobe font metrics";	AFMDIR="$param"
	promptForNonNullStringParameter "$SENDMAIL" \
	    "Location of sendmail program";		SENDMAIL="$param"
    fi
    checkDirectory $USRETC \
"this must be fixed before doing a make install of faxd and faxd.recv."
    checkDirectory $AFMDIR \
"this means that only a crummy builtin font will be available for imaging text."
    checkForExecutable $PS
    checkForExecutable $SENDMAIL
    # make sure UUCP_LOCKMODE is an octal number
    if [ "`expr "$UUCP_LOCKMODE" : '\(.\)'`" != "0" ]; then
	UUCP_LOCKMODE="0${UUCP_LOCKMODE}"
    fi
    printConfig; prompt "Are these ok [yes]?"; read ok
done

# convert uucp lock type back to a #define
case "$UUCP_LOCKTYPE" in
ascii)	UUCP_LOCKTYPE=0;;
binary)	UUCP_LOCKTYPE=1;;
*)	echo "Help, uucp lock type is \"$UUCP_LOCKTYPE\"; shouldn't happen!"
	exit 1
	;;
esac

echo ""

#
# defs include file for all Makefiles
#
if [    "$FAX_BINDIR"	!= "$protoFAX_BINDIR"	\
     -o "$FAX_LIBDATA"	!= "$protoFAX_LIBDATA"	\
     -o "$FAX_LIBEXEC"	!= "$protoFAX_LIBEXEC"	\
     -o "$FAX_SPOOLDIR"	!= "$protoFAX_SPOOLDIR"	\
     -o "$USRETC"	!= "$protoUSRETC"	\
     -o "$MAN"		!= "$protoMAN"		\
     -o "$DOC"		!= "$protoDOC"		\
     -o "$AFMDIR"	!= "$protoAFMDIR"	\
     -o "$UUCP_LOCKTYPE" != "$protoUUCP_LOCKTYPE" \
     -o "$UUCP_LOCKMODE" != "$protoUUCP_LOCKMODE" \
     -o "$UUCP_LOCKDIR"	!= "$protoUUCP_LOCKDIR" \
     -o "$SENDMAIL"	!= "$protoSENDMAIL" \
]; then
    prompt "Set config parameters in the defs file [yes]?"; read x
    if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
	editFile defs \
	    "/^BIN[ 	]*=/s;=[^#]*;=${FAX_BINDIR};" \
	    "/^LIBDATA[ 	]*=/s;=[^#]*;=${FAX_LIBDATA};" \
	    "/^LIBEXEC[ 	]*=/s;=[^#]*;=${FAX_LIBEXEC};" \
	    "/^SPOOL[ 	]*=/s;=[^#]*;=${FAX_SPOOLDIR};" \
	    "/^USRETC[ 	]*=/s;=[^#]*;=${USRETC};" \
	    "/^MAN[ 	]*=/s;=[^#]*;=${MAN};" \
	    "/^DOC[ 	]*=/s;=[^#]*;=${DOC};" \
	    "/^AFMDIR[ 	]*=/s;=[^#]*;=${AFMDIR};" \
	    "/^UUCP_LOCKTYPE[ 	]*=/s;=[^#]*;=${UUCP_LOCKTYPE};" \
	    "/^UUCP_LOCKMODE[ 	]*=/s;=[^#]*;=${UUCP_LOCKMODE};" \
	    "/^UUCP_LOCKDIR[ 	]*=/s;=[^#]*;=${UUCP_LOCKDIR};" \
	    "/^SENDMAIL[ 	]*=/s;=[^#]*;=${SENDMAIL};"
    fi
fi

#
# util/config.h has definitions included by all source code.
#
getHParameter()
{
    param=`grep "$1" $2 | sed -e 's/.*"\(.*\)".*/\1/'`
}
f=util/config.h
getHParameter FAX_SPOOLDIR $f;	protoFAX_SPOOLDIR="$param"
getHParameter FAX_LIBDATA $f;	protoFAX_LIBDATA="$param"
getHParameter FAX_LIBEXEC $f;	protoFAX_LIBEXEC="$param"
getUtilParameter FAX_DEFVRES $f; protoFAX_DEFVRES="$param"
if [    "$FAX_LIBDATA"	!= "$protoFAX_LIBDATA"	\
     -o "$FAX_LIBEXEC"	!= "$protoFAX_LIBEXEC"	\
     -o "$FAX_SPOOLDIR"	!= "$protoFAX_SPOOLDIR"	\
     -o "$FAX_DEFVRES"	!= "$protoFAX_DEFVRES"	\
]; then
    prompt "Set config parameters in $f [yes]?"; read x
    if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
	editFile $f \
	    "/FAX_LIBDATA/s;${protoFAX_LIBDATA};${FAX_LIBDATA};" \
	    "/FAX_LIBEXEC/s;${protoFAX_LIBEXEC};${FAX_LIBEXEC};" \
	    "/FAX_SPOOLDIR/s;${protoFAX_SPOOLDIR};${FAX_SPOOLDIR};" \
	    "/FAX_DEFVRES/s;${protoFAX_DEFVRES};${FAX_DEFVRES};"
    fi
fi

#
# etc/faxaddmodem.sh is the modem installation and configuration
# script; it has server-related definitions built into it.
#
f=etc/faxaddmodem.sh
quit=$FAX_BINDIR/faxquit
getParameter SPOOL $f;		protoFAX_SPOOLDIR="$param"
getParameter SERVERDIR $f;	protoUSRETC="$param"
getParameter LOCKDIR $f;	protoUUCP_LOCKDIR="$param"
getParameter QUIT $f;		protoQUIT="$param"
    getParameter FAXUSER defs;	PROTOUID="$param"
getParameter PROTOUID $f;	protoPROTOUID="$param"
    getParameter FAXGROUP defs;	PROTOGID="$param"
getParameter PROTOGID $f;	protoPROTOGID="$param"
if [    "$FAX_SPOOLDIR"	!= "$protoFAX_SPOOLDIR" \
     -o "$PROTOUID"	!= "$protoPROTOUID" \
     -o "$PROTOGID"	!= "$protoPROTOGID" \
     -o "$USRETC"	!= "$protoUSRETC" \
     -o "$UUCP_LOCKDIR"	!= "$protoUUCP_LOCKDIR" \
     -o "$quit"		!= "$protoQUIT" \
]; then
    prompt "Set config parameters in $f [yes]?"; read x
    if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
	editFile $f \
	    "/^SPOOL=/s;${protoFAX_SPOOLDIR};${FAX_SPOOLDIR};" \
	    "/^PROTOUID=/s;${protoPROTOUID};${PROTOUID};" \
	    "/^PROTOGID=/s;${protoPROTOGID};${PROTOGID};" \
	    "/^SERVERDIR=/s;${protoUSRETC};${USRETC};" \
	    "/^LOCKDIR=/s;${protoUUCP_LOCKDIR};${UUCP_LOCKDIR};" \
	    "/^QUIT=/s;=.*/faxquit;=${FAX_BINDIR}/faxquit;"
    fi
fi

#
# util/ps2fax.*.sh is the shell script that invokes the
# PostScript imager; it has the location of the imager
#
f=util/ps2fax.$PSIMAGER.sh
getParameter PS $f
if [ "$PS" != "$param" ]; then
    prompt "Set config parameters in $f [yes]?"; read x
    if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
	editFile $f "/^PS=/s;${param};${PS};"
    fi
fi

#
# Several scripts are aware of the location of the spooling
# area and of the mailer.
#
# util/faxrcvd.sh	for anonymous received facsimile
# util/pollrcvd.sh	for polled received facsimile
# util/notify.sh	for server notification of events
#
for f in util/faxrcvd.sh util/pollrcvd.sh util/notify.sh
do
    getParameter SPOOL $f;	protoSPOOL="$param"
    getParameter SENDMAIL $f;	protoSENDMAIL="$param"
    if [   "$FAX_SPOOLDIR"	!= "$protoSPOOL" \
	-o "$SENDMAIL"	!= "$protoSENDMAIL" \
    ]; then
	prompt "Set config parameters in $f [yes]? "; read x
	if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
	    editFile $f \
		"/^SENDMAIL=/s;${protoSENDMAIL};${SENDMAIL};" \
		"/^SPOOL=/s;${protoFAX_SPOOLDIR};${FAX_SPOOLDIR};"
	fi
    fi
done

f=util/pagesizes
if [ "$PAGESIZE" != "$protoPAGESIZE" ]; then
    prompt "Set config parameter in $f [yes]? "; read x
    if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
	newDefault=`grep "$PAGESIZE" $f | sed -e 's/[^	]*/default/;q'`
	editFile $f "/^default/s/.*/$newDefault/"
    fi
fi
echo "Done."
exit 0
