# File:         insserv
#
# Author:       Ulli Horlacher (framstag@rus.uni-stuttgart.de)
#
# History:      18 Sep 95   Framstag      initial version
#               24 Nov 95   Framstag      changed SAFT-port
#
# Shell script to install the server of the sendfile service.
# Called by make.
#
# This file is covered by the GNU General Public License
#

SERVERDIR=$1
BIN=$2
if [ "$SERVERDIR" = "" ]; then SERVERDIR=/usr/local/sbin; fi
if [ "$BIN" = "" ]; then BIN=/usr/local/bin; fi

echo installing sendfile-daemon in $SERVERDIR
mkdir $SERVERDIR 2>/dev/null
cp sendfiled $SERVERDIR


if [ ! -f /etc/nosendfile ]; then 
  echo installing sendfile blacklist in /etc
  cp nosendfile /etc/nosendfile
  chmod 644 /etc/nosendfile
fi

SERVICES="`grep '[	]487/tcp' /etc/services`"
if [ "$SERVICES" != "" ]; then
  case "$SERVICES" in 
    saft*)	;;
    *)		echo "install-error: tcp-port 487 is already in use!"; exit 1;;
  esac
else
  echo configuring /etc/services
  echo "saft	487/tcp	# simple asynchronous file transfer" >>/etc/services
fi

if [ "`grep '^saft' /etc/inetd.conf`" = "" ]; then
  echo configuring /etc/inetd.conf
  cat <<EOD>>/etc/inetd.conf

# simple asynchronous file transfer
saft	stream	tcp	nowait	root	$SERVERDIR/sendfiled
EOD
fi

if [ "`grep check_sendfile /etc/profile`" = "" ]; then
  echo adding check_sendfile to /etc/.profile
  cat <<EOD>>/etc/profile
$BIN/check_sendfile
EOD
fi

echo creating /var/spool/sendfile
mkdir /var/spool 2>/dev/null
mkdir /var/spool/sendfile
chmod 755 /var/spool/sendfile

echo "please restart now your inetd ( or simply reboot :-) )"
