#!/bin/sh
# Set up or tear down virtual interfaces needed for testing.
# Only "check" can work without superuser privileges.

. CONFIG

# assume that if /sbin/ifconfig doesn't exist, or can't be run, that
# the aliases already exist.
if [ ! -x /sbin/ifconfig ]; then exit 0; fi

for i
do
	case "$i" in
	up)
		/sbin/ifconfig $EASTIF $EASTIP netmask 255.255.255.255
		/sbin/ifconfig $WESTIF $WESTIP netmask 255.255.255.255
		/sbin/ifconfig $NORTHIF $NORTHIP netmask 255.255.255.255
		/sbin/ifconfig $SOUTHIF $SOUTHIP netmask 255.255.255.255
		;;
	down)
		/sbin/ifconfig $EASTIF down
		/sbin/ifconfig $WESTIF down
		/sbin/ifconfig $NORTHIF down
		/sbin/ifconfig $SOUTHIF down
		;;
	check)
		( /sbin/ifconfig $EASTIF | grep 'inet addr' >/dev/null ) &&
		( /sbin/ifconfig $WESTIF | grep 'inet addr' >/dev/null ) &&
		( /sbin/ifconfig $NORTHIF | grep 'inet addr' >/dev/null ) &&
		( /sbin/ifconfig $SOUTHIF | grep 'inet addr' >/dev/null )
		;;
	show)
		/sbin/ifconfig $EASTIF
		/sbin/ifconfig $WESTIF
		/sbin/ifconfig $NORTHIF
		/sbin/ifconfig $SOUTHIF
		;;
	*)
		echo "$0: \"up\", \"down\", \"check\", or \"show\" expected, not \"$i\"" >&2
		exit 1
		;;
	esac
done
