2013-09-06 17:05:03 +02:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2013-09-08 11:39:31 +02:00
|
|
|
|
function trapINT() {
|
2013-09-08 12:18:22 +02:00
|
|
|
|
[ "x$trp" = "x" ] && trp="yes" || return
|
2013-12-27 07:06:16 +01:00
|
|
|
|
sleep 30 && rm -rf $uid &
|
2013-09-08 11:39:31 +02:00
|
|
|
|
exit
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function stop() {
|
|
|
|
|
echo "stop" > $uid/999999999-page.pbm
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-08 12:18:22 +02:00
|
|
|
|
function log() {
|
|
|
|
|
echo $* | logger -t pstoricohddst-gdi
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-08 11:39:31 +02:00
|
|
|
|
trap "stop; trapINT" SIGINT SIGTERM SIGQUIT
|
|
|
|
|
#trap 'echo No' SIGINT SIGTERM SIGQUIT EXIT;
|
2013-09-06 17:29:49 +02:00
|
|
|
|
# Username
|
2013-09-06 17:05:03 +02:00
|
|
|
|
user="$2"
|
2013-09-06 17:29:49 +02:00
|
|
|
|
|
|
|
|
|
# Page title (not used at this time, "Document" instead)
|
2013-09-06 17:05:03 +02:00
|
|
|
|
ptitle="$3"
|
2013-09-08 11:39:31 +02:00
|
|
|
|
my="$0"
|
2013-09-06 17:29:49 +02:00
|
|
|
|
|
|
|
|
|
# Printing date
|
2013-09-06 17:05:03 +02:00
|
|
|
|
ddate="`LC_ALL=en_US.UTF-8 date '+%Y/%m/%d %H:%M:%S'`"
|
|
|
|
|
|
2013-09-06 17:29:49 +02:00
|
|
|
|
# Temporary directory
|
|
|
|
|
uid="/tmp/pstoricohddst-gdi-`uuidgen`"
|
2013-09-06 17:05:03 +02:00
|
|
|
|
mkdir -p $uid
|
|
|
|
|
|
2013-09-08 11:39:31 +02:00
|
|
|
|
(
|
|
|
|
|
stage="empty"
|
|
|
|
|
inotifywait -q -m -r -e close_write --format '%f' $uid | grep --line-buffered 'page.pbm$' | while read page; do
|
2013-09-08 12:18:22 +02:00
|
|
|
|
# page submitted
|
2013-09-08 11:39:31 +02:00
|
|
|
|
[ "$stage" = "empty" ] && {
|
|
|
|
|
# Flushing PJL header
|
|
|
|
|
cat <<EOF
|
2013-09-06 17:05:03 +02:00
|
|
|
|
%-12345X@PJL
|
|
|
|
|
@PJL SET TIMESTAMP=$ddate
|
|
|
|
|
@PJL SET FILENAME=Document
|
|
|
|
|
@PJL SET COMPRESS=JBIG
|
|
|
|
|
@PJL SET USERNAME=$user
|
|
|
|
|
@PJL SET COVER=OFF
|
|
|
|
|
@PJL SET HOLD=OFF
|
|
|
|
|
EOF
|
|
|
|
|
|
2013-09-08 11:39:31 +02:00
|
|
|
|
stage="printing"
|
|
|
|
|
}
|
|
|
|
|
[ "$page" = "999999999-page.pbm" ] && {
|
|
|
|
|
# Flushing PJL footer
|
|
|
|
|
cat <<EOF
|
|
|
|
|
@PJL EOJ
|
|
|
|
|
%-12345X
|
|
|
|
|
EOF
|
2013-09-08 12:18:22 +02:00
|
|
|
|
pid=`ps ax | grep $uid | grep -v grep | awk ' { print $1 } '`
|
2013-09-08 11:39:31 +02:00
|
|
|
|
[ ! "x$pid" = "x" ] && kill $pid
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
[ "$stage" = "printing" ] && {
|
|
|
|
|
# Converting page to JBIG format (parameters are very special for this printer!)
|
|
|
|
|
pbmtojbg -p 72 -o 3 -m 0 -q < $uid/$page > $uid/raster.jbig
|
|
|
|
|
|
|
|
|
|
# Taking image size
|
|
|
|
|
jsize=`wc -c < $uid/raster.jbig`
|
|
|
|
|
|
|
|
|
|
# Taking image dimensions
|
2013-09-12 13:05:32 +02:00
|
|
|
|
read fn ft xs ys garb < <(identify $uid/$page | tr "x" " ")
|
2013-09-08 11:39:31 +02:00
|
|
|
|
|
|
|
|
|
# Flushing page header
|
|
|
|
|
cat <<EOF
|
2013-09-06 17:05:03 +02:00
|
|
|
|
@PJL SET PAGESTATUS=START
|
|
|
|
|
@PJL SET COPIES=1
|
|
|
|
|
@PJL SET MEDIASOURCE=AUTO
|
|
|
|
|
@PJL SET MEDIATYPE=PLAINRECYCLE
|
|
|
|
|
@PJL SET PAPER=A4
|
|
|
|
|
@PJL SET PAPERWIDTH=$xs
|
|
|
|
|
@PJL SET PAPERLENGTH=$ys
|
|
|
|
|
@PJL SET RESOLUTION=600
|
|
|
|
|
@PJL SET IMAGELEN=$jsize
|
|
|
|
|
EOF
|
|
|
|
|
|
2013-09-08 11:39:31 +02:00
|
|
|
|
# Flushing image
|
|
|
|
|
cat $uid/raster.jbig
|
2013-09-06 17:05:03 +02:00
|
|
|
|
|
2013-09-08 11:39:31 +02:00
|
|
|
|
# Flushing page footer
|
|
|
|
|
# TODO: pixelcount for toner estimate
|
|
|
|
|
cat <<EOF
|
2013-09-06 17:05:03 +02:00
|
|
|
|
@PJL SET DOTCOUNT=1132782
|
|
|
|
|
@PJL SET PAGESTATUS=END
|
|
|
|
|
EOF
|
2013-09-08 11:39:31 +02:00
|
|
|
|
}
|
2013-09-06 17:05:03 +02:00
|
|
|
|
done
|
2013-09-08 11:39:31 +02:00
|
|
|
|
) &
|
2013-09-06 17:05:03 +02:00
|
|
|
|
|
2013-09-08 11:39:31 +02:00
|
|
|
|
# Converting from PostScript to PostScript-monochrome, then to PBM image format (per page)
|
|
|
|
|
gs -sDEVICE=psmono -sOutputFile=- -r600 -dQUIET -dBATCH -dNOPAUSE - | gs -sDEVICE=pbmraw -sOutputFile=${uid}/%d-page.pbm -r600 -dQUIET -dBATCH -dNOPAUSE -
|
|
|
|
|
|
|
|
|
|
stop
|
|
|
|
|
wait
|
|
|
|
|
|
|
|
|
|
trapINT
|