####################################################################
# (C) Copyright 2005-2005 Hewlett-Packard Development Company, L.P.
# @(#) Serviceguard configuration callout master script
# @(#) Product Version           :  A.12.10.00
# @(#) Patch Name                :  
####################################################################    

# Do not modify or delete.
# This is Serviceguard product script used for notifying cluster 
# configuration change.

CALLOUT_PATH="/etc/cmcluster_callout/config"

#Lets create a environment for the callout scripts.
PATH="/usr/bin:/bin:/sbin:/usr/sbin"
export PATH

#For HP-UX set timezone too. 
ostype=$(uname)
if [ "$ostype" = "HP-UX" ]; then
    [ -f /etc/TIMEZONE ] && . /etc/TIMEZONE
fi

host=$(hostname)

#Make sure that directory exists.
if [ ! -d $CALLOUT_PATH ]; then
    exit 0
fi

#Make sure that directory has appropiate permission.
dir_list=$(ls -odL $CALLOUT_PATH |  awk '/^d[-|r][-|w]x[-|r]-[-|x][-|r]-/ {if ($3 == "root"){print $8 }}')
if [ "$dir_list" != "$CALLOUT_PATH" ]; then
    echo "Wrong permission on directory $CALLOUT_PATH on node $host."
    echo "Expected to be owned and modifiable by root only."
    echo "Not deliverling any config change callout on node $host."
    exit 1
fi

#Create a list of executable files who are owned and modifiable by root.
scripts=$(ls -oL $CALLOUT_PATH |  awk '/^-[-|r][-|w]x[-|r]-[-|x][-|r]-/ {if ($3 == "root"){print $8 }}')

#issue callbacks to all the scripts in background.
for script in $scripts
    do 
        nohup $CALLOUT_PATH/$script > /dev/null 2>&1 &
        echo "Invoked callout script $CALLOUT_PATH/$script on node $host" 
    done 
exit 0
