#!/bin/sh

# IP Filter (http://coombs.anu.edu.au/~avalon/)
#
I=/afs/sipb.mit.edu/service/ipf/src
mkdir -p /usr/local/etc/opt/ipf
mkdir -p /usr/local/opt/ipf
ln -s /usr/local/etc/opt/ipf /etc/opt/ipf
ln -s /usr/local/opt/ipf /opt/ipf
#
pkgadd -d $I/pfil.pkg
#
(cd $I/ip_fil4.1.3/SunOS5/sparc-5.9; pkgadd -d ipf.pkg ipfx; pkgadd -d ipf.pkg ipf)
#
if [ ! -d /usr/local/share ]; then
  mkdir /usr/local/share
fi
attach gnu
THE_INTERFACE=lo0
/sbin/ifconfig -a | /mit/gnu/bin/ggrep --quiet le0:
if [ $? -eq 0 ]; then
  THE_INTERFACE=le0
fi
/sbin/ifconfig -a | /mit/gnu/bin/ggrep --quiet hme0:
if [ $? -eq 0 ]; then
  THE_INTERFACE=hme0
fi
/sbin/ifconfig -a | /mit/gnu/bin/ggrep --quiet eri0;
if [ $? -eq 0 ]; then
  THE_INTERFACE=eri0
fi
THE_IPADDR=`/sbin/ifconfig -a | grep 'inet 18' | awk '{print $2}'`
sed -n -e "s/_THE_INTERFACE_/$THE_INTERFACE/g" -e p < $I/usr/local/share/ipf.in > /usr/local/share/ipf.in.t
sed -n -e "s/_THE_IPADDR_/$THE_IPADDR/g" -e p < /usr/local/share/ipf.in.t > /usr/local/share/ipf.in
rm /usr/local/share/ipf.in.t
# script only handles le0, hme0, eri0
if [ "$THE_INTERFACE" = "lo0" ]; then
   cp /dev/null /usr/local/share/ipf.in
fi
rm /etc/rc2.d/S65ipfboot
cp $I/etc/init.d/ipfboot /etc/init.d/ipfboot
chmod 744 /etc/init.d/ipfboot
chown root:root /etc/init.d/ipfboot
ln -s ../init.d/ipfboot /etc/rc2.d/S65ipfboot

