#/bin/bash

# Usage: packageIt.sh --toolpackage=[pimsupport|pimsupportdb|integrityverify]
#

. ${TOP}/bin/get_params.sh

TOOLTOPDIR=$TOP/bin

function usage()
{
    echo ""
    echo "To package a specific tool, such as pimSupportDB, in a portable tar file"
    echo "Usage: packageIt.sh [OPTION]"
    echo "OPTION: --help  To see this usage information"
    echo "        --toolpackage=[pimsupport|pimsupportdb|integritycheck|all]"
    echo ""
}

for _VAR in "$@"; do
    case ${_VAR} in
        --help)
        usage
        exit 0
    esac
done

if [ "X${_CCD_TOOLPACKAGE}" != "X" ]; then
    SAVEDDIR=`pwd`
    DIAGNOSTICDIR=$TOOLTOPDIR/diagnostic
    cd $TOOLTOPDIR

    if [ "$_CCD_TOOLPACKAGE" = "pimsupport" ]; then

        tar -cf pimsupport.tar ./pimSupport.sh ./pimSupport_*.sh ./diagnostic/pim_support ./diagnostic/common ./diagnostic/integrity_check
        mv pimsupport.tar $DIAGNOSTICDIR/pimsupport.tar
        echo "Tool package produced as: $DIAGNOSTICDIR/pimsupport.tar"
        echo "It should be deployed and expanded under $TOP/bin directory in a target environment"
        echo ""

    elif [ "$_CCD_TOOLPACKAGE" = "pimsupportdb" ]; then

        tar -cf pimsupportDB.tar ./get_params.sh ./pimSupportDB*.sh ./diagnostic/pim_support_db ./diagnostic/common
        mv pimsupportDB.tar $DIAGNOSTICDIR/pimsupportDB.tar
        echo "Tool package produced as: $DIAGNOSTICDIR/pimsupportDB.tar"
        echo "It should be deployed to a database server for utilization"
        echo ""

    elif [ "$_CCD_TOOLPACKAGE" = "all" ]; then
        tar -cf all_pimsupport.tar ./pimSupport*.sh ./get_params.sh ./diagnostic
	mv all_pimsupport.tar $DIAGNOSTICDIR/all_pimsupport.tar
        echo "Tool package produced as: $DIAGNOSTICDIR/all_pimsupport.tar"
        echo "It should be deployed and expanded inside '\$TOP/bin' directory in a target environment"
        echo ""

    elif [ "$_CCD_TOOLPACKAGE" = "integritycheck" ]; then
        echo "Not packaged individually. It is included in [pimsupport] or [all]"
        echo ""

    else
        echo "Invalid package name. Please see the Usage:"
        usage
    fi

    cd $SAVEDDIR
    exit 0
fi

usage

