#!/bin/sh
#
# This script makes the necessary changes to the /etc/inetd.conf and
# /etc/services configuration files to incorporate the WhatsNew HTTP
# service (port 8778).
#
# "$Revision: 1.2 $"

ETC=${rbase}/etc
HTTPD=${rbase}/var/www/server/httpd.exe

# We must be root to change the system files:

if [ ! -w ${rbase}/bin/su ] ; then
   echo "You need to be root to run this script."
   exit 1
fi

# Set up the /etc/services entry
#
# Note: if you're using NIS, make sure the NIS master for the services
# database has the following entry.

grep '^wn-http' ${ETC}/services 1>/dev/null 2>&1
if [ $? -ne 0 ]; then
   echo "wn-http\t\t8778/tcp\t\t# WhatsNew http protocol" >>${ETC}/services
fi

if [ ! -f $HTTPD ] ; then
   echo "Error: can't find /var/www/server/httpd"
   exit 1
fi

# Setup inetd.conf to fire off the daemon

grep '^wn-http' ${ETC}/inetd.conf 1>/dev/null 2>&1
if [ $? -ne 0 ]; then
   echo "wn-http\tstream\ttcp\tnowait\tnobody\t?/var/www/server/wn-httpd -f /var/www/conf/httpd.conf" \
   	>> ${ETC}/inetd.conf

    #
    # If in the running (live) system root, then enable the daemon
    #
    if [ -z "${rbase}" -o "${rbase}" = "/" ] ; then
       echo "Starting httpd daemon"
       /etc/killall -HUP inetd
    fi
fi

# Finally, create the link between the new service and the "real" service

rm -f /var/www/server/wn-httpd
ln -s /var/www/server/httpd.exe /var/www/server/wn-httpd

