ARCH=$(uname -m)
EXECDIR=$2
_NICFWUPGLOG=/nicfwupg.log
_NICFWBACKUPDIR=/tmp/nicfw_backup
_XMLFILE=""
_PACKARCH="x86"

_XMLFILE=`ls *.xml 2>/dev/null`

if [ -z "$_XMLFILE" ];then
    echo "Component XML file missing"
    exit 1
else
    _DUMMY=`grep operating_system_xlate $_XMLFILE | grep "(x86)"`
    if [ $? -ne 0 ]; then
        _PACKARCH="x86_64"
    fi
fi

if [ "$_PACKARCH" = "x86"  -a  "$ARCH" = "x86_64" ];then
    echo "Component/Platform architecture mismatch"
    echo "Please use the component meant for 64 bit platforms"
    exit 1
fi

if [ "$_PACKARCH" = "x86_64"  -a  "$ARCH" != "x86_64" ];then
    echo "Component/Platform architecture mismatch"
    echo "Please use the component meant for 32 bit platforms"
    exit 1
fi

# if the nicfwupg.log exists in the current directory then copy it over the tmp target
# directory so that the firmware upgrade output gets appended to the file 

if test -f $EXECDIR$_NICFWUPGLOG; then
    cp $EXECDIR$_NICFWUPGLOG $_TARGET_DIR;
fi

export LD_LIBRARY_PATH=$PWD

# .setup specifically preloads "libbmapi_x64.so.6"
# if, and only if, it doesn't exist, create symlink for it
if ! [ -f libbmapi_x64.so.6 -o -f libbmapi.so.6 ]; then
  if [ "$ARCH" != "x86_64" ]; then
      _BMAPI=libbmapi.so.6.*
      _BMAPI_SO=libbmapi.so.6
  else
      _BMAPI=libbmapi_x64.so.6.*
      _BMAPI_SO=libbmapi_x64.so.6
  fi
  ln -sf $_BMAPI $_BMAPI_SO
fi

if test -d $_NICFWBACKUPDIR; then
    :  #do nothing
else
    mkdir $_NICFWBACKUPDIR
fi

