#!/bin/sh
#
# Perform post-install steps for RPM packages installed
# on rpm-ostree installations.  This is usually done by
# %post sections in the PCP spec file but on rpm-ostree
# installs /var may not persist.
#

. /etc/pcp.env

if [ `id -u` != 0 ]
then
    echo >&2 "Error: this script must run as root"
elif [ ! -w "$PCP_VAR_DIR" ]
then
    echo >&2 "Error: $PCP_VAR_DIR is not writable"
else
    echo "Setting up PCP selinux policy ..."
    $PCP_BINADM_DIR/selinux-setup $PCP_VAR_DIR/selinux install pcpupstream

    echo "Preparing for service restart ..."
    touch $PCP_LOG_DIR/pmlogger/.NeedRewrite
    touch $PCP_PMNS_DIR/.NeedRebuild

    if [ -d $PCP_SHARE_DIR/zeroconf ]
    then
	echo "Enabling zeroconf metrics ..."
	for PMDA in dm nfsclient openmetrics
	do
	    touch $PCP_PMDAS_DIR/$PMDA/.NeedInstall
	done
    fi

    echo "Restarting services ..."
    systemctl restart pmcd pmlogger
    echo "Done.  Have a nice day!"
fi
