#!/bin/bash LOG GEHT NICHT WEGEN NUTZERRECHTEN
#21/06/2007 by Mirco Piccin aka pictux - pictux@gmail.com
#if your works better (surely), please send me it!! :-)


LOGDIR=/tmp
LOGFILE=$LOGDIR/watermark_pdf.log

case $PRINTER in
 PDF)

MOVE=`which mv`
DEL=`which rm`
PDFTOOL=`which pdftk`
BASENM=`which basename`
CHMOD=`which chmod`
FILENAME=`$BASENM $3`
# US=`herbs`

echo `date` " - AD Bitchin : /usr/bin/pdftk /tmp/$FILENAME background $2 output $3" >> $LOGFILE 2>&1 
# echo "$5" >> $LOGFILE 2>&1

$CHMOD 0666 $3
# if [ "$5" == "herbs"]
# then
# echo "Hallo" >> $LOGFILE 2>&1 
# $MOVE $3 /home/herbs/$FILENAME
# fi
 ;;

PDF_ELIP)

if [ `echo $3 | grep -ce "\.[Pp][Dd][Ff]"` -le 0 ]
 then
 echo `date` " - ERR: This scripts accepts only PDF format as input file!!! ($3)" >> $LOGFILE 2>&1 
 exit 1
fi

if [ `echo $2 | grep -ce "\.[Pp][Dd][Ff]"` -le 0 ]
 then
 echo `date` " - ERR: Background/Watermark image must be in PDF format!!! ($2)" >> $LOGFILE 2>&1 
 exit 1
fi

MOVE=`which mv`
DEL=`which rm`
PDFTOOL=`which pdftk`
BASENM=`which basename`
CHMOD=`which chmod`
FILENAME=`$BASENM $3`

$MOVE $3 /tmp/$FILENAME

echo `date` " - Executing : /usr/bin/pdftk /tmp/$FILENAME background $2 output $3" >> $LOGFILE 2>&1

$PDFTOOL /tmp/$FILENAME background $2 output $3
$CHMOD 0666 $3
$CHMOD 0666 /tmp/$FILENAME
$DEL /tmp/$FILENAME
 ;;

PDF_ELIP_intern)

if [ `echo $3 | grep -ce "\.[Pp][Dd][Ff]"` -le 0 ]
 then
 echo `date` " - ERR: This scripts accepts only PDF format as input file!!! ($3)" >> $LOGFILE 2>&1 
 exit 1
fi

if [ `echo $2 | grep -ce "\.[Pp][Dd][Ff]"` -le 0 ]
 then
 echo `date` " - ERR: Background/Watermark image must be in PDF format!!! ($2)" >> $LOGFILE 2>&1 
 exit 1
fi

MOVE=`which mv`
DEL=`which rm`
PDFTOOL=`which pdftk`
BASENM=`which basename`
CHMOD=`which chmod`
FILENAME=`$BASENM $3`
INTERN="/usr/share/Briefpapier/elip_brief_intern.pdf"

$MOVE $3 /tmp/$FILENAME

echo `date` " - Executing : /usr/bin/pdftk /tmp/$FILENAME background $INTERN output $3" >> $LOGFILE 2>&1

$PDFTOOL /tmp/$FILENAME background $INTERN output $3
$CHMOD 0666 $3
$CHMOD 0666 /tmp/$FILENAME
$DEL /tmp/$FILENAME

;;
 *)
# nix
 ;;
esac