#!/bin/sh

#
# $Log: tcpquotaconfig,v $
# Revision 1.4  1998/04/13 14:03:27  turbo
# If we have choosen to use the local mSQL server, remove the
# comment from the 'export MSQL...' lines
#
# Revision 1.3  1998/04/13 10:44:29  turbo
# Added a newline at the end
#
# Revision 1.2  1998/01/16 14:10:31  turbo
# * Make sure we could input characters _AND_ integers...
# * Only give out the remote address for verification if we have choosen the
#   ISDN protocol...
#
# Revision 1.1  1997/12/02 21:25:50  turbo
# Configure the TCPQuota package interactivly... Initial CVS revisition.
#
#

echo
echo "What protocol do you use to connect to the Internet?"
echo "  1. isdn"
echo "  2. ppp"
echo -n "? "
read prot
if [ "$prot" == "1"  -o "$prot" == "isdn" ]; then
    PROTOCOL=isdn
elif [ "$prot" == "2" -o "$prot" == "ppp" ]; then
    PROTOCOL=ppp
else
    echo "No such protocol, $prot"
    exit 1
fi

REM_ADDR=""
if [ "$PROTOCOL" == "isdn" ]; then
    echo
    echo "What IP address does THIS SIDE of the link have?"
    echo "(This is used to check if any one is using the link)"
    echo -n "? "
    read LOC_ADDR

    echo
    echo "What IP address do the other end of the link have?"
    echo "(This is used to double check if the link is realy up)"
    echo -n "? "
    read REM_ADDR
else
    LOC_ADDR=dynamic
fi

echo
echo "Where is the mSQL server which is servicing the TCPQuota database"
echo "located? (Fully Qualified Domain Name or IP address please) "
echo -n "If You are using the local mSQL server, say 'localhost' here: "
read SERVER

# Double check...
echo
echo
echo "Is the choosen configuration correct?"
echo "  Protocol:       $PROTOCOL"
echo "  Local address:  $LOC_ADDR"
if [ "$PROTOCOL" == "isdn" ]; then
  echo "  Remote address: $REM_ADDR"
fi
echo "  mSQL server:    $SERVER"
echo
echo -n "Okay? (Y/n)"
read ok

if [ "$ok" != "n" ]; then
    sed -e "s@%PROTOCOL%@$PROTOCOL@g" \
	-e "s@%LOC_ADDR%@$LOC_ADDR@g" \
	-e "s@%REM_ADDR%@$REM_ADDR@g" \
	-e "s@%SERVER%@$SERVER@g" \
	< /etc/tcpquota/tcpquota.cf > /tmp/tcpquota.cf

    chmod 644 /tmp/tcpquota.cf

    mv /etc/tcpquota/tcpquota.cf /etc/tcpquota/tcpquota.cf.old
    mv /tmp/tcpquota.cf /etc/tcpquota/tcpquota.cf
fi

if [ "$SERVER" == "localhost" ]; then
    sed -e "s/#export /export /g" \
    < /etc/init.d/tcpquotad > /tmp/tcpquotad

    mv /tmp/tcpquotad /etc/init.d/tcpquotad
fi

echo
