-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchive_processed
executable file
·37 lines (31 loc) · 1.28 KB
/
archive_processed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#! /usr/bin/env bash
set -e
export PATH="$(dirname $(readlink -e $0)):$PATH"
declare -r MOVE_PHOTOS="$(dirname $(readlink -e $0))/lib/move_photos.sh"
source "$(dirname "$(readlink -e $0)")/lib/metadata.sh"
declare -r SEARCH_DIR=$(readlink -e "$1")
if ! [[ -d $SEARCH_DIR ]]; then
echo "[EXIT]: $1 is not a directory" >&2
exit 1
elif [[ -z $(find "$SEARCH_DIR" -type f -path '*/converted/*.jpg') ]]; then
echo "[EXIT] No processed photos in $SEARCH_DIR" >&2
exit
fi
declare -r ARCHIVE_DIR=$(readlink -e "$2")
if ! [[ -d $2 ]]; then
echo "[EXIT] $2 is not a directory" >&2
exit 1
fi
set -u
# find all processed in SEARCH_DIR
find "$SEARCH_DIR" -type f -path '*/converted/*.jpg' | \
# get fullnames for all processed files (and make sure we have no duplicates after variants reduction)
while read -r processed_file; do
fullname_from_photofile "$processed_file" | sed -r 's/(.+_[0-9a-zA-Z]+)-[0-9]+$/\1/'
done | sort -u | \
# collect original files
while read -r fullname; do
find "$SEARCH_DIR" -regextype posix-extended -type f -iregex ".+/$fullname\.(ORF|RAW|JPG|CRW|CR2)$" ! -path '*/converted/*'
done | \
# now move original files and all associated files to ARCHIVE_DIR, write protect all files
xargs --no-run-if-empty "$MOVE_PHOTOS" -t "$ARCHIVE_DIR" | xargs --no-run-if-empty chmod ugo-w