#!/bin/sh

function stopsvcs
{
#stop services 
	/etc/init.d/lighttpd stop 
	/etc/init.d/ascpolicy stop 

}

function startsvcs 
{ 
#start services 
	/etc/init.d/lighttpd start 
	/etc/init.d/ascpolicy start 
}

if [ ! -f /usr/local/asc/lib/libdatamanager.so.0.0.0 ];
then
	echo "Intel(R) Active System Console installation could not be detected"
	echo "If Intel(R) Active System Console is installed, please stop "
	echo "lighttpd and ascpolicy services manually  and copy the"
	echo "libdatamanager.so.* to /usr/local/asc/lib/ and restart the services"
else


    echo "Warning: Intel(R) Active System Console Patch Installation is in progress."
    echo "All the Intel(R) Active System Console services will be restarted..."


    SOFILEPATH="./" 

    OS=`lsb_release -d | awk '{printf $2 $3}'`


    if [  $OS == 'RedHat' ];then
        OSV=`lsb_release -d | awk '{print $8}'`  
        #echo $OSV
	OSV=`echo $OSV | cut -f 1 -d .`
        if [ $OSV == 5 ];then
            #echo "5 pass"
            SOFILEPATH="./RHEL/RHEL5/"
        else
            #OSV=`echo $OSV|grep 4`
            if [ $OSV == 4 ];then
                SOFILEPATH="./RHEL/RHEL4/"
            fi
        fi

    elif [ $OS == 'SUSELinux' ];then
        OSV=`lsb_release -d | awk '{print $6}'`
        #OSV=`echo $OSV|grep 10` 
        if [ $OSV == 10 ];then
            SOFILEPATH="./SLES/SLES10/"
            #$OSV=`echo $OSV|grep 11`
        elif [ $OSV == 11 ];
        then
            SOFILEPATH="./SLES/SLES11/" 
        fi
    fi

   # echo $SOFILEPATH


    if [ -f /usr/local/asc/lib/libdatamanager.so.0.0.0 ];
    then
        stopsvcs
    fi

    FILE="${SOFILEPATH}libdatamanager.so.0.0.0"

    #echo $FILE

    cp -f $FILE /usr/local/asc/lib/libdatamanager.so.0.0.0

    if [ -f /usr/local/asc/lib/libdatamanager.so.0.0.0 ];
    then
        startsvcs
    fi 

fi
