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

sts=0
tmp=/var/tmp
trap "rm -f $tmp.*; exit \$sts" 0 1 2 3 15

if [ ! -f /etc/pcp.conf ]
then
    echo "No /etc/pcp.conf ... assume PCP not installed or disabled"
    exit
fi

if [ -f /etc/pcp.env ]
then
    . /etc/pcp.env
else
    echo "No /etc/pcp.env ... prior PCP installation botched"
    sts=1
    exit
fi

# -n (show-me) is the only command line option ...
#
if [ $# -eq 1 -a X"$1" = X"-n" ]
then
    show_me=true
    RM="echo + rm"
    MV="echo + mv"
    MKDIR="echo + mkdir"
    SYSTEMCTL="echo + systemctl"
    RC_UPDATE="echo + rc-update"
    KILL="echo + kill"
else
    show_me=false
    RM=rm
    MV=mv
    MKDIR=mkdir
    SYSTEMCTL=systemctl
    RC_UPDATE=rc-update
    KILL=kill
fi

# The new place ... this should match the setting in /etc/pcp.conf
# _after_ the installation
#
PCP_SYSCONF_DIR=@pcp_sysconf_dir@
# and same here ...
#
PCP_LOG_DIR=@pcp_log_dir@
[ -d "$PCP_LOG_DIR" ] || $MKDIR "$PCP_LOG_DIR"

# and some other things we need ...
#
PCP_RC_DIR=@pcp_rc_dir@
PCP_PMCDCONF_PATH=@pcp_pmcdconf_path@
PCP_PMCDOPTIONS_PATH=@pcp_pmcdoptions_path@
PCP_PMCDRCLOCAL_PATH=@pcp_pmcdrclocal_path@
PCP_PMIECONTROL_PATH=@pcp_pmiecontrol_path@
PCP_PMLOGGERCONTROL_PATH=@pcp_pmloggercontrol_path@
PCP_PMPROXYOPTIONS_PATH=@pcp_pmproxyoptions_path@
