#!/bin/sh
#
# Generic script to be run after installing PCP from a tarball
#

if [ ! -f /etc/pcp.env ]
then
    # PCP not installed ... seems odd
    #
    echo "Error: /etc/pcp.env not installed!"
    exit 1
fi

. /etc/pcp.env

# no need to touch $PCP_VAR_DIR/pmns/.NeedRebuild as this file
# is included in the tarball
#

for conf in \
    $PCP_PMCDCONF_PATH $PCP_PMCDOPTIONS_PATH $PCP_PMCDRCLOCAL_PATH \
    $PCP_PMIECONTROL_PATH $PCP_PMLOGGERCONTROL_PATH \
    $PCP_PMPROXYOPTIONS_PATH
do
    if [ -f "$conf.pre" -a -f "$conf" ]
    then
	if diff "$conf" "$conf.pre" >/dev/null 2>&1
	then
	    rm -f "$conf.pre"
	else
	    mv "$conf" "$conf.dist"
	    mv "$conf.pre" "$conf"
	    echo "Warning: $conf: original restored, new version in $conf.dist"
	fi
    fi
done

# Note: do not start pmie nor pmproxy by default
#
for svc in pcp
do
    if which rc-update >/dev/null 2>&1
    then
	if rc-update show | grep " $svc " >/dev/null 2>&1
	then
	    # service is already installed ...
	    #
	    rc-update delete $svc
	fi
	rc-update add $svc
    fi
    $PCP_RC_DIR/$svc start
done

exit 0
