set -e
set -u
-VERSION="0.3.0"
+VERSION="0.4.0"
MY_BASE=$(basename "${0}")
#--------------------------------------------
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
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
+ if [[ "${verbose}" = "y" ]] ; then
+ echo "Replacing comment in '${IMAGE_FILE}' ..."
+ fi
+ if [[ "${simulate}" = "n" ]] ; then
+ wrjpgcom -replace -comment "${NEW_COMMENT}" "${IMAGE_FILE}" > "${TMP_FILE}"
+ fi
+else
+ if [[ "${verbose}" = "y" ]] ; then
+ echo "Adding comment to '${IMAGE_FILE}' ..."
+ fi
+ 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