From 728997ff9662e6790165fd76296bef9ff8a09d93 Mon Sep 17 00:00:00 2001 From: FRIGN Date: Mon, 19 Sep 2016 19:07:27 +0200 Subject: 2ff: Make it idempotent and clean it up a bit If a file begins with "farbfeld", we just pass it through. --- 2ff | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/2ff b/2ff index 07c7d46..1b61cef 100755 --- a/2ff +++ b/2ff @@ -5,20 +5,32 @@ if [ "$#" -ne 0 ]; then fi TMP=$(mktemp) -cat > "$TMP"; +cat > "$TMP" -FORMAT=$(file -ib "$TMP" | cut -d ";" -f 1); +if [ "$(head -c 8 "$TMP")" = "farbfeld" ]; then + cat < "$TMP" + exit 0 +fi + +FORMAT=$(file -ib "$TMP" | cut -d ";" -f 1) case "$FORMAT" in - image/png) png2ff < "$TMP"; ret=$? ;; - image/jpeg) jpg2ff < "$TMP"; ret=$? ;; - *) convert "$TMP" png:- 2>/dev/null | png2ff 2>/dev/null; ret=$? ;; +image/png) + png2ff < "$TMP" + ;; +image/jpeg) + jpg2ff < "$TMP" + ;; +*) + convert "$TMP" png:- 2>/dev/null | png2ff 2>/dev/null + ;; esac -rm "$TMP"; +ret=$? +rm "$TMP" if [ $ret -ne 0 ]; then - printf "%s: failed to convert %s\n" "$0" "$FORMAT" >&2; + printf "%s: failed to convert from %s\n" "$0" "$FORMAT" >&2 fi -exit $ret; +exit $ret -- cgit v1.2.3