-
Notifications
You must be signed in to change notification settings - Fork 2
/
b2install-data
executable file
·108 lines (97 loc) · 3.17 KB
/
b2install-data
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
#!/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' and 'examples'."
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="[email protected]:"
if [ $# -gt 1 ]; then
GIT_URL="https://oauth2:${2}@gitlab.desy.de/"
fi
# get data type and corresponding directory and environment variable names
DATATYPE=$1
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}belle2/software/${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
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