#!/bin/sh


ipaddr=""
true=1
FALSE=0
CONFLAG=0

cleanup() {
 /usr/bin/rm -rf .tmp.01 2>&1 >/dev/null
 if [ $CONFLAG -eq 1 ]; then
	./bitops
    if [ $? -ne 0 ]; then
	    echo 'Failed to update firmware file corrupted copy patch again and retry'
	    error
    fi
 fi
}

error() {
  cleanup
  echo "Exiting Program $0"
  exit 1
}

trap "error" 1 2 3

Patchpro_contract=$FALSE
if [ "$#" -eq 1 ]; then
  if [ "$#"="ppro" ]; then
    Patchpro_contract=$true
  fi
fi

echo  'Please Enter Hostname or IP Address Of 3xxx platform for upgrade: \c'
read ipaddr    
ping $ipaddr
ERRCODE=$?      
if [ $ERRCODE -ne $FALSE ]; then
  echo 'Target unreachable.'
  error
fi

if [ 1 ]; then
   CONFLAG=1
   ./bitops
   if [ $? -ne 0 ]; then
	   echo 'Failed to update firmware file'
	   error
   fi
fi

./MLOAD $ipaddr

cleanup				# Remove temp directories

exit 0

