#!/bin/sh
#
# ###################################################################
# Copyright (c) 2000, EMC Corporation. All Rights Reserved.
#
# Most Recent Author: Raghu Adabala
# Previous Authors: Raghu Adabala and Ed Goggin
#
# Contents:
# install interfaces for EMC PowerPath ver 3.0 on Linux
# ###################################################################
#

# @(#) $Header: /cvs/source/master/pxmobility/src/pkg/i386_linux/bin_install/.options/distribution/MiracleLinux/.script,v 1.1.8.1 2004/09/09 20:31:06 lrobinso Exp $
#

INSTALL_PATH=$RPM_INSTALL_PREFIX/etc/init.d

init_install_patches()
{
    #
    # Get rid of these (we of course assume that if they exist, they
    # were created as the result of a previous PowerPath installation)
    # so that one can be assured that they are dealing with an up-to-date
    # version of a particular reject file.
    #
    rm -rf $RPM_INSTALL_PREFIX/etc/rc.modules.rej
}

process_install_patches()
{
    #
    # install $INSTALL_PATH/PowerPath.
    #

#    if [ ! -e $INSTALL_PATH/PowerPath ]; then
	cp -f $pp_dir/.options/distribution/MiracleLinux/PowerPath $INSTALL_PATH 2>> $PATCH_LOG
        if [ $? -ne 0 ]; then
  	    elog "$FAILURE $INSTALL_PATH/PowerPath.  Errors in $PATCH_LOG"
	    reset
        else
	    log "$SUCCESS $INSTALL_PATH/PowerPath."
        fi

	chmod 755 $INSTALL_PATH/PowerPath 2>> $PATCH_LOG 
        if [ $? -ne 0 ]; then
  	    elog "$FAILURE (chmod) of $INSTALL_PATH/PowerPath.  Errors in $PATCH_LOG"
	    reset
        else
	    log "$SUCCESS (chmod) of $INSTALL_PATH/PowerPath."
        fi

        if [ -e $RPM_INSTALL_PREFIX/etc/rc.modules ]; then
            grep "/etc/init.d/PowerPath start" $RPM_INSTALL_PREFIX/etc/rc.modules > /dev/null 2>&1
            rc_modules_flag=$?
        else
            rc_modules_flag=1;
        fi

        if [ "$patch" == TRUE -a $rc_modules_flag -ne 0 -o "$patch" != TRUE ]; then
             if [ ! -e $RPM_INSTALL_PREFIX/etc/rc.modules ] ; then
                 echo -n "#" > $RPM_INSTALL_PREFIX/etc/rc.modules
                 echo -ne ! >> $RPM_INSTALL_PREFIX/etc/rc.modules
                 echo "/bin/bash" >> $RPM_INSTALL_PREFIX/etc/rc.modules
                 chmod 755 $RPM_INSTALL_PREFIX/etc/rc.modules 2>> $PATCH_LOG 
             else
                 chmod 755 $RPM_INSTALL_PREFIX/etc/rc.modules 2>> $PATCH_LOG 
	         cp $RPM_INSTALL_PREFIX/etc/rc.modules $POWER_TMP_DIR/rc.modules
             fi 

	     patch -p0 < $pp_dir/.options/distribution/MiracleLinux/rc.modules.diff >> $PATCH_LOG 2>&1
             if [ $? -ne 0 ]; then
  	         elog "Failure to patch $RPM_INSTALL_PREFIX/etc/rc.modules.  Errors in $PATCH_LOG"
#
#	    No longer fails the install in this case in order that PowerPath
#	    may install on non-qualified distributions even if this file needs
#	    to be manually patched.
#
#	    reset
             else
	         log "$SUCCESS $RPM_INSTALL_PREFIX/etc/rc.modules."
             fi
         fi

#    fi
}

reset_install_patches()
{
    rm -f $INSTALL_PATH/PowerPath
    if [ -f $POWER_TMP_DIR/rc.modules ]; then
	 mv $POWER_TMP_DIR/rc.modules $RPM_INSTALL_PREFIX/etc/rc.modules
    else
         rm -f $RPM_INSTALL_PREFIX/etc/rc.modules
    fi
}

finish_install_patches()
{
    rm -f $POWER_TMP_DIR/rc.modules
}

#
# uninstall interfaces
#

init_uninstall_patches()
{
    if [ -e $INSTALL_PATH/PowerPath ]; then
	mv $INSTALL_PATH/PowerPath $POWER_TMP_DIR/PowerPath
    fi
    cp $RPM_INSTALL_PREFIX/etc/rc.modules $POWER_TMP_DIR/rc.modules
    #
    # Get rid of these (we of course assume that if they exist, they
    # were created as the result of a previous PowerPath installation)
    # so that one can be assured that they are dealing with an up-to-date
    # version of a particular reject file.
    #
    rm -rf $RPM_INSTALL_PREFIX/etc/rc.modules.rej
}

#process_uninstall_patches()
#{
#dummy
#}

reset_uninstall_patches()
{
    if [ -e $POWER_TMP_DIR/PowerPath ]; then
    	if [ -f $POWER_TMP_DIR/PowerPath ]; then
	    mv $POWER_TMP_DIR/PowerPath $INSTALL_PATH/PowerPath
	fi
    	if [ -f $POWER_TMP_DIR/rc.modules ]; then
	    mv $POWER_TMP_DIR/rc.modules /etc/rc.modules
	fi
    fi
}

finish_uninstall_patches()
{
    rm -f $POWER_TMP_DIR/PowerPath
    rm -f $POWER_TMP_DIR/rc.modules

    patch -p0 -R < $pp_dir/.options/distribution/MiracleLinux/rc.modules.diff >> $PATCH_LOG 2>&1
    if [ $? -ne 0 ]; then
	elog "Failed to reverse the PowerPath patch for $RPM_INSTALL_PREFIX/etc/rc.modules"
    fi
}
