From aaa114c42614d9a5cdfd6d36be065077c6e9c772 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 28 Sep 2015 12:20:44 +0200 Subject: [PATCH] Added display of current comments in set-jpeg-comment.sh --- set-jpeg-comment.sh | 50 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/set-jpeg-comment.sh b/set-jpeg-comment.sh index 4c2b68c..cd88587 100755 --- a/set-jpeg-comment.sh +++ b/set-jpeg-comment.sh @@ -4,16 +4,23 @@ set -e set -u -VERSION="0.2.0" +VERSION="0.3.0" MY_BASE=$(basename "${0}") #-------------------------------------------- usage() { cat < [COMMENT] +Usage: ${0} [-d|--debug] [-v|--verbose] [-t|--test] [-r|--replace] [COMMENT] ${0} {-h|--help} ${0} {-V|--version} +Options: + -d|--debug debug output (bash -x) + -v|--verbose Set verbosity on. + -t|--test test (simulation) mode - comment will not be applied + -h|--help show this output and exit + -V|--version prints out version number of the script and exit + EOF } @@ -30,9 +37,10 @@ print_file() { debug="n" verbose="n" simulate="n" +replace="n" set +e -TEMP=$( getopt -o dvthV --long debug,verbose,simulate,test,help,version -n "${MY_BASE}" -- "$@" ) +TEMP=$( getopt -o dvtrhV --long debug,verbose,simulate,replace,test,help,version -n "${MY_BASE}" -- "$@" ) if [[ $? != 0 ]] ; then echo "" >&2 usage >&2 @@ -57,6 +65,10 @@ while true ; do simulate="y" shift ;; + -r|--replace) + replace="y" + shift + ;; -h|--help) usage exit 0 @@ -112,5 +124,37 @@ trap "print_file; exit 1" INT TERM EXIT CUR_COMMENT=$( rdjpgcom "${IMAGE_FILE}" ) trap - INT TERM EXIT +show_old="n" +if [[ "$#" -lt 1 || "${verbose}" = "y" ]] ; then + show_old="y" +fi + +if [[ "${show_old}" = "y" ]] ; then + if [[ -n "${CUR_COMMENT}" ]] ; then + echo "Current JPEG comment in '${IMAGE_FILE}': ${CUR_COMMENT}" + else + echo "File '${IMAGE_FILE}' has no JPEG comment." + fi +fi + +if [[ "$#" -lt 1 ]] ; then + exit 0 +fi + +if type -t jhead >/dev/null ; then + : +else + cat >&2 <<-EOF + Executable jhead not found. + + Please install package jhead (Debian/Ubuntu) or media-gfx/jhead (Gentoo). + + EOF + exit 5 +fi + +NEW_COMMENT="$*" + + # vim: et ts=4 softtabstop -- 2.39.5