diff options
author | Simon Rettberg | 2015-10-05 18:41:51 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-10-05 18:41:51 +0200 |
commit | dd6fc5fcca6759afe1087fbfaab5449588561f21 (patch) | |
tree | 020c575f30e4c941f4ff8dbdf47197770e2109d0 | |
parent | [auth-freiburg] Add proper group search base for sssd (diff) | |
download | tm-scripts-dd6fc5fcca6759afe1087fbfaab5449588561f21.tar.gz tm-scripts-dd6fc5fcca6759afe1087fbfaab5449588561f21.tar.xz tm-scripts-dd6fc5fcca6759afe1087fbfaab5449588561f21.zip |
[run-virt/printergui] Add wrapping helper script for printing that does some error checking on the file received from lpd
-rwxr-xr-x | remote/modules/printergui/data/opt/openslx/scripts/run-virt_print | 61 | ||||
-rw-r--r-- | remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_printer_lpd.inc | 4 |
2 files changed, 63 insertions, 2 deletions
diff --git a/remote/modules/printergui/data/opt/openslx/scripts/run-virt_print b/remote/modules/printergui/data/opt/openslx/scripts/run-virt_print new file mode 100755 index 00000000..dfbcdfde --- /dev/null +++ b/remote/modules/printergui/data/opt/openslx/scripts/run-virt_print @@ -0,0 +1,61 @@ +#!/bin/ash + +# Called with $1=USERNAME $2=PRINTFILE + +USER="$1" +FILE="$2" +PRINTERGUI="/opt/openslx/cups/printergui" + +errlog () { + FD=0 + [ -t 1 ] && FD=1 + [ -t 2 ] && FD=2 + if [ $FD -ne 0 ]; then + echo "$2" >&$FD + elif [ $# -gt 2 ]; then + slxlog "$1" "$2" "$3" + sleep 1 + else + slxlog "$1" "$2" + fi + $PRINTERGUI --error "$2" & +} + +if [ $# -ne 2 ]; then + # Bad usage + errlog "printergui-call" "Error: Wrong number of arguments (got $#) ($@)" + exit 1 +fi + +if [ ! -r "$FILE" ]; then + errlog "printergui-file" "Error: File '$FILE' not readable" + exit 1 +fi + +if [ ! -s "$FILE" ]; then + errlog "printergui-file" "Error: File '$FILE' is empty" + exit 1 +fi + +# Some basic error checking if we have ghostscript available +if which gs 2>/dev/null; then + ERRLOG=$(mktemp) + [ -z "$ERRLOG" ] && ERRLOG="/tmp/tmp-$RANDOM-$$-$(whoami)" + gs -sDEVICE=nullpage -dNOPAUSE -dBATCH "$FILE" 2>"$ERRLOG" + RET=$? + if [ $RET -ne 0 ]; then + errlog "printergui-validate" "Error: Ghostscript choked on input file" "$ERRLOG" + exit 1 + fi +else + errlog "printergui-nogs" "Warning: Cannot validate file prior to printing: gs binary not found" +fi + +# Try to print +$PRINTERGUI "$USER" "$FILE" +RET=$? +if [ $RET -ne 0 -a $RET -ne 143 ]; then # SIGTERM results in 143, is sent by printpwgui + errlog "printergui-exec" "Error: printergui execution failed with exit code $RET" +fi +exit $RET + diff --git a/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_printer_lpd.inc b/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_printer_lpd.inc index 425ae9d9..ab010722 100644 --- a/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_printer_lpd.inc +++ b/remote/modules/run-virt/data/opt/openslx/scripts/includes/setup_printer_lpd.inc @@ -3,7 +3,7 @@ ##################################### QUEUE="STANDARD" # This has to match the queue you configured in your VM -USER="$(/usr/bin/whoami)" +USER="$(whoami)" SPOOLDIR= ### Disabled: 100megs is not enough, some jobs are HUGE, try to use temp which should be on disk @@ -28,7 +28,7 @@ fi # TODO: externalize with something like runvirt.d (other parts might benefit from that too) tcpsvd -E 192.168.101.1 5515 \ lpd "$SPOOLDIR" \ - ash -c "/opt/openslx/cups/printergui '${USER}' \"${SPOOLDIR}/${QUEUE}/\$DATAFILE\"" & + ash -c "/opt/openslx/scripts/run-virt_print '${USER}' \"${SPOOLDIR}/${QUEUE}/\$DATAFILE\"" & # PID to kill the process PID_LPD="$!" |