From 014d4f89efac02014652ec99f7f516d3b6b2c3b3 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 28 Sep 2015 12:03:32 +0200 Subject: [PATCH] Added command line parameters to set-jpeg-comment.sh --- set-jpeg-comment.sh | 77 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/set-jpeg-comment.sh b/set-jpeg-comment.sh index 074bc68..4c2b68c 100755 --- a/set-jpeg-comment.sh +++ b/set-jpeg-comment.sh @@ -4,14 +4,83 @@ set -e set -u +VERSION="0.2.0" +MY_BASE=$(basename "${0}") +#-------------------------------------------- usage() { cat < [COMMENT] +Usage: ${0} [-d] [-v] [-t] [COMMENT] + ${0} {-h|--help} + ${0} {-V|--version} EOF } +IMAGE_FILE= + +#-------------------------------------------- +print_file() { + if [[ -n "${IMAGE_FILE}" ]] ; then + printf "%s: not applicable.\n\n" "${IMAGE_FILE}" >&2 + fi +} + +#-------------------------------------------- +debug="n" +verbose="n" +simulate="n" + +set +e +TEMP=$( getopt -o dvthV --long debug,verbose,simulate,test,help,version -n "${MY_BASE}" -- "$@" ) +if [[ $? != 0 ]] ; then + echo "" >&2 + usage >&2 + exit 1 +fi +set -e + +# Note the quotes around `$TEMP': they are essential! +eval set -- "$TEMP" + +while true ; do + case "$1" in + -d|--debug) + debug="y" + shift + ;; + -v|--verbose) + verbose="y" + shift + ;; + -t|--test|--simulate) + simulate="y" + shift + ;; + -h|--help) + usage + exit 0 + ;; + -V|--version) + echo "${MY_BASE} version: ${VERSION}" + exit 0 + ;; + --) shift + break + ;; + *) echo "Unknown parameter '${1}'" >&2 + usage >&2 + exit 1 + ;; + esac +done + +if [[ "${debug}" = "y" ]] ; then + set -x +fi + + +#-------------------------------------------- if [[ "$#" -lt 1 ]] ; then echo -e "No image file given.\n" >&2 usage >&2 @@ -25,7 +94,7 @@ if type -t rdjpgcom >/dev/null ; then : else cat >&2 <<-EOF - Executable rdjpgcom not found. + Executable rdjpgcom not found. Please install package libjpeg-progs (Debian/Ubuntu) or media-libs/libjpeg-turbo (Gentoo). @@ -39,5 +108,9 @@ if [[ ! -f "${IMAGE_FILE}" ]] ; then exit 1 fi +trap "print_file; exit 1" INT TERM EXIT +CUR_COMMENT=$( rdjpgcom "${IMAGE_FILE}" ) +trap - INT TERM EXIT + # vim: et ts=4 softtabstop -- 2.39.5