summaryrefslogtreecommitdiffstats
path: root/remote/modules/printergui/data/opt
diff options
context:
space:
mode:
Diffstat (limited to 'remote/modules/printergui/data/opt')
-rwxr-xr-xremote/modules/printergui/data/opt/openslx/scripts/run-virt_print61
1 files changed, 61 insertions, 0 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
+