WIP#2
[llpp.git] / llppac
blob7739ae54464b46bb26a46e7548cf32c03c3c3dbd
1 #!/bin/sh
3 set -e
5 CACHEDIR=$HOME/.config/llpp
7 die()
9 fmt=$1
10 shift
11 printf "$fmt\n" "$*" >&2
12 exit 1
15 executable_p() {
16 command -v $1 >/dev/null 2>&1
19 trap '! test -z $casp && rm -f $casp' 0
21 test -d $CACHEDIR || die "cache directory %s does not exist" $CACHEDIR
22 test -z "$1" && die "usage %s: path" $0
24 ft=$(file --mime-type -b "$1")
26 case $ft in
27 application/x-gzip) dc=zcat;;
28 application/x-xz) dc=xzcat;;
29 application/x-bzip2) dc=bzcat;;
30 *) unset dc;;
31 esac
33 test -z $dc || ft=$(file --mime-type -bz "$1")
35 case $ft in
36 application/postscript) conv='ps2pdf - $casp';;
37 application/pdf) test -z $dc && exec llpp "$1" || conv='cat >$casp';;
38 image/vnd.djvu) conv='djvups - | ps2pdf - $casp';;
39 application/msword) conv='antiword -m 8859-1.txt -a a4 - >$casp';;
40 image/svg+xml) {
41 executable_p rsvg-convert \
42 && conv='rsvg-convert -f pdf -o $casp' \
43 || conv='inkscape -z -A $casp -'
44 };;
45 application/x-dvi) {
46 test -z $dc || die "can not handle compressed DVIs"
47 conv='dvipdf - $casp'
48 };;
49 *) die "unhandled file type: %s" $ft;;
50 esac
52 hash=$(md5sum "$1" | cut -f 1 -d\ )
53 casp="$CACHEDIR/$hash"
54 test -e $casp ||
55 eval "${dc-cat} \"$1\" | $conv"
57 exec llpp -origin "$1" $casp