-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·329 lines (299 loc) · 8.19 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·329 lines (299 loc) · 8.19 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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-2-Clause
#
# SPDX-FileCopyrightText: 2022 Western Digital Corporation or its affiliates.
# Check software prerequisites and prompt the user to install
# any missing components. Heavily influenced by fio configure.
#
# Author: Dmitry Fomichev
# These variables contol installation of optional components. Set the value to
# yes to include the optional component to the installation.
#
# If the software required for a component is already installed, setting the
# value to no or any other value will not remove it. The the component, however,
# will not be available to build.
if [ $(uname) != "Darwin" ]; then
FFMPEG=yes
else
FFMPEG=no
fi
CONTAINERS=no
KERNEL=no
TMPDIR="/tmp"
INCLUDE_PATH=/usr/include
TMPC="${TMPDIR}/ocs-setup-${RANDOM}-${RANDOM}.c"
TMPO="${TMPDIR}/ocs-setup-${RANDOM}-${RANDOM}.o"
TMPE="${TMPDIR}/ocs-setup-${RANDOM}-${RANDOM}.exe"
CC=gcc
CFLAGS="-D_GNU_SOURCE"
# Go version to use for container builds. Some container environment components
# require a particular Go version .
CONTAINER_GOLANG="1.19"
install_pkg() {
echo "ready to install $1..."
case $PKG_MGR in
dnf) dnf -y install "$1"
;;
apt) apt install "$1" -y
;;
yum) yum install "$1" -y
;;
brew) brew install "$1"
;;
*)
echo "unsupported package manager $PKG_MGR"
return 1
esac
return $?
}
update_pkg() {
case $PKG_MGR in
dnf) dnf -y update "$1"
;;
apt) apt update "$1 -y"
;;
yum) yum --update "$1"
;;
*)
echo "unsupported package manager $PKG_MGR"
return 1
esac
return $?
}
check_and_install() {
if type $1 > /dev/null 2>&1; then
echo "$1 already installed"
return 0
else
echo "installing $1..."
if test -z "$2" ; then
install_pkg $1
else
install_pkg $2
fi
return $?
fi
}
check_version_and_install() {
if $1 --version > /dev/null 2>&1; then
echo "$1 already installed"
return 0
else
echo "installing $1..."
if test -z "$2" ; then
install_pkg $1
else
install_pkg $2
fi
return $?
fi
}
compile_prog() {
local_cflags="$1"
local_ldflags="$2"
$CC $CFLAGS -Werror-implicit-function-declaration \
$local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags \
>> /dev/null 2>&1
}
unset -f command_not_found_handle
if [[ $(id -u) -ne "0" && $(uname) != "Darwin" ]]; then
echo "Please run as root"
exit 1
fi
echo "Installing required OCS-rs software packages..."
# Test what packge manager(s) we have available.
# $PKG_MRG variable may be set externally to specify
# the preferred manager to use.
if test -z $PKG_MGR ; then
if dnf --version > /dev/null 2>&1; then
dnf makecache
PKG_MGR="dnf"
elif apt --version > /dev/null 2>&1; then
apt autoremove -y
PKG_MGR="apt"
elif yum --version > /dev/null 2>&1; then
yum --enablerepo=extras install epel-release -y
if yum install dnf -y; then
dnf makecache
PKG_MGR="dnf"
else
yum makecache
PKG_MGR="yum"
fi
elif brew --version > /dev/null 2>&1; then
PKG_MGR="brew"
fi
else
case $PKG_MGR in
dnf|apt|yum|brew)
;;
*)
echo "unsupported package manager $PKG_MGR"
exit 1
esac
fi
# Install the required software utilities
check_version_and_install wget || exit 1
check_version_and_install curl || exit 1
check_version_and_install git || exit 1
check_version_and_install autoconf || exit 1
check_version_and_install automake || exit 1
check_version_and_install libtool || exit 1
check_version_and_install make || exit 1
check_version_and_install cmake || exit 1
check_version_and_install pkg-config || exit 1
if [ "$PKG_MGR" = "brew" ]; then
pip3 install --user reuse|| exit 1
else
check_version_and_install reuse || exit 1
fi
check_and_install bzip2 || exit 1
if [ "$PKG_MGR" = "dnf" ]; then
check_version_and_install gcc || exit 1
check_version_and_install "c++" "gcc-c++" || exit 1
install_pkg clang-devel || exit 1
install_pkg musl-libc || return 1
install_pkg musl-gcc || return 1
install_pkg libblkid-devel || exit 1
# Fedora doesn't include the necessary codecs for
# FireFox to play H.264/H.265 videos. Install them here
install_pkg \
https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm || exit 1
install_pkg \
https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm || exit 1
install_pkg ffmpeg
elif [ "$PKG_MGR" = "apt" ]; then
install_pkg build-essential || exit 1
install_pkg libclang-dev || exit 1
install_pkg musl || return 1
install_pkg musl-tools || return 1
install_pkg libblkid-dev || exit 1
fi
# MySQL
if [ "$PKG_MGR" = "dnf" ]; then
check_and_install mysql-devel || exit 1
elif [ "$PKG_MGR" = "apt" ]; then
check_and_install libmysqlclient-dev || exit 1
elif [ "$PKG_MGR" = "apt" ]; then
check_and_install mysql || exit 1
elif [ "$PKG_MGR" = "brew" ]; then
check_and_install mysql || exit 1
fi
# Check if some required libraries that we don't
# build are available and install them if not.
echo "checking for zlib..."
cat > $TMPC <<EOF
#include <zlib.h>
int main(void)
{
z_stream stream;
if (inflateInit(&stream) != Z_OK)
return 1;
return 0;
}
EOF
if compile_prog "" "-lz"; then
echo "zlib already installed"
else
echo "installing zlib"
install_pkg zlib || exit 1
fi
# Install optional components
if [ "$KERNEL" = "yes" ]; then
#Linux kernel build prerequisites
check_and_install gawk || exit 1
check_and_install bison || exit 1
check_and_install flex || exit 1
check_and_install openssl || exit 1
check_and_install llvm || exit 1
check_and_install clang || exit 1
if [ "$PKG_MGR" = "dnf" ]; then
install_pkg @development-tools || exit 1
elif [ "$PKG_MGR" = "apt" ]; then
check_and_install libncurses-dev || exit 1
check_and_install libssl-dev || exit 1
check_and_install dkms || exit 1
check_and_install libelf-dev || exit 1
# check_and_install libudev-dev || echo "can't install libudev-dev"
# check_and_install libpci-dev || exit 1
check_and_install libiberty-dev || exit 1
fi
fi
if [ "$FFMPEG" = "yes" ]; then
# Assemblers to build ffmpeg codecs
check_and_install yasm || exit 1
check_version_and_install nasm || exit 1
# freetype is needed for some codecs
echo "checking for freetype..."
cat > $TMPC <<EOF
#include <ft2build.h>
#include FT_FREETYPE_H
int main(void)
{
FT_Library lib;
if (FT_Init_FreeType(&lib))
return 1;
return 0;
}
EOF
if [ "$PKG_MGR" = "dnf" ]; then
if compile_prog "-I$INCLUDE_PATH/freetype2" "-lfreetype"; then
echo "freetype-devel already installed"
else
echo "installing freetype-devel"
install_pkg freetype-devel || exit 1
fi
elif [ "$PKG_MGR" = "apt" ]; then
if compile_prog "-I$INCLUDE_PATH/freetype2" "-lfreetype"; then
echo "libfreetype6-dev already installed"
else
echo "installing libfreetype6-dev"
install_pkg libfreetype6-dev || exit 1
fi
elif [ "$PKG_MGR" = "brew" ]; then
echo "installing freetype"
brew install freetype
brew link --overwrite freetype
else
echo "install freetype2 manually"
fi
fi
if [ "$CONTAINERS" = "yes" ]; then
GOLANG_VERSION=$(go version | sed -n 's/go version go\([0-9]*.[0-9]*\).*/\1/p')
if [ "${GOLANG_VERSION}" != "${CONTAINER_GOLANG}" ];then
echo "installing golang ${CONTAINER_GOLANG}..."
rm -rf /usr/local/go
if [ "$PKG_MGR" = "apt" ]; then
apt purge golang-* -y
fi
wget "https://go.dev/dl/go${CONTAINER_GOLANG}.linux-amd64.tar.gz"
tar -C /usr/local -xzf "go${CONTAINER_GOLANG}.linux-amd64.tar.gz"
rm -rf "go${CONTAINER_GOLANG}.linux-amd64.tar.gz*"
ln -s /usr/local/go/bin/go /usr/bin/go
go env -w GOFLAGS="-buildvcs=false"
go install golang.org/x/tools/cmd/goimports@latest
else
echo "golang ${CONTAINER_GOLANG} is already installed"
fi
if [ "$PKG_MGR" = "dnf" ]; then
check_and_install docker || exit 1
elif [ "$PKG_MGR" = "apt" ]; then
check_and_install docker docker.io || exit 1
else
echo "install docker and golang ${GOLANG_VERSION} manually"
fi
systemctl start docker.service
fi
# Create build.env by taking build.in and appending the variables that
# indicate the availability of components during build.
cp -f build.in build.env
if [ "$FFMPEG" = "yes" ]; then
printf "BUILD_FFMPEG = \"yes\"\n" >> build.env
fi
if [ "$CONTAINERS" = "yes" ]; then
printf "BUILD_CONTAINERS = \"yes\"\n" >> build.env
fi
if [ "$KERNEL" = "yes" ]; then
printf "BUILD_KERNEL = \"yes\"\n" >> build.env
fi
chown -R "${SUDO_USER}" build.env