Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| shellscripts:samba-print-pdf [2006/11/17 21:29] – st | shellscripts:samba-print-pdf [2006/12/02 19:14] (aktuell) – st | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | ====== PDF printing mit Samba ====== | ||
| + | Erstellt einen virtuellen PDF-Drucker auf dem [[Samba: | ||
| + | Aus: | ||
| + | PDF Hacks (O' | ||
| + | |||
| + | ===== Code ===== | ||
| + | <code bash> | ||
| + | |||
| + | #!/bin/bash | ||
| + | # samba-print-pdf | ||
| + | # This is a script which allows you to set up a virtual printer on samba | ||
| + | # which will take the file (generated by a postscript filter on windows) | ||
| + | # and turn it into a PDF, informing the user of where it is when it | ||
| + | # is done | ||
| + | # | ||
| + | # (c) Buchan Milne < | ||
| + | # License: GPLv2 | ||
| + | # Changelog | ||
| + | # v0.0.6 20030428 | ||
| + | # - Allow options passed as env. variables from print command | ||
| + | # - Inline and simplify sed (use tr) clean script | ||
| + | # - Ensure file arrives in PREFIX even if TEMP is used without provided name | ||
| + | # - Changes from Joshua M. Schmidlkofer < | ||
| + | # - Debugging, adjustments, | ||
| + | # - Stupid sed sanitizing script. [probably horribly inefficient also]. | ||
| + | # - Temp file usage cleanup. | ||
| + | # v0.0.5 20020723 | ||
| + | # - Add support for preset settings | ||
| + | # - Allow passing of filename provided by client as final filename | ||
| + | # | ||
| + | # Arguments: | ||
| + | # $1 = file (usually passed with %s from samba) | ||
| + | # $2 = unix prefix to where to place the file (~%u should work) | ||
| + | # $3 = windows prefix to the same location (//%L/%u should work) | ||
| + | # $4 = user/ | ||
| + | # $5 = IP address of client (%I) | ||
| + | # $6 = Name of destination file without extension (%J) | ||
| + | # $7 = PDF setting (prepress, | ||
| + | # | ||
| + | # If you want to customise any of the following configuration defaults, | ||
| + | # you can place them in the file / | ||
| + | # If you need to modify anything in this script, please provide me with your | ||
| + | # changes, preferably in such a way that the changes are configurable. | ||
| + | |||
| + | PS2PDF=ps2pdf13 | ||
| + | OPTIONS=" | ||
| + | #Values taken from arguments: | ||
| + | INPUT=$1 | ||
| + | PREFIX=" | ||
| + | WINBASE=$(echo " | ||
| + | #NAME=`echo " | ||
| + | NAME=`echo " | ||
| + | |||
| + | # Source config file if it exists: | ||
| + | CONFFILE=/ | ||
| + | [ -e $CONFFILE ] && . $CONFFILE | ||
| + | |||
| + | #Values not taken as arguments, could be set via env. vars (?) or config file | ||
| + | KEEP_PS=${KEEP_PS=0} | ||
| + | PERMS=${PERMS=640} | ||
| + | BASEFILE=${BASEFILE=pdf-service} | ||
| + | TEMP=" | ||
| + | UMASK=${UMASK=006} | ||
| + | |||
| + | #Make sure that destination directory exists | ||
| + | mkdir -p " | ||
| + | |||
| + | INFILE=$(basename $INPUT) | ||
| + | |||
| + | umask $UMASK | ||
| + | |||
| + | [ -n " | ||
| + | |||
| + | #make a temp file to use for the output of the PDF | ||
| + | OUTPUT=`mktemp -q $TEMP/ | ||
| + | if [ $? -ne 0 ]; then | ||
| + | echo "$0: Can't create temp file $TEMP/ | ||
| + | exit 1 | ||
| + | fi | ||
| + | if [ -n " | ||
| + | FINALOUTPUT=" | ||
| + | else | ||
| + | FINALOUTPUT=" | ||
| + | fi | ||
| + | if [ -n " | ||
| + | OPTIONS=" | ||
| + | else | ||
| + | OPTIONS=" | ||
| + | fi | ||
| + | |||
| + | WIN_OUTPUT=" | ||
| + | #mv " | ||
| + | |||
| + | # create the pdf | ||
| + | $PS2PDF $OPTIONS " | ||
| + | mv -f " | ||
| + | |||
| + | # Generate a message to send to the user, and deal with the original file: | ||
| + | MESSAGE=$(echo "Your PDF file has been created as $WIN_OUTPUT.pdf\n" | ||
| + | |||
| + | |||
| + | # Cleanup | ||
| + | if [ $KEEP_PS != 0 ];then | ||
| + | mv -f $INPUT " | ||
| + | MESSAGE=$(echo " | ||
| + | # Fix permissions on the generated files | ||
| + | chmod $PERMS " | ||
| + | else | ||
| + | rm -f $INPUT | ||
| + | # Fix permissions on the generated files | ||
| + | chmod $PERMS " | ||
| + | fi | ||
| + | | ||
| + | #Remove empty file from mktemp: | ||
| + | rm -f $OUTPUT | ||
| + | |||
| + | # Send notification to user | ||
| + | echo -e $MESSAGE|smbclient -M $4 -I $5 -U "PDF Generator" | ||
| + | |||
| + | </ | ||