#! /bin/sh
#
# Copyright (c) 2019 Red Hat.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# Replace the (deprecated) PAPI PMDA with perfevent
#

. $PCP_DIR/etc/pcp.env

if grep -q ^papi "$PCP_PMCDCONF_PATH" 2>/dev/null
then
    if grep -q ^perfevent "$PCP_PMCDCONF_PATH" 2>/dev/null
    then
	sed -i -e "/^papi.*/d" $PCP_PMCDCONF_PATH 2>/dev/null
    else
	sed -i -e "s,^papi.*,perfevent	127	pipe	binary	$PCP_PMDAS_DIR/perfevent/pmdaperfevent -d 127,g" $PCP_PMCDCONF_PATH 2>/dev/null
    fi
    rm -f "$PCP_VAR_DIR/pmns/papi" 2>/dev/null
    rm -f -r "$PCP_PMDAS_DIR/papi" 2>/dev/null
fi
exit 0
