chore(user/bkphotorights):Note Bash version used
[BK-2020-03.git] / user / bkphotorights
CommitLineData
63680c0d 1#!/usr/bin/env bash
ef95a74c
SBS
2# Desc: Apply metadata to photos
3# Usage: bkphotometa.sh [FILE in]
4# Ref/Attrib: [1]. Creative Commons XMP recommendation. (2015). https://wiki.creativecommons.org/wiki/XMP
5# [2]. Eva, Johannes. (2023-03-30). “How to edit EXIF metadata via the command line with ExifTool”. libre-software.net. https://libre-software.net/linux/edit-metadata-exiftool/
63680c0d
SBS
6# Version: 0.1.1
7# Depends: * exiftool 12.16 (https://exiftool.org/ )
8# * bash 5.1.16
ef95a74c
SBS
9
10# Adjust me
11strCreator="Steven Baltakatei Sandoval";
12strCreatorURL="https://baltakatei.com";
13strTerms="This work is licensed to the public under the Creative Commons Attribution-ShareAlike license http://creativecommons.org/licenses/by-sa/4.0/ .";
14strLicenseURL="http://creativecommons.org/licenses/by-sa/4.0/";
15
16yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
17die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
18must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails
19main() {
20 declare -a cmd_args;
21 file_in="$1";
22
23 # Check plumbing
24 if [[ ! -f "$1" ]]; then die "FATAL:Not a file:$1"; fi;
1f725176
SBS
25 if ! command -v exiftool 1>/dev/random 2>&1; then
26 die "FATAL:exiftool not available. See https://exiftool.org/ ."; fi;
ef95a74c
SBS
27
28 # Check file
29 # Check if exiftool recognizes the file format
1f725176 30 if ! exiftool -s -FileType "$file_in" 1>/dev/random; then
ef95a74c
SBS
31 yell "ERROR:File type not recognized by exiftool:$file_in";
32 fi;
33
34 # Change file metadata
35 unset cmd_args;
36 cmd_args+=("exiftool");
37 # cmd_args+=("-overwrite_original"); # hashtag reckless
38
39 value="$strTerms";
40 cmd_args+=("-XMP-dc:Rights=""$value"); unset value;
41
42 value="True";
43 cmd_args+=("-XMP-xmpRights:Marked=""$value"); unset value;
44
45 value="$strTerms";
46 cmd_args+=("-XMP-xmpRights:UsageTerms=""$value"); unset value;
47
48 value="$strLicenseURL";
49 cmd_args+=("-XMP-cc:license=""$value"); unset value;
50
51 value="$strCreator";
52 cmd_args+=("-XMP-cc:AttributionName=""$value"); unset value;
53
54 value="$strCreatorURL";
55 cmd_args+=("-XMP-cc:AttributionURL=""$value"); unset value;
56
57 cmd_args+=("$file_in");
58
59 # Execute command
60 "${cmd_args[@]}";
61}; # main program
62
63main "$@";
64
1f725176
SBS
65# Author: Steven Baltakatei Sandoval
66# License: GPLv3+