#!/bin/sh

# This is a maintenance shell script for the rkhunter security tool.
# You can enable this script in /etc/periodic.conf file by putting these lines into it:
#	security_rkhunter_update_enable="YES"
#	security_rkhunter_update_period="daily"
#	security_rkhunter_update_flags="--update --nocolors"
#	security_rkhunter_check_enable="YES"
#	security_rkhunter_check_period="daily"
#	security_rkhunter_check_flags="--checkall --nocolors --skip-keypress"
#
# Written by: Gabor Kovesdan <gabor@FreeBSD.org>

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

# compatibility with pre-stable/12 style variables
for type in update check
do
	for mode in enable flags
	do
		eval old=\"\$daily_rkhunter_${type}_${mode}\"
		if test -n "$old"
		then
			echo "Warning: Variable \$daily_rkhunter_${type}_${mode} is deprecated, use \$security_rkhunter_${type}_${mode} instead." >&2
			eval : \${security_rkhunter_${type}_${mode}:="\$daily_rkhunter_${type}_${mode}"}
		fi
	done
done

# defaults
: ${security_rkhunter_update_period:="daily"}
: ${security_rkhunter_check_period:="daily"}
: ${security_rkhunter_update_flags:="--update --nocolors"}
: ${security_rkhunter_check_flags:="--checkall --nocolors --skip-keypress"}

if check_yesno_period security_rkhunter_update_enable
then
	echo ""
	echo "Updating the rkhunter database..."
	anticongestion
	%%PREFIX%%/bin/rkhunter ${security_rkhunter_update_flags}
fi

if check_yesno_period security_rkhunter_check_enable
then
	echo ""
	echo "Running rkhunter..."
	%%PREFIX%%/bin/rkhunter ${security_rkhunter_check_flags}
fi
