4366 |
27 Feb 17 |
nicklas |
# Finds information about a release export |
4366 |
27 Feb 17 |
nicklas |
2 |
# |
4366 |
27 Feb 17 |
nicklas |
# ./check_export_status.sh <folder> |
4366 |
27 Feb 17 |
nicklas |
4 |
# |
4366 |
27 Feb 17 |
nicklas |
# Outputs a JSON data structure with information about the export |
4366 |
27 Feb 17 |
nicklas |
6 |
# |
5236 |
16 Jan 19 |
nicklas |
# Exists with exit code=99 if the data folder doesn't exists |
5236 |
16 Jan 19 |
nicklas |
# or contains the expected data file |
4366 |
27 Feb 17 |
nicklas |
9 |
# |
4366 |
27 Feb 17 |
nicklas |
10 |
|
4366 |
27 Feb 17 |
nicklas |
# The folder to check is the first parameter |
4366 |
27 Feb 17 |
nicklas |
# (or it may exists as a global variable already) |
4366 |
27 Feb 17 |
nicklas |
13 |
if [ $# -ne 0 ]; then |
4366 |
27 Feb 17 |
nicklas |
14 |
DATA_FOLDER=$1 |
4366 |
27 Feb 17 |
nicklas |
15 |
fi |
4366 |
27 Feb 17 |
nicklas |
16 |
|
4366 |
27 Feb 17 |
nicklas |
17 |
if [ ! -d "${DATA_FOLDER}" ]; then |
4366 |
27 Feb 17 |
nicklas |
18 |
echo "Can't find data folder ${DATA_FOLDER}" 1>&2 |
4366 |
27 Feb 17 |
nicklas |
19 |
exit 99 |
4366 |
27 Feb 17 |
nicklas |
20 |
fi |
4366 |
27 Feb 17 |
nicklas |
21 |
|
4366 |
27 Feb 17 |
nicklas |
# Format string for file dates/times |
4366 |
27 Feb 17 |
nicklas |
23 |
DATE_FORMAT="%Y%m%d %H%M%S" |
4366 |
27 Feb 17 |
nicklas |
24 |
|
4366 |
27 Feb 17 |
nicklas |
25 |
INDEX_JSON=${DATA_FOLDER}/index.json |
4366 |
27 Feb 17 |
nicklas |
26 |
|
5236 |
16 Jan 19 |
nicklas |
27 |
if [ ! -f "${INDEX_JSON}" ]; then |
5236 |
16 Jan 19 |
nicklas |
28 |
echo "Can't find data folder ${DATA_FOLDER}" 1>&2 |
5236 |
16 Jan 19 |
nicklas |
29 |
exit 99 |
5236 |
16 Jan 19 |
nicklas |
30 |
fi |
5236 |
16 Jan 19 |
nicklas |
31 |
|
5236 |
16 Jan 19 |
nicklas |
32 |
|
4366 |
27 Feb 17 |
nicklas |
# Start a JSON object |
4366 |
27 Feb 17 |
nicklas |
34 |
echo "{" |
4366 |
27 Feb 17 |
nicklas |
35 |
|
4366 |
27 Feb 17 |
nicklas |
# index.json is one of the first files created |
4366 |
27 Feb 17 |
nicklas |
# and contains some metadata about the export |
4366 |
27 Feb 17 |
nicklas |
38 |
if [ -f "${INDEX_JSON}" ]; then |
4366 |
27 Feb 17 |
nicklas |
39 |
echo "\"index\":`cat "${INDEX_JSON}"`," |
4366 |
27 Feb 17 |
nicklas |
40 |
echo "\"startdate\": \"`date +"${DATE_FORMAT}" -r "${INDEX_JSON}"`\"," |
4366 |
27 Feb 17 |
nicklas |
41 |
fi |
4366 |
27 Feb 17 |
nicklas |
42 |
|
4366 |
27 Feb 17 |
nicklas |
# The ./json subfolder contains the JSON files for all items |
4366 |
27 Feb 17 |
nicklas |
44 |
if [ -d "${DATA_FOLDER}/json" ]; then |
4366 |
27 Feb 17 |
nicklas |
45 |
echo "\"jsoncount\": `find "${DATA_FOLDER}/json" -type f -name *.json | wc -l`" |
4366 |
27 Feb 17 |
nicklas |
46 |
fi |
4366 |
27 Feb 17 |
nicklas |
47 |
|
4366 |
27 Feb 17 |
nicklas |
# 'exportcomplete' is created when the export is complete |
4366 |
27 Feb 17 |
nicklas |
49 |
if [ -f "${DATA_FOLDER}/exportcomplete" ]; then |
4366 |
27 Feb 17 |
nicklas |
50 |
echo "\"enddate\": \"`date +"${DATE_FORMAT}" -r "${DATA_FOLDER}/exportcomplete"`\"," |
4366 |
27 Feb 17 |
nicklas |
51 |
fi |
4366 |
27 Feb 17 |
nicklas |
52 |
|
4366 |
27 Feb 17 |
nicklas |
# End the main JSON object |
4366 |
27 Feb 17 |
nicklas |
54 |
echo "}" |