#!/bin/sh

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


}

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


	FILENAME=ssl_record.beam
	
	INSTALLPATH=/usr/local/asc/lib/erlang/lib/ssl-4.1/ebin
	INSTALLEDFILE=$INSTALLPATH/$FILENAME
    

if [ ! -f $INSTALLEDFILE ];
then
	echo "Intel(R) Active System Console installation could not be detected"
	echo "If Intel(R) Active System Console is installed, please stop "
	echo "appcore, lighttpd and ascpolicy services manually  and copy the"
	echo "$FILENAME to $INSTALLPATH 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..."


	PATCHFILEPATH="./" 	

    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"
            PATCHFILEPATH="./RHEL/RHEL5/"
        else
            #OSV=`echo $OSV|grep 4`
            if [ $OSV == 4 ];then
                PATCHFILEPATH="./RHEL/RHEL4/"
            fi
        fi

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

    #echo $PATCHFILEPATH   
   
    if [ -f $INSTALLEDFILE ];
    then
        stopsvcs
    fi

    PATCHFILE="${PATCHFILEPATH}${FILENAME}"

    echo $PATCHFILE

    cp -f $PATCHFILE $INSTALLEDFILE

    if [ -f $INSTALLEDFILE ];
    then
        /usr/local/asc/bin/IASCService.sh
    fi 

fi
