# Copyright 2017 Lucid Networks sloeckle
# Package Version 1.11-0 - Script Version 2

. /opt/nexp-tools/nexp-tools.lib

source /etc/nexp-tools/nexp-tools.conf

export DISPLAY=:0
export EMAIL=$HOSTNAME'@lucidnetworks.net'
time=$(date +"%m-%d-%Y_%T")
rand=$(od -N 4 -t uL -An /dev/urandom | tr -d " ")
systeminfo
dir=/tmp/$rand
mkdir $dir &>/dev/null
scrot -q 100 $dir/$time.png &>/dev/null
convert $dir/$time.png -colorspace Gray $dir/$time.tif
#convert $dir/$time.png -blur 1x65535 -level 30x100% -colorspace Gray -contrast-stretch 0 -lat 25x25+20 -sharpen 0x1 $dir/$time.tif
ocr=$(tesseract $dir/$time.tif stdout)
text="$ocr\n\n\n$systeminfo\n"
#convert $dir/$time.png -background Khaki label:"$systeminfobrief" -gravity Center -append $dir/$time-annotated.png
#convert $dir/$time.png -background '#00000080' -fill white label:"$systeminfo" miff:- | composite -gravity south -geometry +0+3 $dir/$time-annotated.pngconvert $dir/$time.png -fill white  -undercolor '#00000080' -pointsize 20 -gravity South -annotate +5+5 "$systeminfobrief" $dir/$time-annotated.png
if [ $APPNOTIFICATION == true ]; then
	if test -z "$1"
	then
		echo -e $text | mutt -s "$HOSTNAME Screenshot OCR @ $time" -a $dir/$time-annotated.png -- $APPMAILTO
	else
		echo -e $text | mutt -s "$HOSTNAME Screenshot OCR @ $time" -a $dir/$time-annotated.png -- $APPMAILTO,$1
	fi
fi
# rm -rf $dir &>/dev/null
