-
Notifications
You must be signed in to change notification settings - Fork 2
/
b2install-externals
executable file
·157 lines (140 loc) · 4.59 KB
/
b2install-externals
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
set -o pipefail
# check for help option
if [ "$1" = "--help" -o "$1" = "-h" -o "$1" = "-?" ]; then
echo
echo "Usage: `basename $0` [--binary] [version [system]]"
echo
echo "- This command installs the given version of the externals in the"
echo " directory given by the environment variable BELLE2_EXTERNALS_TOPDIR."
echo "- By default it tries to install the precompiled binary version for"
echo " the current system. A binary version can be selected explicitly"
echo " with the second argument."
echo "- With the --binary option no compilation of the source will be attempted."
echo "- If no version is given it lists the available externals versions."
echo
exit 0
fi
# make sure tar uses stdin
unset TAPE
# check for binary option
BINARY_ONLY="no"
if [ "$1" = "--binary" ]; then
BINARY_ONLY="yes"
shift
fi
# check number of arguments
if [ $# -gt 2 ]; then
echo "Usage: `basename $0` [version [system]]" 1>&2
exit 1
fi
# check for software tools setup
if [ -z "${BELLE2_EXTERNALS_REPOSITORY}" -o -z "${BELLE2_EXTERNALS_TOPDIR}" ]; then
echo "Belle II software environment is not set up." 1>&2
echo "-> source b2setup" 1>&2
exit 1
fi
# list available versions if no argument is given
if [ $# -eq 0 ]; then
git ls-remote ${BELLE2_EXTERNALS_REPOSITORY} | grep "tags/" | grep -v "\^{}$" | awk -F / '{print $NF}'
COMMIT=`git ls-remote ${BELLE2_EXTERNALS_REPOSITORY} main | awk '{print $1}'`
echo "development (commit ${COMMIT})"
exit 0
fi
# check whether the given version is already installed
VERSION=$1
DIR=${BELLE2_EXTERNALS_TOPDIR}/${VERSION}
if [ -d ${DIR} ]; then
echo "Error: The externals version ${VERSION} is already installed at ${BELLE2_EXTERNALS_TOPDIR}." 1>&2
exit 1
fi
# check whether the externals top directory exists and cd to it
if [ ! -d ${BELLE2_EXTERNALS_TOPDIR} ]; then
echo "The externals top directory ${BELLE2_EXTERNALS_TOPDIR} does not exist."
read -p "Would you like to create it (y/n)? " -n 1 REPLY
echo
if [ "$REPLY" = "y" ]; then
mkdir -p ${BELLE2_EXTERNALS_TOPDIR}
if [ "$?" != 0 ]; then
echo "Error: The creation of the directory ${BELLE2_EXTERNALS_TOPDIR} failed." 1>&2
exit 1
fi
else
exit 1
fi
fi
cd ${BELLE2_EXTERNALS_TOPDIR}
# check whether we can write to the externals directory
if [ ! -w ${BELLE2_EXTERNALS_TOPDIR} ]; then
echo "Error: No write permissions to the directory ${BELLE2_EXTERNALS_TOPDIR}." 1>&2
exit 1
fi
function CheckBuildEnvironment ()
{
# check for geant4 and root setup
if [ -n "${G4SYSTEM}" ]; then
echo "Geant4 setup detected." 1>&2
echo "Please build the externals in a shell where geant4 is not set up" 1>&2
exit 1
fi
if [ -n "${ROOTSYS}" ]; then
echo "Root setup detected." 1>&2
echo "Please build the externals in a shell where root is not set up" 1>&2
exit 1
fi
# accept the geant4_vmc svn server certificate
echo p | svn list https://root.cern.ch/svn/geant4_vmc/ &> /dev/null
}
# check out the selected version
if [ "${VERSION}" = "development" ]; then
CheckBuildEnvironment
git clone ${BELLE2_EXTERNALS_REPOSITORY} development
if [ "$?" != 0 ]; then
echo "\nError: The git checkout of the externals failed." 1>&2
exit 2
fi
else
# try the binary version
SYSTEM=`b2install-print-os | sed "s/ //g"`
if [ $# -gt 1 ]; then
SYSTEM=$2
fi
if [ "${SYSTEM}" != "<unknown><unknown>" ]; then
wget -O - --tries=3 ${BELLE2_DOWNLOAD}/externals/externals_${VERSION}_${SYSTEM}.tgz | tar xz
RESULT=$?
if [ "${RESULT}" = "0" ]; then
exit 0
elif [ "${BINARY_ONLY}" = "yes" ]; then
exit 2
fi
fi
# next try the externals source tarball and then the checkout from the svn repository
CheckBuildEnvironment
wget -O - --tries=3 ${BELLE2_DOWNLOAD}/externals/externals_${VERSION}_src.tgz | tar xz
RESULT=$?
if [ "${RESULT}" -ne "0" ]; then
# check whether the given version is available
git ls-remote ${BELLE2_EXTERNALS_REPOSITORY} ${VERSION} > /dev/null
if [ "$?" != "0" ]; then
echo "Error: The externals version ${VERSION} does not exist." 1>&2
exit 1
fi
git clone ${BELLE2_EXTERNALS_REPOSITORY} ${VERSION}
if [ "$?" != 0 ]; then
echo "\nError: The git checkout of the externals failed." 1>&2
exit 2
else
cd ${VERSION}
git checkout ${VERSION}
cd ..
fi
fi
fi
# build the externals
cd ${VERSION}
make 2>&1 | tee make.log
if [ "$?" != 0 ]; then
echo "\nError: The compilation of the externals failed." 1>&2
echo "Please check the compilation log, try to fix the problem, and rerun make in ${BELLE2_EXTERNALS_TOPDIR}/${VERSION}." 1>&2
exit 3
fi