Fixing tmpfile creation and exit codes in pointer filter. - annna - Annna the nice friendly bot.
HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/
DIR Log
DIR Files
DIR Refs
DIR Tags
DIR README
---
DIR commit d58bae51f639073fd9fbc75ac96893ef65882507
DIR parent 9d1be8e467a5a5843922f2fd32230acada17de2a
HTML Author: Annna Robert-Houdin <annna@bitreich.org>
Date: Sun, 19 Feb 2023 12:53:38 +0100
Fixing tmpfile creation and exit codes in pointer filter.
Diffstat:
M pointer | 64 ++++++++++++++++++++++---------
1 file changed, 46 insertions(+), 18 deletions(-)
---
DIR diff --git a/pointer b/pointer
@@ -1,33 +1,48 @@
#!/bin/sh
die() {
- printf '%s\n' "$1" >&2
+ [ -n "$1" ] && printf '%s\n' "$1" >&2
exit 1
}
-if test $# -ne 2; then
- die "usage: ${0##*/} <file> <outimagefile>"
-fi
+[ $# -ne 2 ] && die "usage: ${0##*/} <file> <outimagefile>"
mimetype="$(file -ib "$1")"
+rminfile=0
case "$mimetype" in
- video/*)
- in="$(mktemp).jpg"
- ffmpeg -i "$1" -frames:v 1 "$in";;
- image/png*)
- # imagemagick text draw on png files is broken,
- # tested on gentoo imagemagick version 7.1.0-48
- in="$(mktemp).jpg"
- convert "$1" "$in";;
- image/*)
- in="$1";;
- *)
- die "file type '${mimetype}' not supported";;
+video/*)
+ in="$(mktemp -u tmp.XXXXXXXX.jpg)"
+ ffmpeg -i "$1" -frames:v 1 "$in"
+ if [ $? -gt 0 ];
+ then
+ [ -e "${in}" ] && rm -f "${in}"
+ die
+ fi
+ rminfile=1
+ ;;
+image/png*)
+ # imagemagick text draw on png files is broken,
+ # tested on gentoo imagemagick version 7.1.0-48
+ in="$(mktemp tmp.XXXXXXXX.jpg)"
+ convert "$1" "$in"
+ if [ $? -gt 0 ];
+ then
+ rm "${in}"
+ die
+ fi
+ rminfile=1
+ ;;
+image/*)
+ in="$1"
+ ;;
+*)
+ die "file type '${mimetype}' not supported"
+ ;;
esac
n="${1##*/}"
n="${n%.*}"
-tmp="$(mktemp).jpg"
+tmp="$(mktemp tmp.XXXXXXXXX.jpg)"
convert \
\( \
+append \
@@ -41,4 +56,17 @@ convert \
-draw "text +10,+10 '${n}'" \
-gravity northeast \
-draw "text -422,+20 '*${n}'" \
- "$tmp" && mv "$tmp" "$2"
+ "$tmp"
+exitcode=$?
+if [ $exitcode -eq 0 ];
+then
+ cp "${tmp}" "$2"
+ chmod o+r "$2"
+fi
+
+# cleanup
+rm "${tmp}"
+[ $rminfile -eq 1 ] && rm "${in}"
+
+exit $exitcode
+