-
Notifications
You must be signed in to change notification settings - Fork 0
/
describe_eprint_repo.bash
executable file
·67 lines (56 loc) · 1.47 KB
/
describe_eprint_repo.bash
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
64
65
66
67
#!/bin/bash
#
# Requirements MySQL Shell and Stephen Dolan's jq for formatting json output.
#
function showEPrintColumns() {
DB_NAME="${1}"
TABLE_NAME="${2}"
mysql --raw --batch --execute \
"SHOW COLUMNS IN ${TABLE_NAME} IN ${DB_NAME}" |\
cut -f 1 | tail -n +2 | sort
}
function showEPrintTables() {
DB__NAME="${1}"
mysql --raw --batch --execute \
"SHOW TABLES IN ${DB_NAME} LIKE 'eprint%'" \
| cut -f 1 | tail -n +2 | sort
}
#
# Main processing
#
if [ "$1" = "" ]; then
APP_NAME=$(basename $0)
cat <<EOF
USAGE
${APP_NAME} EPRINT_DB_NAME
This script will generate a JSON map to each EPrint
table and table's columns. This can be used to determine
what to crosswalk for any specific EPrint repository.
NOTE: It only maps the tables related to the EPrint XML
record.
Requires the MySQL Shell and Stephen Dolan's jq to work.
The MySQL Shell needs to be configure to access the
MySQL database
EOF
exit 1
fi
for DB_NAME in $1; do
echo -n '{'
TABLES=$(showEPrintTables "${DB_NAME}")
DELIM=""
for TABLE_NAME in ${TABLES}; do
if [ "$DELIM" != "" ]; then
echo "${DELIM}"
else
DELIM=","
echo ''
fi
echo -n "\"${TABLE_NAME}\":"
echo -n '['
for COLUMN in $(showEPrintColumns ${DB_NAME} ${TABLE_NAME}); do
echo -n "\"${COLUMN}\" "
done | sed -E 's/" "/", "/g'
echo -n ']'
done
echo -n '}'
done | jq .