#/bin/posix/sh

#
# check is we got the comand line directory parameter
#
if [ $# -ne 1 ]
then
  echo "usage $0 (dir_with_server_images|server_image)" >&2
  exit 1
fi

#
# check is directory exists
#
if [ ! -d $1 -a ! -f $1 ]
then
  echo "$1 does not exist" >&2
  exit 2
else
  DIR=$1
fi


#
# figure out where what command is
#
WHATS="/usr/bin/what /usr/ucb/what /usr/ccs/bin/what"
for WHAT in $WHATS
do 
  if [ -f $WHAT ]
  then
    break
  fi
done

if [ ! -f $WHAT ]
then
  echo "cannot find what command" >&2
  exit 2
fi


M1=C3230A; M2=C2731A; M3=C2708A; M4=C3231A
MODELS="$DIR/$M1 $DIR/$M2 $DIR/$M3 $DIR/$M4 $DIR"

for MODEL in $MODELS
do
  if [ -f $MODEL ]
  then
    VER=`$WHAT $MODEL | egrep -i 'Server.*Code.*Release' \
	   | sed 's/.* Release //' | awk '{print $1}'`
  fi

  if [ "$VER" != "" ]
  then
    echo $VER
    exit 0
  fi
done

echo "no models: $MODELS" >&2
exit 1
