r38: Fix caching of name->sid lookups
[Samba/gebeck_regimport.git] / packaging / Mandrake / samba-print-pdf.sh
blob973bb4f90eeb10a5da05da78407d62aad11a410c
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 # (c) Buchan Milne <bgmilne@cae.co.za> 2002
9 # License: GPLv2
10 # Changelog
11 # v0.0.6 20030428
12 # - Allow options passed as env. variables from print command
13 # - Inline and simplify sed (use tr) clean script
14 # - Ensure file arrives in PREFIX even if TEMP is used without provided name
15 # - Changes from Joshua M. Schmidlkofer <joshua@imr-net.com> 20030425
16 # - Debugging, adjustments, and corrections.
17 # - Stupid sed sanitizing script. [probably horribly inefficient also].
18 # - Temp file usage cleanup.
19 # v0.0.5 20020723
20 # - Add support for preset settings
21 # - Allow passing of filename provided by client as final filename
23 # Arguments:
24 # $1 = file (usually passed with %s from samba)
25 # $2 = unix prefix to where to place the file (~%u should work)
26 # $3 = windows prefix to the same location (//%L/%u should work)
27 # $4 = user/computer to send a notification to (%u or %m)
28 # $5 = IP address of client (%I)
29 # $6 = Name of destination file without extension (%J)
30 # $7 = PDF setting (prepress,print,screen etc)
32 # If you want to customise any of the following configuration defaults,
33 # you can place them in the file /etc/samba/print-pdf.conf.
34 # If you need to modify anything in this script, please provide me with your
35 # changes, preferably in such a way that the changes are configurable.
37 PS2PDF=ps2pdf13
38 OPTIONS="-dAutoFilterColorImages=false -sColorImageFilter=FlateEncode"
39 #Values taken from arguments:
40 INPUT=$1
41 PREFIX="$2"
42 WINBASE=$(echo "$3"|sed -e 's,/,\\\\,g')
43 #NAME=`echo "$6"|sed -e 's/[&/:{}\\\[<>$#@*^!?=|]/-/g;s/\]/-/g'`
44 NAME=`echo "$6"|tr '[:punct:]' '[-*]'`
46 # Source config file if it exists:
47 CONFFILE=/etc/samba/print-pdf.conf
48 [ -e $CONFFILE ] && . $CONFFILE
50 #Values not taken as arguments, could be set via env. vars (?) or config file
51 KEEP_PS=${KEEP_PS=0}
52 PERMS=${PERMS=640}
53 BASEFILE=${BASEFILE=pdf-service}
54 TEMP="${TEMP=$2}"
55 UMASK=${UMASK=006}
57 #Make sure that destination directory exists
58 mkdir -p "$PREFIX"
60 INFILE=$(basename $INPUT)
62 umask $UMASK
64 [ -n "$NAME" ] && TEMP="$PREFIX"
66 #make a temp file to use for the output of the PDF
67 OUTPUT=`mktemp -q $TEMP/$BASEFILE-XXXXXX`
68 if [ $? -ne 0 ]; then
69 echo "$0: Can't create temp file $TEMP/$OUTPUT, exiting..."
70 exit 1
72 if [ -n "$NAME" ]; then
73 FINALOUTPUT="$PREFIX/$NAME"
74 else
75 FINALOUTPUT="$OUTPUT"
77 if [ -n "$7" ]; then
78 OPTIONS="$OPTIONS -dPDFSETTINGS=/${7#pdf-}"
79 else
80 OPTIONS="$OPTIONS -dPDFSETTINGS=/default"
83 WIN_OUTPUT="$WINBASE\\"`basename "$FINALOUTPUT"`
84 #mv "$INPUT" "$INPUT.ps";INPUT="$INPUT.ps"
86 # create the pdf
87 $PS2PDF $OPTIONS "$INPUT" "$OUTPUT.pdf" >/dev/null 2>&1
88 mv -f "${OUTPUT}.pdf" "${FINALOUTPUT}".pdf
90 # Generate a message to send to the user, and deal with the original file:
91 MESSAGE=$(echo "Your PDF file has been created as $WIN_OUTPUT.pdf\n")
94 # Cleanup
95 if [ $KEEP_PS != 0 ];then
96 mv -f $INPUT "${FINALOUTPUT}".ps
97 MESSAGE=$(echo "$MESSAGE and your postscript file as $WIN_OUTPUT.ps")
98 # Fix permissions on the generated files
99 chmod $PERMS "${FINALOUTPUT}".ps "${FINALOUTPUT}".pdf
100 else
101 rm -f $INPUT
102 # Fix permissions on the generated files
103 chmod $PERMS "${FINALOUTPUT}".pdf
106 #Remove empty file from mktemp:
107 rm -f $OUTPUT
109 # Send notification to user
110 echo -e $MESSAGE|smbclient -M $4 -I $5 -U "PDF Generator" >/dev/null 2>&1