--- /dev/null
+#!/bin/bash
+
+
+set -e
+set -u
+
+VERSION="0.4.1"
+MY_BASE=$(basename "${0}")
+
+#--------------------------------------------
+usage() {
+ cat <<EOF
+Usage: ${0} [-d|--debug] [-v|--verbose] [-t|--test] [-r|--replace] <IMAGE_FILE> [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
+}
+
+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"
+replace="n"
+
+set +e
+TEMP=$( getopt -o dvtrhV --long debug,verbose,simulate,replace,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
+ ;;
+ -r|--replace)
+ replace="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
+ exit 1
+fi
+
+IMAGE_FILE="${1}"
+shift
+
+if type -t rdjpgcom >/dev/null ; then
+ :
+else
+ cat >&2 <<-EOF
+ Executable rdjpgcom not found.
+
+ Please install package libjpeg-progs (Debian/Ubuntu) or media-libs/libjpeg-turbo (Gentoo).
+
+ EOF
+ exit 5
+fi
+
+if [[ ! -f "${IMAGE_FILE}" ]] ; then
+ echo -e "File '${IMAGE_FILE}' not found.\n" >&2
+ usage >&2
+ exit 1
+fi
+
+OLD_PERMS=$(stat -c "%a" "${IMAGE_FILE}")
+
+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="$*"
+
+TMP_FILE=
+if [[ "${simulate}" = "n" ]] ; then
+ TMP_FILE=$( mktemp -t image.XXXXXXXXXX.jpg )
+fi
+
+#------------------------------------------------------------------------------
+cleanup() {
+ if [[ -z "${TMP_FILE}" ]] ; then
+ return 0
+ fi
+ if [[ -f "${TMP_FILE}" ]] ; then
+ if "${verbose}" = "y" ]] ; then
+ rm -vf "${TMP_FILE}" || true
+ else
+ rm -f "${TMP_FILE}" || true
+ fi
+ fi
+}
+
+trap "cleanup; exit 8" INT TERM EXIT
+
+if [[ "${replace}" = "y" ]] ; then
+ echo "Replacing comment in '${IMAGE_FILE}' to '${NEW_COMMENT}' ..."
+ if [[ "${simulate}" = "n" ]] ; then
+ wrjpgcom -replace -comment "${NEW_COMMENT}" "${IMAGE_FILE}" > "${TMP_FILE}"
+ fi
+else
+ echo "Adding comment '${NEW_COMMENT}' to '${IMAGE_FILE}' ..."
+ if [[ "${simulate}" = "n" ]] ; then
+ wrjpgcom -comment "${NEW_COMMENT}" "${IMAGE_FILE}" > "${TMP_FILE}"
+ fi
+fi
+
+if [[ "${verbose}" = "y" ]] ; then
+ echo "Moving generated file ..."
+ if [[ "${simulate}" = "n" ]] ; then
+ mv -v "${TMP_FILE}" "${IMAGE_FILE}"
+ fi
+else
+ if [[ "${simulate}" = "n" ]] ; then
+ mv "${TMP_FILE}" "${IMAGE_FILE}"
+ fi
+fi
+
+if [[ "${verbose}" = "y" ]] ; then
+ echo "Applying old permissions '${OLD_PERMS}' to '${IMAGE_FILE}' ..."
+ if [[ "${simulate}" = "n" ]] ; then
+ chmod -v ${OLD_PERMS} "${IMAGE_FILE}"
+ fi
+else
+ if [[ "${simulate}" = "n" ]] ; then
+ chmod ${OLD_PERMS} "${IMAGE_FILE}"
+ fi
+fi
+
+if [[ "${verbose}" = "y" ]] ; then
+ echo "Adjusting permissions of '${IMAGE_FILE}' ..."
+ if [[ "${simulate}" = "n" ]] ; then
+ chmod -v a-x "${IMAGE_FILE}"
+ fi
+else
+ if [[ "${simulate}" = "n" ]] ; then
+ chmod a-x "${IMAGE_FILE}"
+ fi
+fi
+
+if [[ "${verbose}" = "y" ]] ; then
+ echo "Setting timestamp ..."
+ if [[ "${simulate}" = "n" ]] ; then
+ jhead -ft "${IMAGE_FILE}"
+ fi
+else
+ jhead -ft -q "${IMAGE_FILE}"
+fi
+
+trap - INT TERM EXIT
+cleanup
+
+exit 0
+
+
+# vim: et ts=4 softtabstop
+++ /dev/null
-#!/bin/bash
-
-
-set -e
-set -u
-
-VERSION="0.4.1"
-MY_BASE=$(basename "${0}")
-
-#--------------------------------------------
-usage() {
- cat <<EOF
-Usage: ${0} [-d|--debug] [-v|--verbose] [-t|--test] [-r|--replace] <IMAGE_FILE> [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
-}
-
-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"
-replace="n"
-
-set +e
-TEMP=$( getopt -o dvtrhV --long debug,verbose,simulate,replace,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
- ;;
- -r|--replace)
- replace="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
- exit 1
-fi
-
-IMAGE_FILE="${1}"
-shift
-
-if type -t rdjpgcom >/dev/null ; then
- :
-else
- cat >&2 <<-EOF
- Executable rdjpgcom not found.
-
- Please install package libjpeg-progs (Debian/Ubuntu) or media-libs/libjpeg-turbo (Gentoo).
-
- EOF
- exit 5
-fi
-
-if [[ ! -f "${IMAGE_FILE}" ]] ; then
- echo -e "File '${IMAGE_FILE}' not found.\n" >&2
- usage >&2
- exit 1
-fi
-
-OLD_PERMS=$(stat -c "%a" "${IMAGE_FILE}")
-
-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="$*"
-
-TMP_FILE=
-if [[ "${simulate}" = "n" ]] ; then
- TMP_FILE=$( mktemp -t image.XXXXXXXXXX.jpg )
-fi
-
-#------------------------------------------------------------------------------
-cleanup() {
- if [[ -z "${TMP_FILE}" ]] ; then
- return 0
- fi
- if [[ -f "${TMP_FILE}" ]] ; then
- if "${verbose}" = "y" ]] ; then
- rm -vf "${TMP_FILE}" || true
- else
- rm -f "${TMP_FILE}" || true
- fi
- fi
-}
-
-trap "cleanup; exit 8" INT TERM EXIT
-
-if [[ "${replace}" = "y" ]] ; then
- echo "Replacing comment in '${IMAGE_FILE}' to '${NEW_COMMENT}' ..."
- if [[ "${simulate}" = "n" ]] ; then
- wrjpgcom -replace -comment "${NEW_COMMENT}" "${IMAGE_FILE}" > "${TMP_FILE}"
- fi
-else
- echo "Adding comment '${NEW_COMMENT}' to '${IMAGE_FILE}' ..."
- if [[ "${simulate}" = "n" ]] ; then
- wrjpgcom -comment "${NEW_COMMENT}" "${IMAGE_FILE}" > "${TMP_FILE}"
- fi
-fi
-
-if [[ "${verbose}" = "y" ]] ; then
- echo "Moving generated file ..."
- if [[ "${simulate}" = "n" ]] ; then
- mv -v "${TMP_FILE}" "${IMAGE_FILE}"
- fi
-else
- if [[ "${simulate}" = "n" ]] ; then
- mv "${TMP_FILE}" "${IMAGE_FILE}"
- fi
-fi
-
-if [[ "${verbose}" = "y" ]] ; then
- echo "Applying old permissions '${OLD_PERMS}' to '${IMAGE_FILE}' ..."
- if [[ "${simulate}" = "n" ]] ; then
- chmod -v ${OLD_PERMS} "${IMAGE_FILE}"
- fi
-else
- if [[ "${simulate}" = "n" ]] ; then
- chmod ${OLD_PERMS} "${IMAGE_FILE}"
- fi
-fi
-
-if [[ "${verbose}" = "y" ]] ; then
- echo "Adjusting permissions of '${IMAGE_FILE}' ..."
- if [[ "${simulate}" = "n" ]] ; then
- chmod -v a-x "${IMAGE_FILE}"
- fi
-else
- if [[ "${simulate}" = "n" ]] ; then
- chmod a-x "${IMAGE_FILE}"
- fi
-fi
-
-if [[ "${verbose}" = "y" ]] ; then
- echo "Setting timestamp ..."
- if [[ "${simulate}" = "n" ]] ; then
- jhead -ft "${IMAGE_FILE}"
- fi
-else
- jhead -ft -q "${IMAGE_FILE}"
-fi
-
-trap - INT TERM EXIT
-cleanup
-
-exit 0
-
-
-# vim: et ts=4 softtabstop