#!/bin/ksh -p
# $Id: //depot/stable/explorer/tools/u4ft#2 $
#
# Explorer Version:
EXP_VERSION=4.0
#

# Source tools functions
. ${EXP_LIB}/exp_tools

# Run if specified to do so
script=${0##*/}
which_gate_exit $script default all

CMSHOME=/usr/platform/SUNW,Ultra-4FT/SUNWcms
TEXT=`gettext "Not an FT1800 system"`
require "test -d \"${CMSHOME}\"" "${TEXT}"

# collect status-logs. Use cpio to preserve symbolic links
get_dir /var/SUNWlogu u4ft/var_SUNWlogu

# collect COD logs and license if QU2 or above
get_dir /var/SUNWftmu/u4ftcod u4ft/var_SUNWftmu_u4ftcod
get_dir /etc/SUNWftmu/u4ftcod u4ft/etc_SUNWftmu_u4ftcod

# collecting cms config files
get_dir /etc/SUNWcms/.config  u4ft/etc_SUNWcms_.config

# collect split mode files
get_cmd "${CMSHOME}/sbin/splitinfo" u4ft/Splitmode/splitinfo
get_file "/etc/splitd.conf" u4ft/Splitmode
get_file "/etc/config.icn*" u4ft/Splitmode

# collect Firmware upgrade information QU1 and above
if [ -d  /usr/platform/SUNW,Ultra-4FT/SUNWftmu ]; then
   get_cmd "/usr/bin/ls -lR /usr/platform/SUNW,Ultra-4FT/SUNWftmu" u4ft/Firmware/firmware-ls-lR
   get_file "/etc/SUNWftmu/u4ft_compatDB"  u4ft/Firmware
   get_file "/etc/SUNWftmu/u4ft_syspartno" u4ft/Firmware
fi

# collect SEVM setup specific to the ft 1800
get_file "/etc/default/vxassist"      u4ft/ft1800_sevm/etc_default_vxassist
get_file "/etc/vx/sbin/vxaltstale"    u4ft/ft1800_sevm/etc_vx_sbin_vxaltstale
get_file "/etc/rc2.d/S95vxvm-recover" u4ft/ft1800_sevm/etc_rc2.d_vxvm-recover

# collect nvram and debug logs  (still needed for patch C/D machines)
get_cmd "/usr/bin/cat /dev/u4ftlog:nvlog,nodelay" u4ft/Misc/nvlog,nodelay
get_cmd "/usr/bin/cat /dev/u4ftlog:debug,nodelay" u4ft/Misc/debug,nodelay

# copy /etc/release - specific to ft 1800
get_file "/etc/release" u4ft/Misc/etc_release

# grab states of all devices according to FT framework
${CMSHOME}/lib/u4ftctl find / | while read cookie;do
    get_cmd "${CMSHOME}/lib/u4ftctl get_path '$cookie'"     u4ft/Misc/$cookie/get_path
    get_cmd "${CMSHOME}/lib/u4ftctl get_state '$cookie'"    u4ft/Misc/$cookie/get_state
    get_cmd "${CMSHOME}/lib/u4ftctl get_tag '$cookie'"      u4ft/Misc/$cookie/get_tag
    get_cmd "${CMSHOME}/lib/u4ftctl get_driver '$cookie'"   u4ft/Misc/$cookie/get_driver
    get_cmd "${CMSHOME}/lib/u4ftctl get_instance '$cookie'" u4ft/Misc/$cookie/get_instance

    # For compatibility, put all command output in a summary file
    echo_file u4ft/Misc/all-device-states.u4ftctl "$cookie"
    cat ${EXP_TARGET}/u4ft/Misc/$cookie/get_path.out | echo_file u4ft/Misc/all-device-states.u4ftctl
    cat ${EXP_TARGET}/u4ft/Misc/$cookie/get_state.out | echo_file u4ft/Misc/all-device-states.u4ftctl
    cat ${EXP_TARGET}/u4ft/Misc/$cookie/get_tag.out | echo_file u4ft/Misc/all-device-states.u4ftctl
    cat ${EXP_TARGET}/u4ft/Misc/$cookie/get_driver.out | echo_file u4ft/Misc/all-device-states.u4ftctl
    cat ${EXP_TARGET}/u4ft/Misc/$cookie/get_instance.out | echo_file u4ft/Misc/all-device-states.u4ftctl
    echo_file u4ft/Misc/all-device-states.u4ftctl ""
done

# collect eeprom data
for LOCATION in \
A-MBD B-MBD A-CPU B-CPU A-CAF B-CAF \
A-PCI0 A-PCI1 A-PCI2 A-PCI3 A-PCI4 A-PCI5 A-PCI6 A-PCI7 \
B-PCI0 B-PCI1 B-PCI2 B-PCI3 B-PCI4 B-PCI5 B-PCI6 B-PCI7 \
A-RMM B-RMM A-DSK B-DSK \
A-PSU0 A-PSU1 A-PSU2 B-PSU0 B-PSU1 B-PSU2
do
    get_cmd "${CMSHOME}/sbin/cmsfruinfo -i -l $LOCATION EE_EEPROM" u4ft/fru_eeproms/$LOCATION
done
