LOGDIR=/var/sadm/patch/116342-02
LOG=$LOGDIR/postbackout.log

# check for root
user=`/bin/id | /usr/bin/grep root | /usr/bin/wc -l`
if [ $user -eq 0 ]; then
        echo "You must be root to execute this script."
        exit 1
fi

/bin/mkdir -p $LOGDIR

ESM_BASE=`/usr/bin/pkgparam SUNWstm ESM_BASE`
if [ $? -ne 0 ]; then
    msg="Could not determine ESM location."
    echo "$msg"
    echo "$msg" >> $LOG
    exit 1
fi


# restore httpd.conf file if -01 version wasn't on
oldpatch=0
/usr/bin/showrev -p | /usr/bin/grep "Patch: 116342" | /usr/bin/grep -v "116342-02" > /dev/null 2>&1
if [ $? -eq 0 ]; then
    oldpatch=1
fi

if [ $oldpatch -ne 1 ]; then
    if [ -d $ESM_BASE/util/apache/conf ]; then
        cd $ESM_BASE/util/apache/conf
        if [ -f .httpd.conf.nsm ]; then
	    echo "Restoring httpd.conf" >> $LOG
            /bin/mv .httpd.conf.nsm httpd.conf >> $LOG 2>&1
        fi
    fi
fi

# restart ESM if not adding patches with esmpatch
if [ "$ESM_CONTEXT" != "patch" ]; then
    $ESM_BASE/bin/esmcontrol -a start >> $LOG 2>&1
fi
