#!/bin/sh
#
# Cull the pmlogger config.default to remove any zeroconf proc metric
# logging that threatens to fill the filesystem on small QA machines
#

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

. $PCP_DIR/etc/pcp.env

config=$PCP_VAR_DIR/config/pmlogger/config.default

[ ! -f $config ] && exit 0

#
# cull this line
# Auto-generated by pmlogconf on:  Thu Jul 30 08:31:28 AEST 2015
# and delete all of these ...
#+ zeroconf/atop-proc:y:10 seconds:
#
$PCP_AWK_PROG <$config >$tmp.tmp '
/^# Auto-generated /	{ print "# Config culled by qa/cull-pmlogger-config"; next }
/^#\+ zeroconf\//	{ skip = 1; print; next }
/^#\+ /		{ skip = 0 }
/DO NOT UPDATE THE FILE ABOVE THIS LINE/	{ skip = 0 }
/^#/			{ print; next }
skip == 1		{ next }
			{ print }'

if diff $config $tmp.tmp >/dev/null
then
    echo "Nothing to cull."
else
    diff -u $config $tmp.tmp
    sudo cp $tmp.tmp $config
    echo "Culled."
fi
