Code cleanup

This commit is contained in:
Serge V Shistarev 2013-09-08 19:18:22 +09:00
parent f6c2cff604
commit 8d277a9b1a

View file

@ -1,9 +1,7 @@
#!/bin/bash #!/bin/bash
function trapINT() { function trapINT() {
[ "x$trp" = "x" ] && trp="yes" || return [ "x$trp" = "x" ] && trp="yes" || return
# pid=`ps a | grep $uid | grep -v grep | awk ' { print $1 } '`
# [ ! "x$pid" = "x" ] && { kill $pid; sleep 5; }
sleep 3 sleep 3
rm -rf $uid rm -rf $uid
exit exit
@ -13,6 +11,10 @@ function stop() {
echo "stop" > $uid/999999999-page.pbm echo "stop" > $uid/999999999-page.pbm
} }
function log() {
echo $* | logger -t pstoricohddst-gdi
}
trap "stop; trapINT" SIGINT SIGTERM SIGQUIT trap "stop; trapINT" SIGINT SIGTERM SIGQUIT
#trap 'echo No' SIGINT SIGTERM SIGQUIT EXIT; #trap 'echo No' SIGINT SIGTERM SIGQUIT EXIT;
# Username # Username
@ -32,6 +34,7 @@ mkdir -p $uid
( (
stage="empty" stage="empty"
inotifywait -q -m -r -e close_write --format '%f' $uid | grep --line-buffered 'page.pbm$' | while read page; do inotifywait -q -m -r -e close_write --format '%f' $uid | grep --line-buffered 'page.pbm$' | while read page; do
# page submitted
[ "$stage" = "empty" ] && { [ "$stage" = "empty" ] && {
# Flushing PJL header # Flushing PJL header
cat <<EOF cat <<EOF
@ -52,7 +55,7 @@ EOF
@PJL EOJ @PJL EOJ
%-12345X %-12345X
EOF EOF
pid=`ps a | grep $uid | grep -v grep | awk ' { print $1 } '` pid=`ps ax | grep $uid | grep -v grep | awk ' { print $1 } '`
[ ! "x$pid" = "x" ] && kill $pid [ ! "x$pid" = "x" ] && kill $pid
break break
} }
@ -95,16 +98,7 @@ done
# Converting from PostScript to PostScript-monochrome, then to PBM image format (per page) # 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 - gs -sDEVICE=psmono -sOutputFile=- -r600 -dQUIET -dBATCH -dNOPAUSE - | gs -sDEVICE=pbmraw -sOutputFile=${uid}/%d-page.pbm -r600 -dQUIET -dBATCH -dNOPAUSE -
stop stop
wait wait
trapINT trapINT
exit
ls $uid/ | grep 'pbm$' | sort -n | while read page; do
done