#!/bin/bash

############################################################################################
#
# sbwg-describe Adds, edits or prints the SBWG description (XMP tag) to a file that will be
#               used as an attachment file to a SBWG entry.
# Version:      0.0.2
# Last edited:  2022-10-09
#
############################################################################################

scriptdir="$(readlink -f "${BASH_SOURCE[0]%/*}")"

case ${#} in

	1) exiftool -config "${scriptdir}"/exiftool.config -XMP:SBWG_Description -short3 "${1}" && exit 2 ;;

	2) exiftool -config "${scriptdir}"/exiftool.config -XMP:SBWG_Description="${2}" -overwrite_original "${1}" ;;

	*) printf 'Usage: %s FILENAME [DESCRIPTION_STRING]\n' "${BASH_SOURCE[0]}"; exit 1 ;;

esac

############################################################################################
#
# Exit codes:
#
# 0	Added, edited or printed description successfully
# 1	Failed adding, editing or printing description
# 2	Printed description, whether the file had one or not (empty output)
#
############################################################################################
