9 cachedir
="$HOME/.cache/llpp"
10 test -d "$cachedir" || die
"cache directory '$cachedir' does not exist"
15 executable_p
() { command -v "$1" >/dev
/null
2>&1; }
19 eval "$1() { die \"$2 is needed for \$type conversion\"; }"
21 trap 'test -n "${casp-}" && rm -f "$casp"' 0
23 while getopts s
:c
:m
:t
:fu opt
; do
29 ?
) die
"usage: $0 [-c css] [-m mime/type] [-t filter] [-f] [path|url]";;
32 shift $
(($OPTIND - 1))
33 test -z "$1" && die
"usage $0: path"
36 if ${force-test ! -e "$1"} && expr >/dev
/null
"$1" : "\(ftp\|https\?\)://";
38 if executable_p wget
; then
39 dl
() { wget
-q $1 -O $2; }
40 elif executable_p curl
; then
41 dl
() { curl
-L $1 -o $2; }
43 die
"no program to fetch remote urls found"
46 hashof
="$cachedir/$(basename "$1")"
47 dl
"$1" "$hashof" ||
test -e "$md5of"
55 ft
=$
(file -L --mime-type -b "$1") || die
"$ft";
58 application
/x-gzip | application
/x-compress
) dc=zcat
;;
59 application
/x-xz
) dc=xzcat
;;
60 application
/x-bzip2
) dc=bzcat
;;
65 filt
='"${dc-cat}" "$1" |'
69 application
/postscript
) type=ps
;;
70 application
/pdf
) type=pdf
;;
71 image
/vnd.djvu
) type=djvu
;;
72 text
/html
) type=html
;;
73 text
/plain
) type=text
;;
74 application
/msword
) type=word
;;
75 application
/vnd.openxmlformats-officedocument.
* \
76 | application
/vnd.ms-powerpoint \
77 | application
/vnd.ms-excel \
78 | application
/vnd.oasis.opendocument.
*) type=uno
;;
79 image
/svg
+xml
) type=svg
;;
80 image
/png | image
/jpeg
)
81 test -n "${dc-}" && type="image" ||
type="image2";;
83 application
/x-dvi
) type=dvi
;;
89 if test -z "$type"; then
90 test -z "${mime-}" && \
91 mime
=$
(file -L --mime-type -b "$1" || die
"$mime") || \
92 $
(file -L --mime-type -bz "$1" || die
"$mime")
93 typeofmime
"$mime" || die
"unhandled file type: '$mime'"
99 missing ps2pdf
"ps2df(https://ghostscript.com/)"
100 conv
='ps2pdf - "$casp"'
102 image2|pdf
) test -z "${dc-}" && exec llpp
"$@" || conv
='cat >"$casp"';;
104 missing texi2html
"texi2html(http://www.nongnu.org/texi2html/)"
105 conv
='texi2html - -o $casp'
109 missing ddjvu
"ddjvu(http://djvu.sourceforge.net/doc/man/ddjvu.html)"
110 conv
='ddjvu -format=pdf - "$casp"'
113 missing prince
"Prince(http://www.princexml.com/)"
114 conv
='prince $css - -o "$casp"'
117 missing pandoc
"pandoc(http://pandoc.org)"
119 conv
='pandoc -r html - -w epub2 -o "$casp"'
122 missing unoconv
"unoconv"
124 conv
='unoconv -o "$casp" "$1"'
127 test -n "$dc" && die
"cannot convert compressed '$mime'"
129 missing unoconv
"unoconv(http://dag.wiee.rs/home-made/unoconv/)"
130 conv
='unoconv -o "$casp" "$1"'
133 if executable_p inkscape
&& test -z "$dc"; then
135 conv
='inkscape -z -A "$casp" "$1"'
137 if executable_p rsvg-convert
; then
138 conv
='rsvg-convert -f pdf -o "$casp"'
140 test -n "$dc" && die
"cannot convert compressed '$mime'"
142 missing unoconv
"unoconv(http://dag.wiee.rs/home-made/unoconv/)"
143 conv
='unoconv -o "$casp" "$1"'
148 missing convert
"convert(http://www.imagemagick.org/script/convert.php)"
149 conv
='convert - pdf:"$casp"'
152 test -n "$dc" && die
"cannot convert compressed '$mime'"
154 missing dvipdf
"dvipdf(http://ghostscript.com/)"
155 conv
='dvipdf "$1" "$casp"'
158 missing pandoc
"pandoc(http://pandoc.org/)"
159 conv
='pandoc -t epub2 - -o "$casp"'
162 *) die
"unhandled filter type: '$type'";;
165 hash=$
(cksum "$hashof") || die
"$hash"
166 casp
=$cachedir/${hash%% *}$caspsuf
168 { test -n "${force-}" ||
test ! -e "$casp"; } && eval "$filt" "$conv"
171 exec llpp
-origin $origin "$@" "$casp"