#!/usr/bin/sh

if [ "`whoami`" != "root" ] ; then
	echo "Must be root to run this patch script."
	exit 1
fi

Source=ftpd.OSIS50-patched
Target=/usr/local/etc/ftpd
if [ ! -f $Source ] ; then
   echo "Can't find $Source"
   exit 1
fi

if [ ! -f /usr/.smdb./IAFWFTP500.lk ] ; then
   echo "This patch can only be applied to Open Source Internet Solutions V5.0"
   echo "Washington University FTP server subset (IAFW500) which does not appear"
   echo "to be installed." 
   exit 1
fi

if [ -f $Target ]; then
   if [ "`cksum $Target | cut -f-2 -d\ `" = "`cksum $Source | cut -f-2 -d\ `" ]; then
      echo "This patch has already been applied."
      exit 1
   fi
fi

echo "Applying Open Source Internet Solutions V5.0 Anonymous FTP patch"

[ -e $Target ] && mv $Target $Target.OSIS50-orig
mv $Source $Target
chmod 755 $Target
grep -q "$Target ftpd$" /etc/inetd.conf
if [ $? -eq 0 ]; then
  ed -s /etc/inetd.conf <<endofinput >/dev/null 2>&1
g,$Target ftpd$,s,$, -a,
w
q
endofinput
  . /usr/internet/cluster/cluster_support
  reload_inetd
fi

echo "Open Source Internet Solutions V5.0 Anonymous FTP patch applied successfully"
