1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#!/bin/bash
#!/bin/sh
#
# Script to make drag and drop in KDE possible
#set -x
#
if [ $# -lt 2 ]
then
exit 0
fi
# Determine the temp directory
if [ -d "$TMPDIR" ] && [ -w "$TMPDIR" ]
then
tmp_dir=$TMPDIR
elif [ -d "$TEMP" ] && [ -w "$TEMP" ]
then
tmp_dir=$TEMP
else
tmp_dir="/tmp"
fi
# Try to create the temp files in a secure way
if [ -x /bin/tempfile ]
then
out_file=`/bin/tempfile -d "$tmp_dir" -p antiword -s ".ps"` || exit 1
err_file=`/bin/tempfile -d "$tmp_dir" -p antiword -s ".err"`
if [ $? -ne 0 ]
then
rm -f "$out_file"
exit 1
fi
elif [ -x /bin/mktemp ]
then
out_file=`/bin/mktemp -q -p "$tmp_dir" antiword.ps.XXXXXXXXX` || exit 1
err_file=`/bin/mktemp -q -p "$tmp_dir" antiword.err.XXXXXXXXX`
if [ $? -ne 0 ]
then
rm -f "$out_file"
exit 1
fi
else
# Creating the temp files in an un-secure way
out_file=$tmp_dir"/antiword.$$.ps"
err_file=$tmp_dir"/antiword.$$.err"
fi
# Determine the paper size
paper_size=$1
shift
# Make the PostScript file
antiword -p $paper_size -i 0 "$@" 2>"$err_file" >"$out_file"
if [ $? -ne 0 ]
then
# Something went wrong
if [ -r "$err_file" ] && [ -s "$err_file" ]
then
konsole --caption "Error from Antword" -e less "$err_file"
fi
# Clean up
rm -f "$out_file" "$err_file"
exit 1
fi
# Show the PostScript file
gv "$out_file" -nocentre -media $paper_size
# Clean up
rm -f "$out_file" "$err_file"
exit 0
|