Adding Buchan Milne's updates.
[gd/samba-autobuild/.git] / packaging / Mandrake / samba-print-pdf.sh
1 #!/bin/bash
2 # samba-print-pdf
3 # This is a script which allows you to set up a virtual printer on samba
4 # which will take the file (generated by a postscript filter on windows)
5 # and turn it into a PDF, informing the user of where it is when it
6 # is done
7 #
8 # Buchan Milne <bgmilne@cae.co.za> 20020723
9 #
10 # Arguments:
11 # $1 = file (usually passed with %s from samba)
12 # $2 = unix prefix to where to place the file (~%u should work)
13 # $3 = windows prefix to the same location (\\%L\%u should work)
14 # $4 = user/computer to send a notification to (%u or %m)
15 # $5 = IP address of client (%I)
16
17
18 PS2PDF=ps2pdf13 
19 OPTIONS="-dAutoFilterColorImages=false -sColorImageFilter=FlateEncode"
20 INPUT=$1
21 KEEP_PS=1
22 PERMS=640
23 INFILE=$(basename $INPUT)
24 BASEFILE=pdf-service
25
26 #make a temp file to use for the output of the PDF
27 OUTPUT=`mktemp -q $2/$BASEFILE-XXXXXX`
28 if [ $? -ne 0 ]; then
29         echo "$0: Can't create temp file $2/$BASEFILE-XXXXXX, exiting..."
30         exit 1
31 fi
32                                                                         
33 WIN_OUTPUT="$3\\`basename $OUTPUT`"
34
35 # create the PDF:
36 $PS2PDF $OPTOINS $INPUT $OUTPUT.pdf >/dev/null 2>&1
37
38 # Generate a message to send to the user, and deal with the original file:
39 MESSAGE=$(echo "Your PDF file has been created as $WIN_OUTPUT.pdf\n")
40
41 if [ $KEEP_PS ];then
42         mv $INPUT $OUTPUT.ps
43         MESSAGE=$(echo "$MESSAGE and your postscript file as $WIN_OUTPUT.ps")
44         # Fix permissions on the generated files
45         chmod $PERMS $OUTPUT.ps
46 else
47         rm -f $INPUT
48         chmod $PERMS $OUTPUT.ps $OUTPUT.pdf
49         # Fix permissions on the generated files
50 fi
51                                                                 
52 chmod $PERMS $OUTPUT.ps $OUTPUT.pdf
53
54 #Remove empty file from mktemp:
55 rm -f $OUTPUT
56
57 # Send notification to user
58 echo -e $MESSAGE|smbclient -M $4 -I $5 -U "PDF Generator" >/dev/null 2>&1
59