#!/bin/bash -p
######################################################################################
#                                                                                    #
#  Ericsson AB 2001-2024    - All Rights Reserved                                   #
#                                                                                    #
# The copyright to the computer program(s) herein is the property   of Ericsson AB,  #
# Sweden. The programs may be used and/or copied only with the written permission    #
# from Ericsson AB or in accordance with the terms and  conditions stipulated in the #
# agreement/contract under which the program(s) have been supplied.                  #
#                                                                                    #
######################################################################################
#To decode the output of rdsfp -d <port>  or sfp -d <port>  or DU/XMU/RU/RRU
#Based on SFF-8472 : Specification for Diagnostic Monitoring Interface for Optical Transceivers

moshelldir=`dirname "$0"`
if [[ $moshelldir != /* ]] ; then moshelldir=`pwd`/$moshelldir ; fi
vobsinstallation=0
unamea=$(uname -a)
gawkext=""
gawklib=""
if [[ $unamea = [Ll][iI][nN][uU][xX]*x86_64* ]] ; then gawklib="lin64"   ; if [[ $vobsinstallation = 1 ]] ; then gawkext=".lin64" ; fi
elif [[ $unamea = [Ll][iI][nN][uU][xX]* ]]      ; then gawklib="linux"   ; if [[ $vobsinstallation = 1 ]] ; then gawkext=".linux" ; fi
elif [[ $unamea = SunOS*sparc* ]]               ; then gawklib="solaris" ; if [[ $vobsinstallation = 1 ]] ; then gawkext=".solaris" ; fi
elif [[ $unamea = SunOS* ]]                     ; then gawklib="sol86"   ; if [[ $vobsinstallation = 1 ]] ; then gawkext=".sol86" ; fi
elif [[ $unamea = Darwin* ]]                    ; then gawklib="app"     ; if [[ $vobsinstallation = 1 ]] ; then gawkext=".app"   ; fi
else gawklib="cygwin" ; gawkext=".exe"
fi
gawkprog="gawk${gawkext}" 
gawk="$moshelldir/$gawkprog"

#special case where moshell has been installed on a linux 32 bit machine but should be run on linux 64 sharing the same file system
if [[ $unamea = [Ll][iI][nN][uU][xX]*x86_64* && $vobsinstallation != 1 && `file "$moshelldir/gawk"` = *32-bit* ]] ; then gawklib="linux" ; fi

filefunc="$moshelldir/commonjars/lib/${gawklib}/filefuncs"
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}$moshelldir/commonjars/lib/${gawklib}
export LANG=C
export LC_ALL=C

globmoshellrc=$moshelldir/jarxml/moshellrc
commonjardir=$moshelldir/commonjars
jarxmldir=$moshelldir/jarxml
defLogDir=$commonjardir/defLogDir.sh
moshellrc=$($defLogDir)


$gawk -f $moshelldir/funcs.awk -v moshelldir="$moshelldir" -v vobsinstallation="$vobsinstallation" -v globmoshellrc="$globmoshellrc" -v moshellrc="$moshellrc" -l "$filefunc" -f $moshelldir/commonjars/sfpdecoder.awk
