#!/bin/sh
##############################################################################
# $Id: create_defaultrouter,v 1.1 2002/03/21 19:03:23 root Exp $
##############################################################################
# Create /etc/defaultrouter
##############################################################################
# $Log: create_defaultrouter,v $
# Revision 1.1  2002/03/21 19:03:23  root
# Initial revision
#
##############################################################################

echo
echo "Start of $0"
echo '  $Id: create_defaultrouter,v 1.1 2002/03/21 19:03:23 root Exp $'

BASE=/a

if [ -z "$1" ]
then
	echo "  No final octet supplied" >&2
	exit
fi

echo "  Creating /etc/defaultrouter"

# This takes the IP and replaces the last octet with the value supplied
# by the user.  Thus it more or less assumes a /24 subnet mask.

# Grab the IP
ip=`netstat -rn | egrep 'le0|hme0|eri0|ce0' | grep -v '^224' | awk '{print $2}'`

if [ -z "$1" ]
then
	echo "  Failed to find IP address" >&2
	exit
fi

# Replace the last octet with $1
echo $ip | sed 's/[0-9]*$/'$1'/' > $BASE/etc/defaultrouter

chmod 644 $BASE/etc/defaultrouter

echo "End of $0"

