pdf2archive icon indicating copy to clipboard operation
pdf2archive copied to clipboard

Compatibility with pure SH

Open chereskata opened this issue 2 years ago • 0 comments

Hello,

i have made some adjustments to run this nice helper program in every SH compatible shell:

--- .local/bin/pdf2archive.orig
+++ .local/bin/pdf2archive
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/usr/bin/env sh
 
 # PDF2ARCHIVE 0.3.2
 # (C) 2018 Matteo Seclì <[email protected]>

@@ -263,7 +241,7 @@
 [ -z ${PDFTRAPPED+x} ] && PDFTRAPPED=$(echo "$METADUMP" | grep "__knowninfoTrap
ped: " | sed "s/^__knowninfoTrapped: //g")
 # Replace "Trapped" string, if not empty, with an operator. Fixes 3Heights.
 if [ "$PDFTRAPPED" != "" ]; then
-  PDFTRAPPED="/$(tr '[:lower:]' '[:upper:]' <<< ${PDFTRAPPED:0:1})$(tr '[:upper:]' '[:lower:]' <<< ${PDFTRAPPED:1})"
+  PDFTRAPPED="/$(echo ${PDFTRAPPED:0:1} | tr '[:lower:]' '[:upper:]')$(echo ${PDFTRAPPED:1} | tr '[:upper:]' '[:lower:]')"
 fi
 # Check if the operator is allowed, otherwise empty variable.
 if [ "$PDFTRAPPED" != "/True" ] && [ "$PDFTRAPPED" != "/False" ]; then

Additionally as i run an apparmor profile, it would be easier to allow one single /tmp/ghostscript directory for rw:

@@ -216,8 +190,12 @@
 if [ "$OUTPUT" == "" ]; then
     OUTPUT="${INPUT%.pdf}-PDFA.pdf"
 fi
-TMPDIR=$(mktemp -d)
-TMPDIR=$(mktemp -d)
+if [ ! -d /tmp/ghostscript ]; then
+    mkdir /tmp/ghostscript
+fi
+TMPDIR=/tmp/ghostscript
+TMPFILE=$TMPDIR/tmp.pdf
 PSTMPFILE=$TMPDIR/PDFA_def.ps
 ICCTMPFILE=$TMPDIR/AdobeRGB1998.icc

Use as you like and thank you for your work

chereskata avatar Dec 08 '22 15:12 chereskata