-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy-verify.sh
More file actions
executable file
·63 lines (47 loc) · 1.93 KB
/
Copy pathcopy-verify.sh
File metadata and controls
executable file
·63 lines (47 loc) · 1.93 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
# TODO: list dependencies and document Mac OSX vs Linux differences
source_full_path=$1
target_full_path=$2
# TODO: output messages to stderr
# script currently takes exactly two arguments: full path to source; full path to target
if [ "$#" -ne 2 ] ; then
echo "This script requires two arguments." >&2
exit
fi
if [ ! -d "$source_full_path" ]
then
echo "The directory \"$source_full_path\" could not be found." >&2
exit
fi
if [ -d "$target_full_path" ]
then
echo "Found existing directory at \"$target_full_path\". The target path must be a new directory." >&2
exit
fi
source=$(basename "$source_full_path")
source_parent=$(dirname "$source_full_path")
# create target directory
mkdir -pv "$target_full_path/data"
# generate payload checksum manifest that conforms to the BagIt structure
# change into parent directory of source in order to list relative pathnames in manifest
# prepend "data" to manifest filepath to match path in target folder
cd "$source_parent"
find "$source" -type f -exec md5sum {} \; | sed 's/./&data\//34' | tee "$target_full_path/manifest-md5.txt"
# generate file count and total size for payload
count=$(find "$source" -type f | wc -l)
size=$(find "$source" -type f -exec stat -c "%s" {} \; | awk '{n += $1} ; END{printf "%.0f", n}')
# TODO: add rsync log file to target directory
rsync -rvh --times --itemize-changes --progress "$source" "$target_full_path"/data/
# create bag-info.txt file
echo "Bag-Software-Agent: copy-verify.sh script
Bagging-Date: $(date -I)
Payload-Oxum: $size.$count" > "$target_full_path/bag-info.txt"
# create bagit.txt file
echo "BagIt-Version: 0.97
Tag-File-Character-Encoding: UTF-8" > "$target_full_path/bagit.txt"
# change into target directory to create tag manifest using relative paths within bag
cd "$target_full_path"
md5sum "bagit.txt" "bag-info.txt" "manifest-md5.txt" > tagmanifest-md5.txt
# validate bag
# TODO: log result to file
bagit.py --validate "$PWD"