Hello! I finally figured what was going wrong with my script.<br><br><br>Jonas, I have tried implementing your suggestions. using mktemp, XXXXX, and also a -m 077. The code doesnt work for some reason that way. lpr gets me a failed job. Also that code is basically ported from this guide,<br>
<a href="http://www.ibm.com/developerworks/linux/library/l-dvi-filter.html">http://www.ibm.com/developerworks/linux/library/l-dvi-filter.html</a><br><br>Jonas, Silbe, notice this<br><br>[Vamsi@localhost Desktop]$ $(abiword --to=ps /home/Vamsi/lololo.odt); if [ $? -ne 0 ]; then echo 'hello'; else echo 'what'; fi<br>
hello <br>[Vamsi@localhost Desktop]$ $(abiword --to=doc /home/Vamsi/lololo.odt); if [ $? -ne 0 ]; then echo 'hello'; else echo 'what'; fi<br>
what <br>[Vamsi@localhost Desktop]$ $(set -e abiword --to=doc /home/Vamsi/lololo.odt); if [ $? -ne 0 ]; then echo 'hello'; else echo 'what'; fi<br>
what <br>[Vamsi@localhost Desktop]$ $(set -e abiword --to=ps /home/Vamsi/lololo.odt); if [ $? -ne 0 ]; then echo 'hello'; else echo 'what'; fi<br>
what <br>[Vamsi@localhost Desktop]$ $(abiword --to=ps /home/Vamsi/lololo.odt); if [ $? -ne 0 ]; then echo 'hello'; else echo 'what'; fi<br>
hello <br>[Vamsi@localhost Desktop]$ $(abiword --to=ps /home/Vamsi/lololo.odt); if [ $? -ne 0 ]; then echo 'hello'; else echo 'what'; fi<br>
hello <br><br>Set -e basically yields me the same case, that is even on an error it returns me a 0. But without set -e , it works great.<br><br><br>Moving on,<br><br>Its like this,<br><br>The lp user of lp group ( cups script executor) messes up with permissions when executing commands in a subshell, that's really messed up. my rationale is, in a subshell the lp user has no longer domain. Also, CUPS doesnt write to our /tmp folder, instead has its own folder defined somewhere.<br>
So what I made is,<br><br style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 51);"><span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 51);">sandbox1="${TMPDIR1:-/</span>tmp<span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 51);">}/</span>tempcups<span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 51);">.$$$$"</span><br style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 51);">
<span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 51);">
(</span>umask<span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 51);"> 077 && </span>mkdir<span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 51);"> "$sandbox1") || exit 1</span><br>
<br>I made another temp folder for the subshells to execute their commands<br><br><br>And, andres, it initially does try to convert to doc.<br><br><br>The algorithm is pretty much like this,<br><br>1) We try to write to some new path besides the same folder, if it works, we are running 2.6.6 and plus, if not we are on 2.6.6--<br>
- We cannot check for ~<a href="http://somepath.ps">somepath.ps</a> here as 2.6.8 doesnt have that capability, so that would be inviting a hole as we would be skipping for 2.6.8 as well!<br><br># $fn happens to be supplied variable<br>
<span style="background-color: rgb(255, 255, 0);">$(</span>abiword<span style="background-color: rgb(255, 255, 0);"> --to=$sandbox1/temp123.doc $</span>fn<span style="background-color: rgb(255, 255, 0);">)</span><br style="background-color: rgb(255, 255, 0);">
<br># if this doesnt work, do the following, as 2.6.6- could only do operations in the same folder,<br># we are copying ;)<br><span style="background-color: rgb(255, 255, 0);">if [ "$?" -</span>ne<span style="background-color: rgb(255, 255, 0);"> 0 ]; </span><br style="background-color: rgb(255, 255, 0);">
<span style="background-color: rgb(255, 255, 0);">then</span><br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);">#our dummy file</span><br style="background-color: rgb(255, 255, 0);">
<span style="background-color: rgb(255, 255, 0);">fn1="$sandbox/temp123.</span>odt<span style="background-color: rgb(255, 255, 0);">"</span><br style="background-color: rgb(255, 255, 0);">cp<span style="background-color: rgb(255, 255, 0);"> "$</span>fn<span style="background-color: rgb(255, 255, 0);">" "$fn1"</span><br style="background-color: rgb(255, 255, 0);">
<br style="background-color: rgb(255, 255, 0);"><br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);"># Call </span>abiword<span style="background-color: rgb(255, 255, 0);"> quietly, securely </span><br style="background-color: rgb(255, 255, 0);">
abiword<span style="background-color: rgb(255, 255, 0);"> --to="</span>ps<span style="background-color: rgb(255, 255, 0);">" "`echo "$fn1" | </span>sed<span style="background-color: rgb(255, 255, 0);"> -e 's/</span>odt<span style="background-color: rgb(255, 255, 0);">$/doc/' `"</span><br style="background-color: rgb(255, 255, 0);">
<span style="background-color: rgb(255, 255, 0);">fn2="`echo "$fn1" | </span>sed<span style="background-color: rgb(255, 255, 0);"> -e 's/</span>odt<span style="background-color: rgb(255, 255, 0);">$/</span>ps<span style="background-color: rgb(255, 255, 0);">/' `"</span><br style="background-color: rgb(255, 255, 0);">
<br><br>2) Now we enter the case what if we are in fact on 2.6.6+, well now come two paths again, 1) are we 2.6.8, or 2) anything other than 2.6.8<br> (again 2.6.8 cant write to ps directly, we need an intermediate doc conversion for this effect)<br>
<br>
<span style="background-color: rgb(255, 255, 0);"># Call abiword quietly, securely </span><br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);">
#check if our version doesn't require an intermediate conversion, if it does, do it</span><br style="background-color: rgb(255, 255, 0);">
<br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);">
$(abiword --to="$sandbox1/<a href="http://temp123.ps">temp123.ps</a>" "$fn")</span><br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);">
if [ "$?" -ne 0 ];</span><br style="background-color: rgb(255, 255, 0);">
<br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);">
then</span><br style="background-color: rgb(255, 255, 0);">
<br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);">
abiword --to="$sandbox/temp123.doc" "$fn"</span><br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);">
abiword --to="$sandbox/<a href="http://temp123.ps">temp123.ps</a>" "$sandbox/temp123.doc"</span><br style="background-color: rgb(255, 255, 0);">
<br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);">
else</span><br style="background-color: rgb(255, 255, 0);">
<br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);">
#abiword --to="$sandbox/<a href="http://temp123.ps">temp123.ps</a>" "$fn"</span><br style="background-color: rgb(255, 255, 0);">
<br style="background-color: rgb(255, 255, 0);"><span style="background-color: rgb(255, 255, 0);">
fn2="$sandbox1/<a href="http://temp123.ps">temp123.ps</a>"</span><br style="background-color: rgb(255, 255, 0);">
<br style="background-color: rgb(255, 255, 0);">Andres, script works great for ALLL cases :D<br><br><br><br style="background-color: rgb(255, 255, 0);">#!/bin/bash<br># CUPS filter to process ODT files using abiword<br><br>
<br><br># $6 happens to be the path to file passed as argument for debugging purposes i am use $1<br>fn="$6"<br><br>#for our subshell convenience<br>sandbox1="${TMPDIR1:-/tmp}/tempcups.$$$$"<br>(umask 077 && mkdir "$sandbox1") || exit 1<br>
<br><br># we are creating a dummy folder, which can take different file types.<br>sandbox="${TMPDIR:-/tmp}/t6cups-odftops.$$$$"<br>(umask 077 && mkdir "$sandbox") || exit 1<br><br><br>#The condition which checks whether our abiword is 2.6.6+ or 2.6.6-<br>
<br>$(abiword --to="$sandbox1/temp123.doc" "$fn")<br><br>if [ "$?" -ne 0 ];<br>then<br><br>#our dummy file<br>fn1="$sandbox/temp123.odt"<br>cp "$fn" "$fn1"<br><br>
# Call abiword quietly, securely <br>abiword --to="ps" "`echo "$fn1" | sed -e 's/odt$/doc/' `"<br>fn2="`echo "$fn1" | sed -e 's/odt$/ps/' `"<br><br>else<br>
<br># Call abiword quietly, securely <br>#check if our version doesn't require an intermediate conversion, if it does, do it<br><br>$(abiword --to="$sandbox1/<a href="http://temp123.ps">temp123.ps</a>" "$fn")<br>
if [ "$?" -ne 0 ];<br><br>then<br><br>abiword --to="$sandbox/temp123.doc" "$fn"<br>abiword --to="$sandbox/<a href="http://temp123.ps">temp123.ps</a>" "$sandbox/temp123.doc"<br>
<br>else<br><br>#abiword --to="$sandbox/<a href="http://temp123.ps">temp123.ps</a>" "$fn"<br><br>fn2="$sandbox1/<a href="http://temp123.ps">temp123.ps</a>"<br><br>fi<br><br>fi<br><br>cat "$fn2"<br>
<br>#remove the sandbox folder, for debugging purposes check by commenting the following line and see what is in the /tmp/ folder<br>#rm -rf $sandbox<br>#rm -rf $sandbox1<br><br>