#!/pkg/bin/ksh
# -----------------------------------------------------------------------------
# show_tech_fast_admin_bundles - Admin mode show tech-support fast script for 
#                                bundles
#
# March 2010, Anthony Toole
#
# Copyright (c) 2010-2012 by cisco Systems, Inc.
# All rights reserved.
#------------------------------------------------------------------------------

#
# OVERVIEW OF BUNDLE SHOW TECH FAST
#
# See 'show_tech_fast_bundles' for an explanation of when and how this script 
# will be called.  The admin-mode command is much simpler, as there is no 
# interaction with Ethernet/POS/Chdlc provided scripts.
#

#
# Load the script provided by show-tech infra, which provides worker functions
#
. /pkg/bin/show_tech_main_fragment

#
# Parse the arguments to the script - in particular, to work out what node type
# we are running on and any interface filter.
#
# The args passed to this script seem to get easily mixed in with the show tech
# arguments, so make no assumption about ordering of arguments here - and pass
# anything unhandled over to showtech infra.
#
__cardtype="unspecified"
showtech_argv=""
showtech_argc="0"

while [ "$#" -gt "0" ]; do
    case "$1" in
        -t) __cardtype="$2"; shift 2;;
        *) showtech_argv="$showtech_argv $1"; (( showtech_argc+=1 )); shift 1;;
    esac
done

#
# Call the showtech infra default parser - using set to recreate the $#, $@, 
# etc. - "--" is necessary so set doesn't try to interpret any of the 
# arguments we are passing through!
#
if [[ $showtech_argc -ne 0 ]]; then
    set -- $showtech_argv
    default_parser_function $@
fi

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

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

arg_string="$arg_string -t $__cardtype"

#
# The display() function is the one called by the show-tech infra to actually
# do the work of running the commands (it is run by show_tech_file_fragment, 
# called below).
#
# NOTE: our "sys" commands ideally want to be run once per LR.  But seems there
# is currently no way to detect this, so for now we duplicate the SYS handling
# on all RP cards - this means for each RP type node in an LR we'll duplicate 
# the information (not ideal, but better than losing data).
#
display() {
    print_main_heading "admin show tech-support bundles"
        
    run_module show_tech_admin_ema_common "$arg_string"
    
    print_main_heading "admin show tech-support bundles complete"
}

#
# This function calls the display() function and sends the output to file if
# the file option has been set. 
#
. /pkg/bin/show_tech_file_fragment
