#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# show_tech_grid - GRID show tech command
#
# October 2019, Nirmith V
#
# Copyright (c) 2019-2021 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------

. /pkg/bin/show_tech_main_fragment
. /pkg/bin/show_tech_grid_util

__cardtype="unspecified"

# Parse the arguments to the script.
while [ "$#" -gt "0" ]; do
    case "$1" in
        -t) __cardtype="$2"; shift 2;;
        *)  default_parser_function "$@"; shift $#;;
    esac
done

if [ "$__filename" = "unspecified" ]; then
    echo "show_tech_grid: output file not specified"
    exit
fi

if [ "$__cardtype" == "unspecified" ]; then
    __cardtype=`node_type`
fi



# ***********************************************************
#  Show commands to be run by the show tech-support commands
# ***********************************************************

#############################################################

# Commands that run on once per system
cmd_index=1
sys_exec[$cmd_index]='show platform'
sys__ksh[$cmd_index]='show_platform_sysdb'

((cmd_index++))
sys_exec[$cmd_index]="show redundancy"
sys__ksh[$cmd_index]='show_rmf_sysdb'

((cmd_index++))
sys_exec[$cmd_index]="show install active"
sys__ksh[$cmd_index]='sdr_instcmd show install active'

((cmd_index++))
sys_exec[$cmd_index]="show version"
sys__ksh[$cmd_index]='ng_show_version'

((cmd_index++))
sys_exec[$cmd_index]="show running-config"
sys__ksh[$cmd_index]='nvgen -c -l 1 -t 1 -i1 -o 1'

((cmd_index++))
sys_exec[$cmd_index]='show config commit list'
sys__ksh[$cmd_index]='config_history -r -b -n 0xffffffff'

if [ "$platform" != "enxr" ]; then
    cp /etc/build-info.txt $__tar_file_directory_on_node 2>/dev/null
    cp /etc/show_version.txt $__tar_file_directory_on_node 2>/dev/null
fi

#############################################################

# Commands that run on once per system
cmd_index=1
grid_rp_exec[$cmd_index]='show grid trace all location $location'
grid_rp__ksh[$cmd_index]='rid_show_ltrace -EVR'

((cmd_index++))
grid_rp_exec[$cmd_index]='show grid info-all location $location'
grid_rp__ksh[$cmd_index]='grid_show -I'

#############################################################
# Script

display() {
    print_main_heading "show tech-support grid"
        
    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys
    else
        case "$__cardtype" in
        "RP")
            exec_commands grid_rp 
            ;;
        "LC")
            display_grid_lc
            ;;
        esac
    fi
    print_main_heading "show tech-support grid complete"
}

. /pkg/bin/show_tech_file_fragment
