#!/bin/bash

# No way to push this to gitlab's CI runner YAML for now, so here's the script:
RETVAL=0

LOGROTS="$(find . -name "logrotate*" -type d|wc -l)"
[ "$LOGROTS" -eq 0 ]&&echo "No directory with a name starting with logrotate found."&&exit 0

for i in $(find . -name "logrotate*" -type d)/*;do
	ERRCNT="$(/usr/sbin/logrotate -ds /tmp/logrotcheck "$i" 2>&1|grep '^error:'|grep -vcE 'unknown group|found error')"
	echo "$i: $ERRCNT errors"
	[ "$ERRCNT" -ne 0 ]&&((++RETVAL))
	continue
done

exit $RETVAL