#!/bin/csh -f
# 16.4.1997 J.E. Klasek jk@auto.tuwien.ac.at
#
# bin archive install program
#

# setting up inetd.conf

echo "Setting up qpopper ..."
set cf=/sys/node_data/etc/inetd.conf


set tmpcf=/tmp/INSTALL.$$

/bin/rm -f $tmpcf
if (-e $tmpcf) then
	echo "can't remove temporary file ($tmpcf)."
	goto leave
endif

if (! -e $cf) then
	echo "$cf does not exist."
	goto leave
endif


# search for tcp_wrapper
foreach e (`which frontd` /usr/local/bin/{frontd,tcpd} /etc/frontd /usr/local/etc/bin/{frontd,tcpd} /usr/sbin/{tcpd,frontd})
  if (! -x $e) continue
  set tcpwrapper=$e
end

grep -v -e '^pop[23].*/usr/local/etc/bin/popper' $cf | sed -e 's/^\(pop[23].*$\)/#\1/' $cf >$tmpcf

if ($?tcpwrapper) then

echo "Adding tcp_wrapper styled inetd.conf entries ..."
cat <<EOF >>$tmpcf
pop3		stream	tcp	nowait	root	$tcpwrapper /usr/local/etc/bin/popper -s
pop2		stream	tcp	nowait	root	$tcpwrapper /usr/local/etc/bin/popper -s
EOF

else

echo "Adding normal styled inetd.conf entries ..."
cat <<EOF >>$tmpcf
pop3		stream	tcp	nowait	root	/usr/local/etc/bin/popper popper -s
pop2		stream	tcp	nowait	root	/usr/local/etc/bin/popper popper -s
EOF

endif

# commit change 
echo "Changes in ${cf}:"
diff $cf $tmpcf|sed -e 's/^/    /'
echo ""
echo -n "ok? "
set a=$<
if ("$a" != "y" && "$a" != "Y") then
	echo "No changes."
	goto leave
endif

# replace file
if (-e $tmpcf) then
	mv $tmpcf $cf
endif

set pid=`ps axuwww | grep -e '^root.*inetd'|grep -v grep|awk '{print $2;exit}'`
echo Restarting inetd ...
kill -1 $pid


leave:
/bin/rm -f $tmpcf
