LOGDIR=/var/sadm/patch/116342-02
LOG=$LOGDIR/postpatch.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

# setup
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

# take fastcgi out of httpd.conf file (if previous version of patch hasn't
# already)
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/apach/conf ]; then
	echo "Updating httpd.conf" >> $LOG 2>&1
        cd $ESM_BASE/util/apache/conf
        /bin/mv httpd.conf .httpd.conf.nsm
        /bin/grep -vi fcgi .httpd.conf.nsm > httpd.conf1
        /bin/grep -vi fastcgi httpd.conf1 > httpd.conf2
        _flen=`wc -l httpd.conf2 | sed -e 's/\ httpd\.conf2//'`
        _flen=`expr ${_flen} - 2`
        /bin/head -${_flen} httpd.conf2 > httpd.conf
        /bin/rm -f httpd.conf1 httpd.conf2
    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
