#!/bin/sh

#ident "$script: load-sddlmadrv Build 5.81.0.7 06/09/10 17:00:00 $"

#----------------------------------------------------------------------------#
# PRODUCT :  HDLM Driver 0501                                                #
#----------------------------------------------------------------------------#
# NAME :     load-sddlmadrv                                                  #
# FUNCTION : load alert driver during bootup                                 #
# INSTANCE :                                                                 #
# MEMO :                                                                     #
# DATE :     2003/06/07                                                      #
# AUTHOR :   Bharvi Oak                                          	     #
# HISTORY :                                                                  #
#                                                                            #
#@ All Rights Reserved, Copyright (C) 2003,2006 Hitachi, Ltd.	             #
#----------------------------------------------------------------------------#

# REVAMP ACTIVITY PERFORMED. SO ALL PREVIOUS FDOCS & COMMENTS ARE REMOVED. PLEASE LOOKUP 
# PREVIOUS VERSIONS CODES FOR REFERENCE.

if [ -f /etc/redhat-release ]; then
    if [ -f /etc/sysconfig/hdlm-scripts/common-defines ]; then
	    . /etc/sysconfig/hdlm-scripts/common-defines
    else
	    failure $"Attempting to source /etc/sysconfig/hdlm-scripts/common-defines: "
	    return
    fi
elif [ -f /etc/SuSE-release ]; then
    . /etc/rc.status
    rc_reset
    if [ -f /etc/sysconfig/hdlm-scripts/common-defines ]; then
	    . /etc/sysconfig/hdlm-scripts/common-defines
    else
            /bin/logger -t load-sddlmadrv "Attempting to source /etc/sysconfig/hdlm-scripts/common-defines:  failed"
	    rc_failed
	    rc_status 
	    return
        fi
fi

#############################
# Kernel and HDLM version check start
#############################
if [ "$HDLM_COMMON_RESULT" != "SUPPORT" ]; then
	if [ "$HDLM_COMMON_RESULT" == "NOT_SUPPORT" ]; then
	    DisplayMessage "KAPL06100-E The version of the kernel supported by the installed HDLM does not match the currently booting kernel version."
	else
		DisplayMessage "KAPL06101-E The HDLM file is invalid. File name = $HDLM_COMMON_KNL_VER_FILE"
	fi
	if [ -f /etc/SuSE-release ]; then
		rc_exit
	else
		return
	fi
fi
#############################
# Kernel and HDLM version check end
#############################

#  START BFS : Check if alert driver is already inserted
$CMD_LSMOD | $CMD_GREP sddlmadrv > /dev/null 2>&1
if [ $? -eq 0 ] 
then
    return
fi
# END BFS : Check if alert driver is already inserted

# This script is called from /etc/rc.d/rc.sysinit.
# This script will not run individually from command line
# because it requires a prior sourcing of /etc/rc.d/init.d/functions in the same shell.
if [ -f /etc/redhat-release ]; then
  
    # SDDLMADRV module insert steps start here for RedHat releases
    $CMD_RM -rf $DLMCTRLDIR/sddlmadrv0 #Removing Alert driver control file in case of abnormal shutdown
    $CMD_RM -rf $DLManagerEtcDir/dlmcfgmgr*.log #Removing temporary log files
    if [ -d $DLMCTRLDIR ] || $CMD_LS /dev | $CMD_GREP -q $DLMBLKDEV || $CMD_LS /dev | $CMD_GREP -q $DLMCHRDEV ; then 
	    export CFGMGR_FROM_SYSINIT=1
	    $CMD_ECHO -n $"Removing HDLM devices: "
	    $DLMCfgMgr -d -s  > /dev/null 2>&1 && \
	    success $"Removing HDLM devices: " || failure $"Removing HDLM devices: "
	    $CMD_ECHO
	    unset CFGMGR_FROM_SYSINIT
    fi
    $CMD_ECHO -n $"Loading HDLM Alert driver: "
    # Use of Wrapper script for insmod and rmmod MOD Start
    if [ "TRUE" = "$USE_INS_RM_MOD_SCRIPT" ]; then
	    $DLM_INSMOD_Alert > /dev/null 2>&1 && \
	    success $"Loading HDLM Alert driver: " || failure $"Loading HDLM Alert driver: "
	    $CMD_ECHO
	    if [ ! -x $DLM_INSMOD_Alert ]; then
		    $CMD_ECHO "Script execution failed, scriptname=$DLM_INSMOD_Alert"
	    fi
    else
	    $CMD_INSMOD $ALERTDRV > /dev/null 2>&1 && \
	    success $"Loading HDLM Alert driver: " || failure $"Loading HDLM Alert driver: "
	    $CMD_ECHO
    fi
    # Use of Wrapper script for insmod and rmmod MOD Ends
    # SDDLMADRV module insert steps end here for RedHat releases
else
    if [ -f /etc/SuSE-release ]; then
        # SDDLMADRV module insert steps start here for SuSE releases
        rc_reset
        $CMD_RM -rf $DLMCTRLDIR/sddlmadrv0 #Removing Alert driver control file in case of abnormal shutdown
        $CMD_RM -rf $DLManagerEtcDir/dlmcfgmgr*.log #Removing temporary log files
        if [ -d $DLMCTRLDIR ] || $CMD_LS /dev | $CMD_GREP -q $DLMBLKDEV || $CMD_LS /dev | $CMD_GREP -q $DLMCHRDEV ; then 
	        export CFGMGR_FROM_SYSINIT=1
	        $CMD_ECHO  $"Removing HDLM devices: "
            $DLMCfgMgr -d -s > /dev/null 2>&1 && { /bin/logger "Removing HDLM devices: succeeded"; rc_status; rc_status -v1; } || { /bin/logger "Removing HDLM devices: failed"; rc_failed; rc_status -v1; }  
	        unset CFGMGR_FROM_SYSINIT
        fi
        rc_reset
        $CMD_ECHO  $"Loading HDLM Alert driver: "
        # Use of Wrapper script for insmod and rmmod MOD Start
        if [ "TRUE" = "$USE_INS_RM_MOD_SCRIPT" ]; then
	        $DLM_INSMOD_Alert > /dev/null 2>&1 && { /bin/logger "Loading HDLM Alert driver:  succeeded"; rc_status; rc_status -v1; } || { /bin/logger "Loading HDLM Alert driver:  failed"; rc_failed; rc_status -v1; } 
	        if [ ! -x $DLM_INSMOD_Alert ]; then
		        $CMD_ECHO "Script execution failed, scriptname=$DLM_INSMOD_Alert"
	        fi
        else
	        $CMD_INSMOD $ALERTDRV > /dev/null 2>&1 && { /bin/logger "Loading HDLM Alert driver:  succeeded"; rc_status; rc_status -v1; } || { /bin/logger "Loading HDLM Alert driver:  failed"; rc_failed; rc_status -v1; } 
        fi
        # Use of Wrapper script for insmod and rmmod MOD Ends 
        # SDDLMADRV module insert steps end here for SuSE releases
        rc_exit
    fi
fi

