#!/bin/sh
#
# $Id: netswap,v 1.1 1992/02/17 15:36:52 ejb Exp $
# $Source: /home/ejb/scripts/RCS/netswap,v $
# $Author: ejb $
#
#
# This script is used to change a machine from standalone to
# network-dependent or the other way around.  It is not designed
# to be general purpose, but relies on certain aspects of the
# system configuration.
#
# The script can be invoked in one of two ways:
#   netswap off
# to remove the network dependencies or
#   netswap on 
# to restore them.  This script does not make any permenant
# changes to the system.  If the system should reboot, it will
# come back in its default state.
#

PATH=/bin:/usr/bin:/usr/etc; export PATH

usage() {
   echo "Usage: $1 on | off" 1>&2
   exit 1
}

whoami=`basename $0`
cd /

# Usage: Lookup string
# Find a process with string in it and return pid
lookup() {
   ps ax | grep $1 | grep -v grep | awk '{print $1}'
}

# Usage: shutdown pid
# Kill pid and wait for process to exit
shutdown() {
   kill $1
   while [ $? -eq 0 ]; do
      sleep 1; 
      kill -0 $1 > /dev/null 2>&1; 
   done
}
   

neton() {
   ifconfig le0 up
   ypbind
   mount -vat nfs
   automount
}

netoff() {
   pid=`lookup automount`
   shutdown $pid
   umount -t nfs
   pid=`lookup ypbind`
   shutdown $pid
}

if [ $# -ne 1 ]; then
   usage $whoami
fi

if [ "$1" = "on" ]; then
   neton 
elif [ "$1" = "off" ]; then
   netoff
else
   usage $whoami
fi

exit 0
