#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/haws/sbin/clhaws_snap.sh 1.8 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2004,2011 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)79	1.8 src/43haes/usr/sbin/cluster/haws/sbin/clhaws_snap.sh, hacmp.assist, 61haes_r714 11/28/11 14:55:25
#
###############################################################################
#
# This script gathers HAWS information for support.
#
#

###############################################################################
#
#
#
# Set the LC_MESSAGES and LC_TIME variables to C.  clsnap only works
# for the C locale.  It's not internationalized.
#
export LANG=C
export LC_MESSAGES=C
export LC_ALL=C
export LC_TIME=C

###############################################################################
#	o usage message

usage()
{
    echo "Usage: clhaws_snap [-d destinationdir]\n"
    echo "-d  Destination directory to put the data"
    echo 
    echo 
}

###############################################################################
#	o Function build_log_files_list 

build_files_list () {
    FN=$1
    for CPF in `ls -1 $FN*`
      do
      LOG[$numlogs]=`basename $CPF`
      LOG_PATH[$numlogs]=$CPF
      LOG_DIR[$numlogs]=$2
      LOG_PATH_LIST="$LOG_PATH_LIST $numlogs"
      ((numlogs=$numlogs + 1))
    done
}

###############################################################################
#	o Function build_log_files_list 

copy_files_from_list () {
    for F in $LOG_PATH_LIST
    do
	cp -pf ${LOG_PATH[$F]} $tmp_path/${LOG_DIR[$F]}/${LOG[$F]}
    done
}


###############################################################################
#       M A I N  MAIN   main
###############################################################################

PATH=$PATH:/usr/bin:/usr/es/sbin/cluster:/usr/es/sbin/cluster/utilities:/etc:.:
export PATH

# Initialize variables
destdir=

# get the command line parameters.

set -f

set -- `getopt d: $*`
if [ "$?" != 0 ]
then
        usage
        exit 1
fi

while [ "$1" != -- ]
do
        case $1 in
                -d)     destdir=$2      # Directory to put information
                        shift;shift;;
		 *)     usage; exit 3

        esac
done

set +f

if [ -z "$destdir" ]
then
	tmp_path=/tmp/haws.snap
else
	tmp_path=$destdir
fi

HAWS_HOME=/usr/es/sbin/cluster/haws
CURR_DATE=`date +%m%d`
CURR_HOUR=`date +%H`
CURR_MINUTE=`date +%M`
filename=haws.$CURR_DATE$CURR_HOUR$CURR_MINUTE.tar

if [[ ! -d $HAWS_HOME ]] ; then
    echo "PowerHA SystemMirror Smart Assist for WebSphere installation directory does not exist.\n"
    exit 0
fi

mkdir -p $tmp_path/config
mkdir -p $tmp_path/logs
mkdir -p $tmp_path/scripts

LOG_PATH_LIST=""
numlogs=0

build_files_list $HAWS_HOME/config/ config
build_files_list $HAWS_HOME/logs/ logs
build_files_list $HAWS_HOME/scripts/ scripts

copy_files_from_list

tar -cf $tmp_path/$filename $tmp_path/config $tmp_path/logs $tmp_path/scripts

rm -rf $tmp_path/config
rm -rf $tmp_path/logs
rm -rf $tmp_path/scripts

exit 0