#!/bin/bash
# -----------------------------------------------------------------------------
# show_tech_pd                     
#                                      
# Copyright (c) 2015, 2020-2021 by cisco Systems, Inc.
# All rights reserved.
#------------------------------------------------------------------------------

#
# Load the script provided by show-tech infra, which provides worker functions
#
source /opt/cisco/calvados/script/show_tech_main_fragment
#
# Parse the arguments to the script - card type and interface filter are the 
# only support options currently.  No need to use the default parser function,
# as this has been done by caller.
#
__cardtype="unspecified"
trace_only="0"
show_only="0"
not_sim="0"

while [ "$#" -gt "0" ]; do
    case "$1" in
        -T) trace_only="1"; shift 1;;
        -S) show_only="1"; shift 1;;
        -t) __cardtype="$2"; shift 2;;
        *) shift;;
    esac
done

if [ "$__cardtype" == "unspecified" ]; then
    __cardtype=`/opt/cisco/calvados/script/node_type`
fi

not_sim=`lspci | grep "Ethernet controller: Intel" | wc -l`

#sys_hw_show_exec[1]='PEM driver show_power'
#sys_hw_show__ksh[1]='/opt/cisco/calvados/sbin/show_power -t'

rplc_show_exec[1]='dump envmon data structures'

if [[ -f "/opt/cisco/calvados/bin/envmon_test_fretta" ]]; then
    rplc_show__ksh[1]='/opt/cisco/calvados/bin/envmon_test_fretta -d'
else
    rplc_show__ksh[1]='/opt/cisco/calvados/bin/envmon_test_eyrie -d'
fi

# XC show
xc_show_exec[1]='dump envmon data structures'
xc_show__ksh[1]='/opt/cisco/calvados/bin/envmon_test_fretta -d'
xc_show_exec[2]='show fan tray dump'
xc_show__ksh[2]='cat /tmp/fan_dump'
xc_show_exec[3]='show pem dump'
xc_show__ksh[3]='cat /tmp/pem_dump'


#
# The display() function is the one that does all the work - called by us as 
# this is a worker script.
#
display() {
    print_main_heading "Platform Dependent envmon tech-support info"
        
    if [ "$__cardtype" = "SYS" ]; then
        if [ "$trace_only" = "0" ]; then
                if [ "$not_sim" != "0" ]; then
                     exec_commands sys_hw_show
                fi
        fi
    else
        case "$__cardtype" in
        "RP")
            exec_commands rplc_show
            ;;

        "LC")
            exec_commands rplc_show
            ;;

        "FC")
            exec_commands rplc_show
            ;;

        "XC")
            exec_commands xc_show
            ;;

        esac

   fi 
}

display
