#!/pkg/bin/ksh
#----------------------------------------------------------------------------
# show commands for show tech-support
#
# July 2016, Neil McGill
#
# Copyright (c) 2016-2017, 2019-2021 by cisco Systems, Inc.
# All rights reserved.
#----------------------------------------------------------------------------

. /pkg/bin/show_tech_main_fragment

__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 "$0: output file not specified"
    exit
fi

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

#----------------------------------------------------------------------------
# Commands that run once per system
#

idx=1

sys_gen_exec[idx]="show version details"
sys_gen__ksh[idx]='ng_show_version'
((idx++))

sys_gen_exec[idx]="show running-config"
sys_gen__ksh[idx]='nvgen -c -l 1 -t 1 -i1 -o 1'
((idx++))

sys_gen_exec[idx]="show install active"
sys_gen__ksh[idx]='sdr_instcmd show install active'
((idx++))

sys_gen_exec[idx]="show redundancy"
sys_gen__ksh[idx]='show_rmf_sysdb'
((idx++))

sys_gen_exec[idx]="show logging"
sys_gen__ksh[idx]='show_logging'
((idx++))

sys_gen_exec[idx]="show cli history detail"
sys_gen__ksh[idx]='show_parser_history -h 0x2'
((idx++))

sys_gen_exec[idx]="show configuration commit list detail"
sys_gen__ksh[idx]='config_history -r -d -n 0xffffffff'
((idx++))

if [ -f /opt/cisco/thinxr/am_i_thinxr ]; then
    sys_gen_exec[idx]='show reboot history detail'
    sys_gen__ksh[idx]='show_platform_sysdb "-r" "-d"'
    ((idx++))
else
    sys_gen_exec[idx]='show reboot history location $location'
    sys_gen__ksh[idx]='show_reboot_ng -h -n $fq_nodeid'
    ((idx++))
fi

# ZTP oper data
idx=1

sys_oper_exec[idx]="show ztp information"
sys_oper__ksh[idx]='ztp_cli show-info --detail'
((idx++))

sys_oper_exec[idx]="show ztp status"
sys_oper__ksh[idx]='ztp_cli show-status'
((idx++))

#----------------------------------------------------------------------------
# Commands that run once per node
#

idx=1

rp_logs_exec[idx]="show all ztp logs"
rp_logs__ksh[idx]='ztp_cli show-tech'
((idx++))


#----------------------------------------------------------------------------
# Collect show tech files
#

display() {
    print_main_heading "show tech-support ztp"

    if [ "$__cardtype" == "SYS" ]; then
        exec_commands sys_gen
        exec_commands sys_oper
    elif [ "$__cardtype" == "RP" ]; then
        exec_commands rp_logs
    fi

    print_main_heading "show tech-support ztp complete"
}

# Run the appropriate function depending on the node specified and if a
# file is specified write the output to that file. We need to redirect
# stderr to stdout when writing to a file because some of the show
# commands output to stderr instead of stdout
. /pkg/bin/show_tech_file_fragment
