#!/bin/bash # Debug mode: change to 'yes' to enable DEBUG=no function log() { [ "${DEBUG}" = "yes" ] && echo $* | logger -t "$0[$$]" } function logpipe() { [ "${DEBUG}" = "yes" ] && echo $* | logger -t "$0[$$]" } function trapINT() { log "trapINT()" [ "x$trp" = "x" ] && trp="yes" || return sleep 30 && { [ ! "${DEBUG}" = "yes" ] && rm -rf $uid; log "Cleanup complete"; } & exit } function stop() { log "Stop stop page"; echo "stop" > $uid/999999999-page.pbm } log "Called with cmdline: $0 $*" trap "stop; trapINT" SIGINT SIGTERM SIGQUIT #trap 'echo No' SIGINT SIGTERM SIGQUIT EXIT; # Username user="$2" # Page title (not used at this time, "Document" instead) ptitle="$3" my="$0" options="$5" pagesize="A4" resolution="600" mediasource="TRAY1" for opt in $options; do case "$opt" in PageSize=*) pagesize="$(echo "${opt#PageSize=}" | tr a-z A-Z)" ;; Resolution=*) resolution=${opt#Resolution=} resolution=${resolution%dpi} ;; InputSlot=*) mediasource=${opt#InputSlot=} ;; esac done # MS-style EOL e=$(echo -en "\r") # Printing date ddate="`LC_ALL=en_US.UTF-8 date '+%Y/%m/%d %H:%M:%S'`" # Temporary directory uid="/tmp/pstoricohddst-gdi-`uuidgen`" mkdir -p $uid [ "${DEBUG}" = "yes" ] && exec >$uid/output.stream #> >(tee $uid/output.stream) [ -x "$(which inotifywait)" ] && { log "Asynchronous variant" ( stage="empty" inotifywait -q -m -r -e close_write --format '%f' $uid | grep --line-buffered 'page.pbm$' | while read page; do log "Page submitted" [ "$stage" = "empty" ] && { log "1st stage. Flushing PJL header" cat < $uid/raster.jbig # Taking image size jsize=`wc -c < $uid/raster.jbig` # Taking image dimensions read fn ft xs ys garb < <(identify $uid/$page | tr "x" " ") # Flushing page header cat < $uid/raster.jbig # Taking image size jsize=`wc -c < $uid/raster.jbig` # Taking image dimensions read fn ft xs ys garb < <(identify $page | tr "x" " ") log "Identified as ${xs}x${ys}" # Flushing page header cat <