#!/bin/sh # # Michael Goffioul # Updated by P T Withington for Mac OS X # Updated by Richard Bronosky # Updated by Steve Palm (N9YTY) - case insensitive URI, unique output files LOGFILE=/tmp/PDF.log GSBIN=/usr/bin/pstopdf FILENAME= echo "Script: $0" > $LOGFILE echo "Executable: $GSBIN" >> $LOGFILE echo "job: $1" >> $LOGFILE echo "user: $2" >> $LOGFILE echo "title: $3" >> $LOGFILE echo "num-copies: $4" >> $LOGFILE echo "options: $5" >> $LOGFILE echo "filename: $6" >> $LOGFILE # case of no argument, prints available URIs if [ $# -eq 0 ]; then if [ ! -x "$GSBIN" ]; then exit 0 fi echo "direct PDF \"Unknown\" \"PDF Writing\"" exit 0 fi # case of wrong number of arguments if [ $# -ne 5 -a $# -ne 6 ]; then echo "Usage: PDF job-id user title copies options [file]" exit 1 fi # get PDF directory from device URI, and check write status URI_PRE=`echo $DEVICE_URI | cut -c 1-3 | tr "[a-z]" "[A-Z]"` URI_BODY=`echo $DEVICE_URI | cut -c 4-` DEVICE_URI="${URI_PRE}${URI_BODY}" echo "Device URI: $DEVICE_URI" >> $LOGFILE PDFDIR=${DEVICE_URI#PDF:} if [ `echo $PDFDIR|cut -c1-3` = //~ ]; then PDFDIR=/Users/$2`echo $PDFDIR|cut -c4-` # This step added by Richard Bronosky to allow referencing the users home directory fi if [ ! -d "$PDFDIR" -o ! -w "$PDFDIR" ]; then echo "ERROR: directory $PDFDIR not writable" exit 1 fi echo "PDF directory: $PDFDIR" >> $LOGFILE # generate output filename OUTPUTFILENAME= if [ "$3" = "" ]; then OUTPUTFILENAME="$PDFDIR/unknown.PDF" else OUTPUTFILENAME="$PDFDIR/${3//[^[:alnum:]]/_}.PDF" fi FBASE=`basename ${OUTPUTFILENAME} .PDF` typeset -i I=1 while [ -e $OUTPUTFILENAME ] do OUTPUTFILENAME="${PDFDIR}/${FBASE}_$I.PDF" I=$I+1 done echo "Output file name: $OUTPUTFILENAME" >> $LOGFILE # run ghostscript if [ $# -eq 6 ]; then $GSBIN $6 -o $OUTPUTFILENAME >> $LOGFILE else $GSBIN -i -o $OUTPUTFILENAME >> $LOGFILE fi # modify ownership and permissions on the file # - world readable # - owns to user specified in argument chmod a+r $OUTPUTFILENAME if [ "$2" != "" ]; then chown $2 $OUTPUTFILENAME fi exit 0