-
Notifications
You must be signed in to change notification settings - Fork 2
/
b2install-prepare
executable file
·239 lines (218 loc) · 7.1 KB
/
b2install-prepare
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/bash
NO_PROMPT=no
INSTALL_OPTION=4
for i in "$@"; do
case $i in
--non-interactive)
NO_PROMPT=yes
;;
tools)
INSTALL_OPTION=1
;;
light)
INSTALL_OPTION=2
;;
basf2)
INSTALL_OPTION=3
;;
build)
INSTALL_OPTION=4
;;
externals)
INSTALL_OPTION=5
;;
all)
INSTALL_OPTION=6
;;
*)
cat <<EOT
Usage: b2install-prepare [--non-interactive] [tools|light|basf2|build|externals|all]
This tool will check if all necessary packages are installed and if not it will
ask the user if they should be installed. If --non-interactive is given the tool will not
ask for confirmation but will just install the necessary packages.
The purpose for which the necessary packages are installed is given by one
of the following arguments:
tools: for using the tools
light: for using a (light) basf2 release, without graphics
basf2: for using a full basf2 release, including graphics
build: for building basf2 [default]
externals: for building the externals
all: for building the externals including optional packages
A given purpose includes all purposes earlier in the list.
EOT
exit 1
;;
esac
done
# If /etc/os-release is present, read system identifier from it
OS_RELEASE_ID="<unknown>"
OS_RELEASE_ID_LIKE="<unknown>"
OS_RELEASE_VERSION="<unknown>"
if [ -f /etc/os-release ]; then
OS_RELEASE_ID=`(source /etc/os-release && echo $ID)`
OS_RELEASE_ID_LIKE=`(source /etc/os-release && echo $ID_LIKE)`
OS_RELEASE_VERSION=`(source /etc/os-release && echo $VERSION_ID)`
fi
if [ $OS_RELEASE_ID == "ubuntu" ] || [[ $OS_RELEASE_ID_LIKE = *ubuntu* ]]; then
# Ubuntu
PACKAGES="git python3-setuptools"
if [[ "$INSTALL_OPTION" > "1" ]]; then
PACKAGES+=" libfreetype6 diffutils libc6-dev"
fi
if [[ "$INSTALL_OPTION" > "2" ]]; then
PACKAGES+=" libglu1-mesa libglx0 libopengl0 libxpm4 libxft2 libfl2 libsm6 libice6 libtirpc3"
fi
if [[ "$INSTALL_OPTION" > "3" ]]; then
PACKAGES+=" pkg-config"
fi
if [[ "$INSTALL_OPTION" > "4" ]]; then
PACKAGES+=" make wget unzip xz-utils gcc m4 g++ bzip2 bison texinfo libssl-dev python3-pip libreadline-dev libfreetype-dev libx11-dev libxpm-dev libxft-dev libxext-dev libglew-dev libprotobuf-dev protobuf-compiler rsync libtirpc-dev ocaml"
fi
if [[ "$INSTALL_OPTION" > "5" ]]; then
PACKAGES+=" flex"
fi
CHECK_CMD="dpkg -s"
SU_CMD="sudo"
# but sometimes there's no sudo (yes official docker images, looking at you ...)
if ! [ -x "$(command -v sudo)" ]; then
SU_CMD="su -c"
fi
UPDATE_CMD="apt-get update"
INSTALL_CMD="apt-get install"
if [ "$NO_PROMPT" = "yes" ]; then
UPDATE_CMD="DEBIAN_FRONTEND=noninteractive apt-get update -q -y"
INSTALL_CMD="DEBIAN_FRONTEND=noninteractive apt-get install -q -y"
fi
elif [ $OS_RELEASE_ID == "debian" ]; then
# Debian
PACKAGES=""
PACKAGES_WITH_ARCHITECTURE="git procps python3"
if [[ "$INSTALL_OPTION" > "1" ]]; then
PACKAGES_WITH_ARCHITECTURE+=" libfreetype6 diffutils libc6-dev"
fi
if [[ "$INSTALL_OPTION" > "2" ]]; then
PACKAGES_WITH_ARCHITECTURE+=" libglu1-mesa libglx0 libopengl0 libxpm4 libxft2 libfl2 libtirpc3"
fi
if [[ "$INSTALL_OPTION" > "3" ]]; then
PACKAGES_WITH_ARCHITECTURE+=" pkg-config libsm6 libice6"
fi
if [[ "$INSTALL_OPTION" > "4" ]]; then
PACKAGES_WITH_ARCHITECTURE+=" make wget unzip xz-utils gcc m4 g++ bzip2 bison texinfo libssl-dev libreadline-dev libx11-dev libxpm-dev libxft-dev libxext-dev libglew-dev libprotobuf-dev protobuf-compiler rsync libtirpc-dev ocaml"
if [[ $OS_RELEASE_VERSION < "11" ]]; then # debian10 or older
PACKAGES_WITH_ARCHITECTURE+=" libfreetype6-dev"
else
PACKAGES_WITH_ARCHITECTURE+=" libfreetype-dev"
fi
PACKAGES+=" python3-pip"
fi
if [[ "$INSTALL_OPTION" > "5" ]]; then
PACKAGES_WITH_ARCHITECTURE+=" flex"
fi
# Add architecture specification to work on multiarch systems.
ARCHITECTURE=`dpkg --print-architecture`
for package in ${PACKAGES_WITH_ARCHITECTURE}; do
PACKAGES="${PACKAGES} ${package}:${ARCHITECTURE}"
done
CHECK_CMD="dpkg -s"
SU_CMD="su -c"
UPDATE_CMD="apt-get update"
INSTALL_CMD="apt-get install"
if [ "$NO_PROMPT" = "yes" ]; then
UPDATE_CMD="apt-get update -y"
INSTALL_CMD="apt-get install -y"
fi
else
# RHEL, CentOS, anything else
PACKAGES="git procps python3"
if [[ "$INSTALL_OPTION" > "1" ]]; then
PACKAGES+=" brotli freetype glibc-devel diffutils which"
fi
if [[ "$INSTALL_OPTION" > "2" ]]; then
PACKAGES+=" mesa-libGLU libglvnd-opengl libtirpc libicu libXpm libXft"
fi
if [[ ! $OS_RELEASE_VERSION < "9" ]]; then
if [[ "$INSTALL_OPTION" > "3" ]]; then
PACKAGES+=" perl-FindBin perl-File-Copy perl-Sys-Hostname perl-Hash-Util"
fi
fi
if [[ "$INSTALL_OPTION" > "4" ]]; then
PACKAGES+=" make wget unzip gcc m4 gcc-c++ bzip2 bison texinfo openssl-devel patch readline-devel freetype-devel libX11-devel libXpm-devel libXft-devel libXext-devel mesa-libGL-devel mesa-libGLU-devel protobuf-devel rsync libtirpc-devel ocaml"
fi
if [[ "$INSTALL_OPTION" > "5" ]]; then
PACKAGES+=" flex"
fi
CHECK_CMD="rpm -q"
SU_CMD="su -c"
INSTALL_CMD="dnf install"
if [[ $OS_RELEASE_VERSION < "8" ]]; then # el7 or older
INSTALL_CMD="yum install"
fi
if [ ! -f /etc/redhat-release ]; then
echo "Unknown linux distribution. Trying installation with yum..."
INSTALL_CMD="yum install"
fi
if [[ $OS_RELEASE_VERSION == "7" ]]; then # el7
PACKAGES+=" epel-release"
elif [[ $OS_RELEASE_VERSION < "9" ]]; then # el8
INSTALL_CMD="$INSTALL_CMD --enablerepo=powertools"
else # el9 or higher
INSTALL_CMD="$INSTALL_CMD --enablerepo=crb"
fi
if [ "$NO_PROMPT" = "yes" ]; then
INSTALL_CMD="$INSTALL_CMD -y"
fi
fi
TEXT="already"
# check for missing packages
MISSING_PACKAGES=""
for PACKAGE in ${PACKAGES}; do
${CHECK_CMD} ${PACKAGE} &> /dev/null
if [ "$?" != 0 ]; then
MISSING_PACKAGES="${MISSING_PACKAGES} ${PACKAGE}"
fi
done
# check for missing optional packages
MISSING_OPTIONALS=""
for PACKAGE in ${OPTIONALS}; do
${CHECK_CMD} ${PACKAGE} &> /dev/null
if [ "$?" != 0 ]; then
MISSING_OPTIONALS="${MISSING_OPTIONALS} ${PACKAGE}"
fi
done
# ask the user to install the missing packages
if [ -n "${MISSING_PACKAGES}" ]; then
TEXT="now"
INSTALL_MISSING=${INSTALL_CMD}${MISSING_PACKAGES}
if [ "${SU_CMD}" != "sudo" ]; then
INSTALL_MISSING=\"${INSTALL_MISSING}\"
fi
if [ "$NO_PROMPT" = "yes" ]; then
REPLY=y
else
echo "The following packages are missing:${MISSING_PACKAGES}
Please install them with the following command:
${SU_CMD} ${INSTALL_MISSING}
You will need root access to run this command.
"
read -p "Would you like to execute it now (y/n)? " -n 1 REPLY
echo
fi
if [ "$REPLY" = "y" ]; then
if [ "${SU_CMD}" != "sudo" ]; then
${SU_CMD} "${UPDATE_CMD}"
${SU_CMD} "${INSTALL_CMD}${MISSING_PACKAGES}"
else
${SU_CMD} ${UPDATE_CMD}
${SU_CMD} ${INSTALL_MISSING}
fi
if [ "$?" != 0 ]; then
exit 1
fi
else
exit 1
fi
fi
echo "
All software that is required to use the Belle II software for the
given purpose is ${TEXT} installed on your system.
"