#!/bin/bash
#File Path to transfer the CUPS converted files
FILE_PATH="/var/opt/novell/iprintmobile/drivers/spool/"
# The echo string should contain the same file name,ie , printfile for lpadmin command to work
if [ $# -eq 0 ]; then
  echo 'direct printfile:/drivers/spool/  "Unknown" "Print any job to file specified in
  device-URI"'
  exit 0
fi
# Backend gets input data either via stdin or in filename argument as argv[6]. 
# Backend get the following arguments from CUPS
#argv[1] - CUPS job ID
#argv[2] - The user printing the job
#argv[3] - The job name/title/file name
#argv[4] - The number of copies to print
#argv[5] - The options
#argv[6] - The file to print 
#If input is at fd0 (stdin) in any case:
 if test -n "$6"
 then exec <"$6"
 fi
 
 #Saving the converted data along with its filename
cat - > /tmp/$3.prn
#Changing file permission
chmod 660 /tmp/$3.prn
#Changing file owner details
chgrp iprint /tmp/$3.prn

#Copying to mobile server's spool directory
mv /tmp/$3.prn $FILE_PATH$3.prn
exit 0

