#!/bin/sh
#
# Import PCP services into SMF but do not start them - let admin do it
# when she's ready.
#

export PATH=/usr/sbin:$PATH

if [ -f /etc/pcp.conf ]
then
    # for all the configuration files we know about, try to keep 
    # any local modifications, and salt away file with a .orig
    # suffix for a subsequent upgrade
    #
    . /etc/pcp.conf
    for conf in \
	$PCP_PMCDCONF_PATH $PCP_PMCDOPTIONS_PATH $PCP_PMCDRCLOCAL_PATH \
	$PCP_PMIECONTROL_PATH $PCP_PMLOGGERCONTROL_PATH \
	$PCP_PMPROXYOPTIONS_PATH $PCP_PMWEBDOPTIONS_PATH
    do
	if [ -f $conf.pre -a -f $conf ]
	then
	    if cmp -s $conf.pre $conf
	    then
		cp $conf $conf.orig
		rm $conf.pre
	    else
		# restore local modifications ...
		cp $conf $conf.orig
		mv $conf.pre $conf
	    fi
	elif [ -f $conf ]
	then
	    cp $conf $conf.orig
	fi
    done
fi

getent group pcp >/dev/null || groupadd -r pcp
getent passwd pcp >/dev/null || \
  useradd -c "Performance Co-Pilot" -g pcp -d /var/lib/pcp -M -r -s /usr/bin/false pcp
chown -R pcp:pcp /var/log/pcp/pmcd 2>/dev/null
chown -R pcp:pcp /var/log/pcp/pmlogger 2>/dev/null
chown -R pcp:pcp /var/log/pcp/pmie 2>/dev/null
chown -R pcp:pcp /var/log/pcp/pmwebd 2>/dev/null
chown -R pcp:pcp /var/log/pcp/pmproxy 2>/dev/null

svccfg import /var/svc/manifest/application/pcp.xml

# only needed if you're making changes to the namespace for the
# pre-installed PMDAs like solaris
#
#. /etc/pcp.env
#rm -f $PCP_VAR_DIR/pmns/root $PCP_VAR_DIR/pmns/root.bin
