#!/bin/sh -
#
# $FreeBSD$
#

if [ -r /etc/defaults/periodic.conf ]; then
	. /etc/defaults/periodic.conf
	source_periodic_confs
fi

. /etc/periodic/security/security.functions

case "${daily_status_security_pkg_checksum_enable}" in
	[Yy][Ee][Ss])
	pkgcmd=/usr/local/sbin/pkg

	echo
	echo 'Checking for packages with mismatched checksums:'

	if ${pkgcmd} -N >/dev/null 2>&1 ; then
		echo 'pkg-checksum is enabled but pkg is not used'
		rc=2
	else
		rc=$(${pkgcmd} check -sa 2>&1 |
		sed -e 's/ checksum mismatch for//' |
		tee /dev/stderr |
		wc -l)
		[ $rc -gt 1 ] && rc=1
	fi
	;;
	*)
	rc=0
	;;
esac

exit $rc
