Mandrake packaging updates from Buchan & Sly
[Samba.git] / packaging / Mandrake / samba-print-pdf.sh
blob3d88f9fb8854434a8062b7ccd876250192de6cd6
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
8 # Buchan Milne <bgmilne@cae.co.za> 20020723
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)
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
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
33 WIN_OUTPUT="$3\\`basename $OUTPUT`"
35 # create the PDF:
36 $PS2PDF $OPTIONS $INPUT $OUTPUT.pdf >/dev/null 2>&1
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")
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
52 chmod $PERMS $OUTPUT.ps $OUTPUT.pdf
54 #Remove empty file from mktemp:
55 rm -f $OUTPUT
57 # Send notification to user
58 echo -e $MESSAGE|smbclient -M $4 -I $5 -U "PDF Generator" >/dev/null 2>&1