#
#	$OpenBSD: daily,v 1.88 2016/04/29 13:05:33 schwarze Exp $
#	From: @(#)daily	8.2 (Berkeley) 1/25/94
#
# For local additions, create the file /etc/daily.local.
# To get section headers, use the function next_part in daily.local.
#
umask 022

PARTOUT=/var/log/daily.part
MAINOUT=/var/log/daily.out
install -o 0 -g 0 -m 600    /dev/null $PARTOUT
install -o 0 -g 0 -m 600 -b /dev/null $MAINOUT

start_part() {
	TITLE=$1
	exec > $PARTOUT 2>&1
}

end_part() {
	exec >> $MAINOUT 2>&1
	test -s $PARTOUT || return
	echo ""
	echo "$TITLE"
	cat $PARTOUT
}

next_part() {
	end_part
	start_part "$1"
}

run_script() {
	f=/etc/$1
	test -e $f || return
	if [ `stat --format '%A%u' $f | cut -b1,6,9,11-` != '---0' ]; then
		echo "$f has insecure permissions, skipping:"
		ls -l $f
		return
	fi
	. $f
}

start_part "Running daily.local:"
run_script "daily.local"

# NOTE: Removed OpenBSD specific daily stuff.

next_part "Services that should be running but aren't:"
if systemctl --quiet is-failed '*'; then
	systemctl --failed
fi

next_part "Checking subsystem status:"
if [ "X$VERBOSESTATUS" != X0 ]; then
	echo ""
	echo "disks:"
	df -ikl
	if [ -x /sbin/dump ]; then
		echo ""
		/sbin/dump W
	fi;
fi

next_part "network:"
if [ "X$VERBOSESTATUS" != X0 ]; then
	netstat -ivn
fi

end_part
[ -s $MAINOUT ] && {
	uname -a
	echo
	uptime
	cat $MAINOUT
} 2>&1 | mail -s "`hostname` daily output" root

# NOTE: removed OpenBSD security(8) stuff.
