#!/bin/ksh
if    [[ -z $1  ]]
then  echo 'You need to specify a machine I.P. name (not the I.P. address)'
      exit 123
fi 

ip_addr="$(host $1)" || exit $?
# Response could be simple (e.g. "nemesis.almaden.ibm.com is 129.33.40.14")
# or complex (e.g. "nameserver2.almaden.ibm.com is 129.33.10.4, \
#                   Aliases: nameserver2.almaden.ibm.com")
# either way, all we want is the dotted decimal portion.
ip_addr=${ip_addr##* is }   # Strip off "such.and.such.a.name is " leader
ip_addr=${ip_addr%%,*}      # Strip off everything past the first comma (if any)

# Parse ip_addr to get subnet and use that to get default route
subnet="${ip_addr%.*}"      # Strip off last .xx
subnet="${subnet##*.}"      # Strip off leading xxx.xxx.

case "$subnet" in
10|12|13|14|15|22|32|40) type_parm="cable_type1=dix" ;;   # Ethernet - Old network
24|25|26|27|28|29|30|31) type_parm="cable_type1=dix"      # Ethernet - New network
                         subnet=24 ;;
60|62|63|64|65|68|82|160) type_parm="ring_speed1=16" ;;   # Token Ring - Old network
72|73|74|75|76|77|78|79) type_parm="ring_speed1=16"       # Token Ring - New network
                         subnet=72 ;;
*) echo "Unknown subnet ($subnet).  Please contact the AIX Help Desk at 7-2525 Option 1 to fix the Do-net script on nemesis."
   exit 234  ;;
esac

lsnim -t standalone $1 1>/dev/null 2>&1 || nim -o define -t standalone -a platform=rs6k -a if1="subnet$subnet $1.almaden.ibm.com 0" -a $type_parm $1
nim -o allocate -a lpp_source=lpp-414 -a script=Do-net -a script=Do-afs -a spot=spot1 $1
nim -o bos_inst -a source=spot -a no_client_boot=yes $1
