From: Gustav Eek Date: Wed, 13 May 2020 11:29:21 +0000 (+0200) Subject: [unoconv-display] Inital on PDF conversion from email X-Git-Url: https://git.g-eek.se/?a=commitdiff_plain;h=0e9ba1bac9bc13f942f810d08e5b893dcdb197b6;p=users%2Fgustav%2Fscripts.git [unoconv-display] Inital on PDF conversion from email --- diff --git a/Makefile b/Makefile index 1f707f9..089208e 100644 --- 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 index 0000000..25fa465 --- /dev/null +++ b/unoconv-display @@ -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