-
Notifications
You must be signed in to change notification settings - Fork 8
/
indexschemas
executable file
·62 lines (52 loc) · 2.5 KB
/
indexschemas
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
#!/usr/bin/env bash
# indexschemas
# This script makes a text file listing certain files from the ltfs schema file.
SCRIPTDIR=$(dirname "${0}")
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ; }
_check_for_lto_index_dir
LTO_LOGS="${LTO_INDEX_DIR}"
unset VERSION
if [[ $(dirname $(command -v "${0}")) = "/usr/local/bin" || $(dirname $(command -v "${0}")) = "${HOME}/.linuxbrew/bin" ]] ; then
VERSION=$(TMP=$(brew info ltopers | grep ".*\*$" | grep -Eo "/ltopers/.* \(") ; echo "${TMP:9:(${#TMP}-11)}")
fi
_usage(){
cat <<EOF
$(basename "${0}") ${VERSION}
This script makes a text file listing certain files from the LTFS schema
file.
Usage: $(basename "${0}") -t | -h
-t check schema files modified today for volume names that may need
to be overwritten
-h display this help
EOF
}
OPTIND=1
while getopts ":th" opt ; do
case "${opt}" in
t) TODAYCHECK=(-mtime -24h) ;;
h) _usage ; exit 0 ;;
*) echo "Error: Bad option -${OPTARG}" ; _usage ; exit 1 ;;
esac
done
shift "$((OPTIND-1))"
renameschemas -u
find "${LTO_LOGS}" -iname "*.schema" -maxdepth 1 -mindepth 1 "${TODAYCHECK[@]}" | while read LTO_SCHEMA ; do
LTO_ID=$(basename "${LTO_SCHEMA%.*}")
LTO_INDEX="${LTO_LOGS}/${LTO_ID}_index.txt"
LTO_NAMESIZE="${LTO_LOGS}/${LTO_ID}_namesize.txt"
BARCODE_OVERWRITE=$(xml sel -t -m "/ltfsindex" -v "directory/contents/file/name[substring-before(., '_') = 'barcode']" "${LTO_SCHEMA}" | cut -d_ -f 2 | cut -d. -f1)
if [[ ! -z "${BARCODE_OVERWRITE}" && "${BARCODE_OVERWRITE}" != "${LTO_ID}" ]] ; then
OVERWRITE_NAME=$(dirname "${LTO_SCHEMA}")/"${BARCODE_OVERWRITE}.schema"
if [[ -f "${OVERWRITE_NAME}" ]] ; then
OVERWRITE_NAME=$(dirname "${LTO_SCHEMA}")/"${BARCODE_OVERWRITE}x.schema"
fi
echo "An overwrite is requested to $(basename "${LTO_SCHEMA}") changing to ${BARCODE_OVERWRITE}."
mv -v "${LTO_SCHEMA}" "${OVERWRITE_NAME}"
LTO_SCHEMA="${OVERWRITE_NAME}"
fi
if [ "${LTO_SCHEMA}" -nt "${LTO_INDEX}" ] ; then
echo "Updating index for ${LTO_ID}."
xml sel -t -m ".//file" -m "ancestor-or-self::directory" -v "name" -o "/" -b -v name -n "${LTO_SCHEMA}" | grep -v "/metadata/\|/access/\|/trimmed_materials/" > "${LTO_INDEX}"
xml sel -t -m ".//file" -m "ancestor-or-self::directory" -v "name" -o "/" -b -v name -o " " -v length -n "${LTO_SCHEMA}" | grep -v "/metadata/\|/access/\|/trimmed_materials/" | awk -F/ '{print $NF}' > "${LTO_NAMESIZE}"
fi
done