#!/bin/sh
#
# setup.sh.sample
#
#		How  to use  an external script file  with  parameters
#		given by dip.  The parameters  are given in this order
#		(please refer the man page for details):
#
#		./thisscript UP|DOWN if pro mtu local locip remote
#			     rmtip gw gwip nmsk rt rtip dft tmot
#
#
# Version:	@(#)./samples/setup.sh.sample 1.02	1.July.1995
#
#
# Author:	Joachim Bartz, <injb@sun.rz.tu-clausthal.de>
#
#
#		This program is free software; you can redistribute it
#		and/or  modify it under  the terms of  the GNU General
#		Public  License as  published  by  the  Free  Software
#		Foundation;  either  version 2 of the License, or  (at
#		your option) any later version.
#
#		This program is  distributed in the  hope that it will
#		be useful, but WITHOUT ANY WARRANTY;  without even the
#		implied warranty of MERCHANTABILITY  or  FITNESS FOR A
#		PARTICULAR  PURPOSE.    See  the  GNU  General  Public
#		License for more details.
#
#		You  should have received  a copy  of the  GNU General
#		Public License along with this program;  if not, write
#		to the
#			Free Software Foundation, Inc.
#			675 Mass Ave
#			Cambridge, MA 02139, USA
#

THISSCRIPT=$0

UPDOWN=$1
INTERFACE=$2
PROTOCOL=$3
MTU=$4
LOCALNM=$5
LOCALIP=$6
REMOTENM=$7
REMOTEIP=$8
GWNM=$9

shift 9

GWIP=$1
NETMASK=$2
ROUTENM=$3
ROUTEIP=$4
DEFAULT=$5
TIMEOUT=$6

B_IFCONFIG='/sbin/ifconfig'
B_ROUTE='/sbin/route'

if [ "$UPDOWN" = "UP" ]
then
  #
  # Connection established
  #
  if [ "$PROTOCOL" = "SLIP" ]
  then
    PROTOCOL='-link0 link2'
  else
    PROTOCOL='link0 link2'
  fi
  IFCONFIG $INTERFACE inet $LOCALIP $REMOTEIP netmask $NETMASK $PROTOCOL up

  if [ "$DEFAULT" = "1" ]
    B_ROUTE add default $REMOTEIP
  else
    B_ROUTE add $REMOTEIP $LOCALIP
  fi
else
  if [ "$UPDOWN" = "DOWN" ]
  then
    #
    # Connection down
    #
    B_IFCONFIG $INTERFACE down

    if [ "$DEFAULT" = "1" ]
      B_ROUTE delete default
    else
      B_ROUTE delete $REMOTEIP $LOCALIP
    fi
  fi
fi
exit 0
