#!/bin/bash

################################################################################
# * IBM Confidential                                                           *
# * OCO Source Materials                                                       *
# * @EPEE_PID@
# *                                                                            *
# * (C) Copyright IBM Corp. 2007, 2008                                         *
# *                                                                            *
# * The source code for this program is not published or otherwise divested of *
# * its trade secrets, irrespective of what has been deposited with the U.S.   *
# * Copyright Office.                                                          *
################################################################################

#
# This postflight script start up XPD Core to begin provisioning.
#

chmod -R 775 "/tmp/xpd.config"

### 10/17/2007
### 
### SPR XQTG76HCLX Fixed by Yun Zhi lin
### If provisioning fails,installer would indicate failure to end user

rcp_home=`cat /tmp/xpd.config |grep "pathToRcpHome" | cut -d '=' -f2`

provision_rc="$rcp_home"/../.provisioning_rc


#check if provisioning finishes successfully,if provisioning failure ,we return -1 to set the installation fail.
#The result code in provisining_rc is:
#RC_SUCCESS=0
#RC_FAILURE=1
#RC_FAILURE_PARTIAL_RESULT=2
#RC_NO_MANIFEST_FOUND=8
#RC_CANCELLED=9
#RC_PROV_PROCESS_ERROR=99

#Put this check in postflight but not in postinstall,because if some features fail to provision, they may not affect the whole system.
#The platform is able to start, just missing some features. If we put the check in postinstall,the platform could not be started.
#And if we put this check in postflight,it would apply to both install and upgrade,we do not need to implement the same function in install and upgrade twice.

#If we could not find provision_rc or it is empty, we would regard as a failure.
if [ ! -f "$provision_rc" -o ! -s "$provision_rc" ]
then
    result=-1
else
    #  provision_rc is not empty, we try to read rc from this file
    #  provision_rc is a properties file like: rc=0
    rc=`cat "$provision_rc" |grep "rc" | cut -d '=' -f2`
    #if rc is empty, we regard as a failure
    if [ -z $rc ]
    then
		result=-1
    else
		if [ $rc -eq 0 -o $rc -eq 2 ]
		then
			#RC_SUCCESS and RC_FAILURE_PARTIAL_RESULT would regard as success.
			result=0
		else
			result=-2
		fi
    fi
fi

# remvoe eclipse site. This is caused by LI 7011. This removal is due to rcplauncher on Mac has not changed to accommodate this change, we need to remove it here.
rm -rf "$rcp_home/../eclipse"

# remove /tmp/xpdinstall directory
rm -rf "$3/tmp/xpdinstall"


#remove receipts

filelist=`ls "$3/Library/Receipts"|grep xpdclient|grep coreinstaller`
for file in $filelist
do
	rm -rf "$3/Library/receipts/$file"
done


exit $result