####################################################################
# (C) Copyright 2004-2012 Hewlett-Packard Development Company, L.P.
# @(#) Product Name                :  HP Serviceguard
# @(#) Product Version             :  A.12.10.00
# @(#) Patch Name                  :  
####################################################################
# Package control convert script
#
# update_cntl_scripts 10/11/04
#
# This program will convert an existing Serviceguard for
# Linux package control script to work with lvm version 2.
# LVM version 2 ships with the 2.6 kernel. This script
# will work with any distribution that uses lvm2, currently
# that is only SLES9 but RedHat 4 will also.
#
# INPUT PARAMETER:
# $1: The full path name of the package control file.
# $2: The full path name of the updated package control file.
#
###############################################################
PATH=/sbin:/usr/bin:/usr/sbin:/etc:/bin:/opt/hpclx/bin
export PATH

function usage 
{
printf "Usage: $0 [source control script] [target control script]\n"
}

# Need one input file and one output file. Anything else is an error.
if (( $# != 2 )); then
    printf "Error: Illegal number of arguments.\n"
    usage
    exit 1
fi

# Check to see if the input file matches the output file. They
# should not.
if [[ $1 = $2 ]]; then
        printf "Error: Input and output files are the same!\n"
        exit 1
fi


PACKAGE_CNTL_FILE=$1
UPDATED_PACKAGE_CNTL_FILE=$2

if [[ ! -f ${PACKAGE_CNTL_FILE} ]]; then
    printf "Error: File ${PACKAGE_CNTL_FILE} does not exist!\n"
    exit 1;
fi

if [[ -f ${UPDATED_PACKAGE_CNTL_FILE} ]]; then
    printf "Warning: File ${UPDATED_PACKAGE_CNTL_FILE} will be overwritten.\n"
    printf "\tPress any key to continue or <CNTL>-c to abort.\n"
    read
fi

sed -e '/\*successfully\*deactivated\*)/i\
            *0*logical*volume*in*volume*group*now*active*)\
                ;;\
               ' ${PACKAGE_CNTL_FILE} > ${UPDATED_PACKAGE_CNTL_FILE}

exit_val=$?
if (( exit_val > 0 )); then
    printf "ERROR: Could not update file.\n"
    exit ${exit_val}
else
    printf "Package Control file ${PACKAGE_CNTL_FILE} has been\n"
    printf "converted to ${UPDATED_PACKAGE_CNTL_FILE}.\n"
fi

exit 0
