]> git.g-eek.se Git - users/gustav/scripts.git/commitdiff
[unoconv-display] Inital on PDF conversion from email
authorGustav Eek <gustav.eek@fripost.org>
Wed, 13 May 2020 11:29:21 +0000 (13:29 +0200)
committerGustav Eek <gustav.eek@fripost.org>
Wed, 13 May 2020 11:29:21 +0000 (13:29 +0200)
Makefile
unoconv-display [new file with mode: 0644]

index 1f707f9f83ddf4fc1be619f2ea915c3d37ad8a36..089208e82564206b1c39da45218def4513c1cf64 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ json2yaml \
 yaml2json \
 ip-check \
 folkets \
-
+unoconv-display \
 
 bash-completion = \
 repo-encrypt \
diff --git a/unoconv-display b/unoconv-display
new file mode 100644 (file)
index 0000000..25fa465
--- /dev/null
@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+
+# -*- mode: shell-script -*-
+
+# Convert to PDF and display a libreoffice compatible document read
+# file on command line or else on stdandard in
+
+DEBUG=1
+
+C="$HOME/.cache/unoconv-display"
+tmp="/tmp/${0##*/}"
+mkdir -p "$C" "$tmp"
+test -n "$DEBUG" &&\
+    echo "[$(date -Is)] ${0##*/} D: Start." >> $tmp/log
+file=$1
+if [ -z "$file" ]; then
+    file="$tmp/$$"
+    cat > "$file"
+fi
+sha=$(sha1sum "$file");
+pdf="$C/${sha:0:16}.pdf"
+
+test -n "$DEBUG" &&\
+    echo "[$(date -Is)] ${0##*/} D: Continue for '$tmp', '$file', '$pdf'." >> $tmp/log
+
+if [ -f "$pdf" ]; then # Start PDF viewer
+    test -n "$DEBUG" &&\
+        echo "[$(date -Is)] ${0##*/} D: Found '$pdf'. Start PDF viewer." >> $tmp/log
+    exec zathura --fork "$pdf" 2>> "/tmp/err" &
+    rm -f "$tmp/$$"
+    exit 0
+fi
+
+test -n "$DEBUG" &&\
+    echo "[$(date -Is)] ${0##*/} D: Convert '$file' to '$pdf'." >> $tmp/log
+
+# Convert to PDF
+unoconv -f pdf -o "$pdf" "$file" || \
+    unoconv -l && \
+        unoconv -f pdf -o "$pdf" "$file"
+
+if [ -f "$pdf" ]; then # Recursively start evince
+    test -n "$DEBUG" &&\
+        echo "[$(date -Is)] [$(date -Is)] ${0##*/} D: Recursively for '$file'." >> $tmp/log
+    bash ${0} "$file"
+    exit $?
+fi
+
+echo "[$(date -Is)] [$(date -Is)] ${0##*/} E: Error. Why are we here?" >> $tmp/log
+exit 1