#!/bin/bash
# -----------------------------------------------------------------------------
# tech_shelf_mgr                     
#                                      
# Copyright (c) 2012-2015, 2017 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"
show_only="0"

while [ "$#" -gt "0" ]; do
    case "$1" in
        -S) show_only="1"; shift 1;;
        -t) __cardtype="$2"; shift 2;;
        *) shift;;
    esac
done
if [ "$__cardtype" != "SYS" ]; then
    __cardtype=$__node_type
fi

#
# List of commands to be run.  Each set must finish with a pair of empty 
# strings.  Note that it is important to use single quotes rather than double 
# quotes for the strings containing your commands.
#
# For all of these the __ksh variable is the process that will actually be 
# spawned, the _exec variable is just a string that is printed in the output to
# describe it. 
#

###############################################################################
# Show commands that run on all RP or LC                                      #
###############################################################################

#
# Show Commands
#
sys_show_exec[1]='show platform'
sys_show__ksh[1]='/opt/cisco/calvados/bin/show_cmd "terminal length 0; show platform"'

sys_show_exec[2]='show platform detail'
sys_show__ksh[2]='/opt/cisco/calvados/bin/show_cmd "terminal length 0; show platform detail"'

sys_show_exec[3]='show inventory all'
sys_show__ksh[3]='/opt/cisco/calvados/bin/show_cmd "terminal length 0; show inventory all"'

sys_show_exec[4]='show processes shelf_mgr location all'
sys_show__ksh[4]='/opt/cisco/calvados/bin/show_cmd "terminal length 0; show processes shelf_mgr location all"'

sys_show_exec[5]='show processes services all location all'
sys_show__ksh[5]='/opt/cisco/calvados/bin/show_cmd "terminal length 0; show processes services all location all"'

sys_show_exec[6]='show reboot-history card'
sys_show__ksh[6]='/opt/cisco/calvados/bin/show_cmd "terminal length 0; show reboot-history card"'

sys_show_exec[7]='show reboot-history admin-vm'
sys_show__ksh[7]='/opt/cisco/calvados/bin/show_cmd "terminal length 0; show reboot-history admin-vm"'

#
# misc show RP
#
rp_show_exec[1]='show version'
rp_show__ksh[1]='cat /etc/show_version.txt'

rp_show_exec[2]='Dump logic slot info'
rp_show__ksh[2]='/opt/cisco/calvados/bin/test_cpmi_data_client 2 8 1'

rp_show_exec[3]='Dump OIR Log'
rp_show__ksh[3]='cat /var/log/inv_debug_shelf.log'

rp_show_exec[4]='Dump DB'
rp_show__ksh[4]='/opt/cisco/calvados/bin/inv_dump_tool rack -file show_tech_rack.inv'

rp_show_exec[5]='Display DB'
rp_show__ksh[5]='cat /var/log/show_tech_rack.inv'

rp_show_exec[6]='Delete DB file'
rp_show__ksh[6]='rm /var/log/show_tech_rack.inv'

rp_show_exec[7]='Display all hdl info'
rp_show__ksh[7]='/opt/cisco/calvados/bin/test_inv_svc_client 2 20 1'

#
# misc show LC
#
lc_show_exec[1]='show version'
lc_show__ksh[1]='cat /etc/show_version.txt'

lc_show_exec[2]='Dump logic slot info'
lc_show__ksh[2]='/opt/cisco/calvados/bin/test_cpmi_data_client 1 8 1'

lc_show_exec[3]='Dump OIR Log'
lc_show__ksh[3]='cat /var/log/inv_debug_shelf.log'

lc_show_exec[4]='Dump DB'
lc_show__ksh[4]='/opt/cisco/calvados/bin/inv_dump_tool node -file show_tech_node.inv'

lc_show_exec[5]='Display DB'
lc_show__ksh[5]='cat /var/log/show_tech_node.inv'

lc_show_exec[6]='Delete DB file'
lc_show__ksh[6]='rm /var/log/show_tech_node.inv'

#
# The display() function is the one that does all the work - called by us as 
# this is a worker script.
#
display() {
    print_main_heading "General shelf_mgr tech-support info"
        
    if [ "$__cardtype" = "SYS" ]; then
            exec_commands sys_show
    else
        case "$__cardtype" in
        "RP"|"CC")
            exec_commands rp_show
            ;;
        "SC")
            exec_commands rp_show
            ;;
        "LC")
            exec_commands lc_show
            ;;
        "FC")
            exec_commands lc_show
            ;;
        "XC")
            exec_commands lc_show
            ;;
        esac
    fi
    
    print_main_heading "General shelf_mgr tech-support info complete"
}

display
