
if dpkg-maintscript-helper supports mv_conffile
then
    _version_configs "$@"
fi

touch /var/lib/pcp/pmns/.NeedRebuild
chmod 644 /var/lib/pcp/pmns/.NeedRebuild
touch /var/log/pcp/pmlogger/.NeedRewrite
chmod 644 /var/log/pcp/pmlogger/.NeedRewrite

getent group pcp >/dev/null || groupadd -r pcp
getent passwd pcp >/dev/null || \
useradd -c "Performance Co-Pilot" -g pcp -d /var/lib/pcp -M -r -s /usr/sbin/nologin pcp

# must match GNUmakefile
chown pcp:pcp /var/lib/pcp/config/pmda
chmod 775 /var/lib/pcp/config/pmda
chown pcp:pcp /var/lib/pcp/tmp
chmod 775 /var/lib/pcp/tmp
chown pcp:pcp /var/log/pcp
chmod 775 /var/log/pcp
chown pcp:pcp /etc/pcp/nssdb
chmod 775 /etc/pcp/nssdb

# must match src/pmcd/GNUmakefile
chown pcp:pcp /var/log/pcp/pmcd
chmod 775 /var/log/pcp/pmcd

# must match src/pmdas/{json,bash,mmv}/GNUmakefile
for PMDA in bash json mmv; do
    # directory may be in optionally build component, so test first
    #
    if [ -d /var/lib/pcp/tmp/$PMDA ]
    then
	chown pcp:pcp /var/lib/pcp/tmp/$PMDA
	chmod 775 /var/lib/pcp/tmp/$PMDA
    fi
done

# must match src/pmie/GNUmakefile
chown pcp:pcp /var/lib/pcp/config/pmie
chmod 775 /var/lib/pcp/config/pmie
chown pcp:pcp /var/lib/pcp/tmp/pmie
chmod 775 /var/lib/pcp/tmp/pmie
chown pcp:pcp /var/log/pcp/pmie
chmod 775 /var/log/pcp/pmie

# must match src/pmlogger/GNUmakefile
chown pcp:pcp /var/lib/pcp/config/pmlogger
chmod 775 /var/lib/pcp/config/pmlogger
chown pcp:pcp /var/lib/pcp/tmp/pmlogger
chmod 775 /var/lib/pcp/tmp/pmlogger
chown pcp:pcp /var/log/pcp/pmlogger
chmod 775 /var/log/pcp/pmlogger
chown pcp:pcp /var/log/pcp/sa
chmod 775 /var/log/pcp/sa

# must match src/pmproxy/GNUmakefile
chown pcp:pcp /var/log/pcp/pmproxy
chmod 775 /var/log/pcp/pmproxy

# and fixup the change in deployment plan for these ones in the case
# of an upgrade, rather than an install ... they used to be pcp:pcp
chown root:root /etc/pcp/pmie
chmod 755 /etc/pcp/pmie
chown root:root /etc/pcp/pmie/control
chmod 644 /etc/pcp/pmie/control
chown root:root /etc/pcp/pmlogger
chmod 755 /etc/pcp/pmlogger
chown root:root /etc/pcp/pmlogger/control
chmod 644 /etc/pcp/pmlogger/control

do_systemd=true
which deb-systemd-helper >/dev/null 2>&1 || do_systemd=false
# only need to check pmcd.service, if it is here they will all
# be here
[ -f /lib/systemd/system/pmcd.service ] || do_systemd=false

if $do_systemd
then
    deb-systemd-helper enable pmcd.service >/dev/null
    deb-systemd-helper enable pmlogger.service >/dev/null
    deb-systemd-helper enable pmie.service >/dev/null
    deb-systemd-helper enable pmproxy.service >/dev/null
elif which update-rc.d >/dev/null 2>&1
then
    update-rc.d -f pmcd remove >/dev/null
    update-rc.d pmcd defaults >/dev/null
    update-rc.d -f pmlogger remove >/dev/null
    update-rc.d pmlogger defaults >/dev/null
    update-rc.d -f pmie remove >/dev/null
    update-rc.d pmie defaults >/dev/null
    update-rc.d -f pmproxy remove >/dev/null
    update-rc.d pmproxy defaults >/dev/null
fi

if which invoke-rc.d >/dev/null 2>&1
then
    invoke-rc.d pmcd start
    invoke-rc.d pmlogger start
else
    /etc/init.d/pmcd start
    /etc/init.d/pmlogger start
fi
