#!/bin/bash
#
CMD=$(basename $0)
CMDVER="1.0"
CMDSTR="$CMD v$CMDVER (2018/10)"

set -e -u


usage()
{
	echo "usage: $CMD [-q]" >&2
	exit 1
}

VERBOSE=true
PATH="$PATH:/usr/sbin"

[ "X${1:-}" = "X-q" ] && {
	VERBOSE=false
	shift
}
[ $# != 0 ] && usage


disabled=$(lpstat -t | grep ' disabled ' | awk '{ print $2; }')
msg=

for printer in $disabled
do
	if out=$(cupsenable $printer 2>&1)
	then
		msg="printer $printer disabled, re-enabled forced"
	else
		msg="printer $printer disabled, cupsenable failed with status $?\n$out"
	fi

	echo "$msg" | while read line
	do
		$VERBOSE && echo "$line"
		/usr/bin/logger -t $CMD "$line"
	done
done

exit 0
