-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathb2install-data
More file actions
executable file
·118 lines (106 loc) · 3.64 KB
/
b2install-data
File metadata and controls
executable file
·118 lines (106 loc) · 3.64 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
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
117
118
#!/bin/bash
set -o pipefail
# check for help option
if [ "$1" = "--help" -o "$1" = "-h" -o "$1" = "-?" ]; then
echo
echo "Usage: `basename $0` datatype [token]"
echo
echo "- This command installs or updates the given type of basf2 data."
echo " Supported data types are 'validation', 'examples' and 'starterkit'."
echo "- The command requires that you have access to the DESY gitlab with ssh key:"
echo " https://gitlab.desy.de"
echo "- Alternatively a token can be used to access the repository."
echo
exit 0
fi
# check number of arguments
if [ $# -gt 2 ] || [ $# -lt 1 ]; then
echo "Usage: `basename $0` datatype [token]" 1>&2
echo "For more information use `basename $0` --help."
exit 1
fi
# check for software tools setup
if [ -z "${VO_BELLE2_SW_DIR}" ]; then
echo "Belle II software environment is not set up." 1>&2
echo "-> source b2setup" 1>&2
exit 1
fi
# check for optional token
GIT_URL=$(dirname ${BELLE2_SOFTWARE_REPOSITORY})
if [ $# -gt 1 ]; then
GIT_URL="https://oauth2:${2}@gitlab.desy.de/belle2/software"
fi
# get data type and check that it is one of the supported values
DATATYPE=$1
if [[ "$DATATYPE" != "validation" && "$DATATYPE" != "examples" && "$DATATYPE" != "starterkit" ]]; then
echo "Error: The first argument must be either 'validation', 'examples' or 'starterkit'."
exit 1
fi
# set directory and environment variable names corresponding to data type
DIRNAME="${DATATYPE,,}-data"
ENVNAME="BELLE2_${DATATYPE^^}_DATA_DIR"
# check existence of directory and create it if missing and approved by user
if [ -n "${!ENVNAME}" ]; then
DIR=${!ENVNAME}
if [ ! -d ${DIR} ]; then
echo "The environment variable ${ENVNAME} is set to ${DIR}, but the directory does not exit."
read -p "Would you like to create it (y/n)? " -n 1 REPLY
echo
if [ "$REPLY" != "y" ]; then
exit 0
fi
mkdir -p ${DIR}
if [ "$?" != "0" ]; then
echo "Error: The creation of the directory ${DIR} failed."
echo "-> Make sure the environment variable ${ENVNAME} is set correctly and you have write access to the directory."
exit 1
fi
fi
else
DIR=${VO_BELLE2_SW_DIR}/${DIRNAME}
if [ ! -d ${DIR} ]; then
echo "The environment variable ${ENVNAME} is not set. The default installation directory is ${DIR}, but it does not exit."
if [ ! -w ${VO_BELLE2_SW_DIR} ]; then
echo "Error: No write permissions to the directory ${VO_BELLE2_SW_DIR}. Make sure the environment variable ${ENVNAME} is set correctly." 1>&2
exit 1
fi
read -p "Would you like to create it (y/n)? " -n 1 REPLY
echo
if [ "$REPLY" != "y" ]; then
exit 0
fi
mkdir -p ${DIR}
if [ "$?" != "0" ]; then
echo "Error: The creation of the directory ${DIR} failed."
echo "-> Make sure the environment variable ${ENVNAME} is set correctly and you have write access to the directory."
exit 1
fi
fi
fi
# connect to git repository
cd ${DIR}
if [ ! -d .git ]; then
git clone --no-checkout ${GIT_URL}/${DIRNAME}.git tmp
if [ "$?" != 0 ]; then
echo "Error: The synchronization of the ${DATATYPE} data failed." 1>&2
echo " Make sure you have access to the DESY gitlab." 1>&2
exit 1
fi
mv tmp/.git .
rm -rf tmp
git lfs install
if [[ "${BELLE2_GIT_SERVER}" == *"github.com"* ]]; then
git config lfs.standalonetransferagent b2lfs
git config lfs.customtransfer.b2lfs.path ${BELLE2_TOOLS}/b2lfs
fi
fi
# sync data
echo "Syncing ${DATATYPE} data to ${DIR}"
git fetch
if [ "$?" != 0 ]; then
echo "Error: The synchronization of the ${DATATYPE} data failed." 1>&2
echo " Make sure you have access to the DESY gitlab." 1>&2
exit 1
fi
git checkout -f main
git pull