-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopulate.sh
executable file
·116 lines (102 loc) · 3.72 KB
/
populate.sh
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
############################################################
#
# This script is intended to be run inside the CouchDB
# container to populate the CouchDB database with the
# data from the EXFOR library.
#
# Usage:
# bash populate.sh <list of optional parameters>
#
# --exfor-parser-commit <COMMIT ID>
# The commit id associated with the version of
# the exfor-parserpy package [1] that should be
# used for the conversion of EXFOR master files
# to the JSON format. For default see code below.
# --exfor-master-commit <COMMIT ID>
# The commit id associated with the version of
# the EXFOR master files [2] whose content
# should be added to the CouchDB database.
# For default see code below.
# --user <USERNAME>
# The username to be used for connecting
# to the CouchDB sever. Default is "admin"
# --password <PASSWORD>
# The password for connecting to the CouchDB
# server. Default is "password"
# --dbname <DATABASE NAME>
# The name of the database on the CouchDB
# server that should be created and filled
# with the EXFOR library. Default is "exfor"
#
# [1]: https://github.com/iaea-nds/exfor-parserpy
# [2]: https://github.com/IAEA-NDS/exfor_master
#
############################################################
# Arguments that may be changed by the user
EXFOR_PARSER_COMMIT_ID="2669680e049fec81c34890b7cbb1ee4fec5e04a1"
EXFOR_MASTER_COMMIT_ID="main" # branch name or commit id
DBNAME="exfor"
# Script starts here
# if environment variables are not set for
# CouchDB credentials, adopt default choices
if [ -z ${COUCHDB_USER+x} ]; then
COUCHDB_USER="admin"
fi
if [ -z ${COUCHDB_PASSWORD+x} ]; then
COUCHDB_PASSWORD="password"
fi
argument_parser () {
while [ $# -gt 0 ]; do
if [[ $1 == "--"* ]]; then
param="${1/--/}"
if [[ $param == "exfor-parser-commit" ]]; then
EXFOR_PARSER_COMMIT_ID=$2
shift
elif [[ $param == "exfor-master-commit" ]]; then
EXFOR_MASTER_COMMIT_ID=$2
shift
elif [[ $param == "user" ]]; then
COUCHDB_USER=$2
shift
elif [[ $param == "password" ]]; then
COUCHDB_PASSWORD=$2
shift
elif [[ $param == "dbname" ]]; then
DBNAME=$2
shift
fi
fi
shift
done
}
argument_parser $@
# Leave as is unless there is a good reason to change these strings
EXFOR_PARSER_DIR="exfor-parserpy-${EXFOR_PARSER_COMMIT_ID}"
EXFOR_MASTER_DIR="exfor_master-${EXFOR_MASTER_COMMIT_ID}"
EXFOR_LIBRARY_DIR="${EXFOR_MASTER_DIR}/exforall"
mkdir /install_tmpdir
cd /install_tmpdir &&
# install exfor-parserpy
wget https://github.com/IAEA-NDS/exfor-parserpy/archive/${EXFOR_PARSER_COMMIT_ID}.zip &&
unzip ${EXFOR_PARSER_COMMIT_ID}.zip &&
pip install ./${EXFOR_PARSER_DIR} &&
rm -rf ./${EXFOR_PARSER_DIR}
if [ "$?" -ne 0 ]; then
echo "ERROR: Something went wrong during the installation of exfor-parserpy."
echo " Therefore unable to fill the CouchDB database with EXFOR content."
echo " Aborting."
exit 1
fi
# download exfor database
wget https://github.com/IAEA-NDS/exfor_master/archive/${EXFOR_MASTER_COMMIT_ID}.zip &&
unzip ${EXFOR_MASTER_COMMIT_ID}.zip &&
python3 /usr/local/bin/populate_exfor_couchdb.py \
--path ${EXFOR_LIBRARY_DIR} --ext .x4 \
--couchdb_url http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@localhost:5984 \
--dbname ${DBNAME}
if [ "$?" -ne 0 ]; then
echo "ERROR: Something went wrong during the ingestion of EXFOR content"
echo " into the CouchDB database. Aborting."
fi
rm -rf /install_tmpdir