Introduction
Introduction Statistics Contact Development Disclaimer Help
Fixing tmpfile creation and exit codes in pointer filter. - annna - Annna the n…
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6…
Log
Files
Refs
Tags
README
---
commit d58bae51f639073fd9fbc75ac96893ef65882507
parent 9d1be8e467a5a5843922f2fd32230acada17de2a
Author: Annna Robert-Houdin <[email protected]>
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(-)
---
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
+
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.