#!/bin/sh
#
# Copyright (c) 2004 by Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#

# Start the server, if needed
PATHNUM=`env | grep PatchNum`
AS_BASEDIR=${ROOTDIR}/`pkginfo -R ${ROOTDIR} -r SUNWasvu`
LOCAL_AS_BASEDIR=`pkginfo -R ${ROOTDIR} -r SUNWasvu`
if [ -f ${AS_BASEDIR}/etc/mps/admin/v5.2/shared/config/serverroot.conf ] ; then
    	SERVER_ROOT=${ROOTDIR}/`cat ${AS_BASEDIR}/etc/mps/admin/v5.2/shared/config/serverroot.conf`
fi

if [ -f  /var/tmp/.shouldRestartAS_prepatch_${PATHNUM} ]
then
	echo "Postbackout script is starting Administration Server..."
	USER=`cat /var/tmp/.shouldRestartAS_prepatch_${PATHNUM}`
	su ${USER} -c "${LOCAL_AS_BASEDIR}/usr/sbin/mpsadmserver start"
	rm -f /var/tmp/.shouldRestartAS_prepatch_${PATHNUM}

	if [ -f ${SERVER_ROOT}/admin-serv/logs/pid  ]
	then
		echo "Postbackout script has started Administration Server."
	else
		echo "Postbackout script failed to start Administration Server."
	fi
else
	if [ "x${ROOTDIR}" != x ] && [ "x${ROOTDIR}" != "x/" ]
	then
		if [ -f ${SERVER_ROOT}/admin-serv/config/adm.conf ]
		then
            		echo ""
            		echo "Postbackout script cannot start Administration Server when option -R is used."
	    		echo "If you need to start Administration Server,"
	    		echo "log in to the system where Administration Server is installed"
	    		echo "and run the following command:"
	    		echo "${LOCAL_AS_BASEDIR}/usr/sbin/mpsadmserver start" | sed "s,//*,/,g"
		fi
	fi
fi
