#!/bin/sh # # (C) 2011 Michiel Broek for ArchLinux # # Based on the SUSE script by Axel Schmidt and Michael Goffioul (kdeprint). # # License: GPL # # This is the CUPS Raw writer backend script. # # If this script is mode 0700, then it runs as root and files go into the # users home directories if they exist. # If this script is mode 0755, then it runs as lp and files go into the # path defined by the URL. That path should exist and should be owned by lp. # # To add this printer: # lpadmin -p RAW_2_File -v raw2file:/mnt/users/printfiles/ -E -D "Raw to files" -L "$(hostname -f)" # mkdir -p /mnt/users/printfiles # chown lp:lp /mnt/users/printfiles # chmod 755 /mnt/users/printfiles CAT=$( which cat ) DATE=$( date +%Y%m%d%H%M%S ) WHOAMI=$( id -un ) JOB=$1 PRTUSER=$2 # Check DEVICE DISCOVERY + test CAT # if [ "$JOB" = "" ]; then if test -f "$CAT" ; then echo "network raw2file:/mnt/users/printfiles \"Unknown\" \"Raw Writer (file)\" " logger "raw2file: INFO: driver information" exit 0 else echo "Error: $0 - cat is not available!" logger "raw2file: ERROR: cat is not available!" exit 1 fi fi # Check number of command line arguments # if [ $# -ne 5 -a $# -ne 6 ]; then echo "Usage: $0 job-id user title copies options [file]" logger "raw2file: CRITICAL: Printer stopped !" exit 1 fi logger "raw2file: start job $1 for $2, $4 copies" # get RAW-WRITER directory from device URI # PDFPATH=${DEVICE_URI#raw2file:} # Check write status # if [ ! -d "$PDFPATH" -o ! -w "$PDFPATH" ]; then logger "raw2file: ERROR: directory $PDFPATH not writeable" exit 1 fi # Create output filename based on user name and user mode # if [ "$WHOAMI" == "root" -a "$PRTUSER" != "" ]; then PASSWD=$( grep "^$PRTUSER" /etc/passwd ) if [ "$PASSWD" != "" ]; then HOMEDIR=$( echo $PASSWD | cut -d ':' -f 6 ) PRTUID=$( echo $PASSWD | cut -d ':' -f 3 ) PRTGID=$( echo $PASSWD | cut -d ':' -f 4 ) mkdir -p $HOMEDIR/printfiles chown $PRTUID:$PRTGID $HOMEDIR/printfiles chmod 755 $HOMEDIR/printfiles FILENAME="$HOMEDIR/printfiles/${JOB}-${DATE}.raw" else FILENAME="${PDFPATH}/${PRTUSER}-${JOB}-${DATE}.raw" fi else if [ "$PRTUSER" != "" ]; then FILENAME="${PDFPATH}/${PRTUSER}-${JOB}-${DATE}.raw" else FILENAME="${PDFPATH}/raw2file-${JOB}-${DATE}.raw" fi fi logger "raw2file: $FILENAME" # Run cat # if [ $# -eq 6 ]; then $CAT $6 > $FILENAME else $CAT - > $FILENAME fi logger "raw2file: written '${FILENAME}', result $?" # If PASSWD is set then we run as root # if [ "$PASSWD" != "" ]; then # Let the user own the file chown $PRTUID:$PRTGID $FILENAME chmod 644 $FILENAME else # Make file writable for the user. chmod 666 $FILENAME fi exit 0