/
install-prerequisites.sh
executable file
·299 lines (263 loc) · 11.7 KB
/
install-prerequisites.sh
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
#!/usr/bin/env bash
#-----------------------------------------------------------------------------
#
# TSDuck - The MPEG Transport Stream Toolkit
# Copyright (c) 2005-2022, Thierry Lelegard
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
#
#-----------------------------------------------------------------------------
#
# This script installs all pre-requisites packages to build TSDuck,
# depending on the system.
#
# Supported options:
#
# --m32 : install libraries for 32-bit cross-compilation (when supported)
# --static : install static libraries for static build (when supported)
# Additional options are passed to the package manager (dnf, apt, brew, etc.)
#
# Supported operating systems:
#
# - macOS
# - Ubuntu
# - Debian
# - Raspbian
# - Fedora
# - Red Hat
# - CentOS
# - Alma Linux
# - Rocky Linux
# - openSUSE Linux
# - Arch Linux
# - Alpine Linux
# - Gentoo
# - Linux Mint
#
#-----------------------------------------------------------------------------
SCRIPT=$(basename $0 .sh)
SCRIPTDIR=$(cd $(dirname $0); pwd)
error() { echo >&2 "$SCRIPT: $*"; exit 1; }
# Default options.
STATIC=false
M32=false
PKGOPTS=
# Decode command line options.
while [[ $# -gt 0 ]]; do
case "$1" in
--m32)
M32=true
;;
--static)
STATIC=true
;;
*)
PKGOPTS="$PKGOPTS $1"
;;
esac
shift
done
[[ -n "$PKGOPTS" ]] && echo "====> using packager options: $PKGOPTS"
SYSTEM=$(uname -s)
DISTRO=$(lsb_release -i 2>/dev/null | sed -e 's/.*:[\t ]*//')
MAJOR=$(lsb_release -r 2>/dev/null | sed -e 's/.*:[\t ]*//' -e 's/\..*//')
MINOR=$(lsb_release -r 2>/dev/null | sed -e '/\./!d' -e 's/.*:[\t ]*//' -e 's/.*\.//')
VERSION=$(( ${MAJOR:-0} * 100 + ${MINOR:-0} ))
#-----------------------------------------------------------------------------
# macOS (with HomeBrew as open source packager)
#
# Update command: brew update; brew upgrade
#-----------------------------------------------------------------------------
if [[ "$SYSTEM" == "Darwin" ]]; then
pkglist="gnu-sed grep dos2unix coreutils srt librist python3 openjdk"
if [[ -z $(which clang 2>/dev/null) ]]; then
# Build tools not installed
xcode-select --install
fi
if [[ -z $(which brew 2>/dev/null) ]]; then
# Homebrew not installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
# Sometimes, brew exits with an error status even though the installation completes.
# Mute this and enforce a good status to avoid GitHub Actions CI failure.
brew $PKGOPTS install $pkglist || true
# Register the openjdk jvm.
[[ -e /Library/Java/JavaVirtualMachines/openjdk.jdk ]] || \
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
#-----------------------------------------------------------------------------
# Ubuntu
#
# Update command: sudo apt update; sudo apt upgrade
# Find package providing file: dpkg -S /path/to/file
#-----------------------------------------------------------------------------
elif [[ "$DISTRO" == "Ubuntu" ]]; then
pkglist="g++ dos2unix curl tar zip doxygen graphviz linux-libc-dev libedit-dev pcscd libpcsclite-dev dpkg-dev python3 default-jdk"
if [[ "$MAJOR" -le 17 ]]; then
pkglist="$pkglist libcurl3 libcurl3-dev"
else
pkglist="$pkglist libcurl4 libcurl4-openssl-dev"
fi
if $M32; then
pkglist="$pkglist gcc-multilib"
fi
if [[ "$VERSION" -ge 2010 ]]; then
pkglist="$pkglist libsrt-openssl-dev"
elif [[ "$VERSION" -ge 1904 ]]; then
pkglist="$pkglist libsrt-dev"
fi
sudo apt update
sudo apt install -y $PKGOPTS $pkglist
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
#-----------------------------------------------------------------------------
# Linux Mint
#
# Update command: sudo apt update; sudo apt upgrade
# Find package providing file: dpkg -S /path/to/file
#-----------------------------------------------------------------------------
elif [[ "$DISTRO" == "Linuxmint" ]]; then
pkglist="g++ dos2unix curl tar zip doxygen graphviz linux-libc-dev libedit-dev pcscd libpcsclite-dev dpkg-dev python3 default-jdk libcurl4 libcurl4-openssl-dev libsrt-dev"
sudo apt update
sudo apt install -y $PKGOPTS $pkglist
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
#-----------------------------------------------------------------------------
# Debian or Raspbian (Raspberry Pi)
#
# Update command: sudo apt update; sudo apt upgrade
# Find package providing file: dpkg -S /path/to/file
#-----------------------------------------------------------------------------
elif [[ "$DISTRO" = "Debian" || "$DISTRO" = "Raspbian" ]]; then
pkglist="g++ dos2unix curl tar zip doxygen graphviz linux-libc-dev libedit-dev pcscd libpcsclite-dev dpkg-dev python3 default-jdk"
if $M32; then
pkglist="$pkglist gcc-multilib"
fi
if [[ "$MAJOR" -le 9 ]]; then
pkglist="$pkglist libcurl3 libcurl3-dev"
else
pkglist="$pkglist libcurl4 libcurl4-openssl-dev"
fi
if [[ "$MAJOR" -ge 11 ]]; then
pkglist="$pkglist libsrt-openssl-dev"
fi
sudo apt update
sudo apt install -y $PKGOPTS $pkglist
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
#-----------------------------------------------------------------------------
# Fedora
#
# Update command: sudo dnf update
# Find package providing file: rpm -qf /path/to/file
#-----------------------------------------------------------------------------
elif [[ -f /etc/fedora-release ]]; then
FC=$(grep " release " /etc/fedora-release 2>/dev/null | sed -e 's/^.* release \([0-9\.]*\) .*$/\1/')
pkglist="gcc-c++ dos2unix curl tar zip doxygen graphviz kernel-headers libedit-devel pcsc-tools pcsc-lite-devel libcurl libcurl-devel rpmdevtools python3 java-latest-openjdk-devel"
if $STATIC; then
pkglist="$pkglist glibc-static libstdc++-static"
fi
if $M32; then
pkglist="$pkglist glibc-devel.i686 libstdc++-devel.i686 pcsc-lite-devel.i686 libcurl-devel.i686"
fi
if [[ $FC -ge 31 ]]; then
pkglist="$pkglist srt-devel"
if $M32; then
pkglist="$pkglist srt-devel.i686"
fi
fi
sudo dnf -y install $PKGOPTS $pkglist
sudo alternatives --set python /usr/bin/python3
#-----------------------------------------------------------------------------
# Red Hat, CentOS, Alma Linux, Rocky Linux, etc.
#
# Update command: sudo dnf update
# Find package providing file: rpm -qf /path/to/file
#-----------------------------------------------------------------------------
elif [[ -f /etc/redhat-release ]]; then
EL=$(grep " release " /etc/redhat-release 2>/dev/null | sed -e 's/$/.99/' -e 's/^.* release \([0-9]*\.[0-9]*\).*$/\1/')
EL=$(( ${EL/.*/} * 100 + ${EL/*./} ))
pkglist="gcc-c++ dos2unix curl tar zip doxygen graphviz kernel-headers libedit-devel pcsc-lite pcsc-lite-devel libcurl libcurl-devel libatomic rpmdevtools python3 java-latest-openjdk-devel"
if $STATIC; then
pkglist="$pkglist glibc-static libstdc++-static"
fi
if $M32; then
pkglist="$pkglist glibc-devel.i686 libstdc++-devel.i686 pcsc-lite-devel.i686 libcurl-devel.i686"
fi
if [[ $EL -ge 802 ]]; then
pkglist="$pkglist srt-devel"
if $M32; then
pkglist="$pkglist srt-devel.i686"
fi
fi
if [[ $EL -lt 800 ]]; then
sudo yum -y install $PKGOPTS epel-release
sudo yum -y install $PKGOPTS $pkglist
elif [[ $EL -lt 803 ]]; then
sudo dnf -y config-manager --set-enabled PowerTools
sudo dnf -y install $PKGOPTS epel-release
sudo dnf -y install $PKGOPTS $pkglist
else
sudo dnf -y config-manager --set-enabled powertools
sudo dnf -y install $PKGOPTS epel-release
sudo dnf -y install $PKGOPTS $pkglist
fi
sudo alternatives --set python /usr/bin/python3
#-----------------------------------------------------------------------------
# openSUSE
#
# Update command: sudo zypper update -y -l
# Find package providing file: zypper se --provides /path/to/file
#-----------------------------------------------------------------------------
elif [[ -f /etc/os-release ]] && grep -q -i '^ID.*suse' /etc/os-release; then
pkglist="make gcc-c++ dos2unix curl tar zip doxygen graphviz linux-glibc-devel libedit-devel pcsc-tools pcsc-lite-devel curl libcurl-devel srt-devel rpmdevtools python3 java-11-openjdk-devel"
sudo zypper install -y -l $PKGOPTS $pkglist
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
#-----------------------------------------------------------------------------
# Arch Linux
#
# Update command: sudo pacman -Syu
# Find package providing file: pacman -Qo /path/to/file
#-----------------------------------------------------------------------------
elif [[ -f /etc/arch-release ]]; then
pkglist="make gcc dos2unix core/which inetutils net-tools curl tar zip doxygen graphviz linux-api-headers libedit pcsclite srt python jdk-openjdk"
sudo pacman -Syu --noconfirm $PKGOPTS $pkglist
#-----------------------------------------------------------------------------
# Alpine Linux
#
# Update command: sudo apk update; sudo apk upgrade
# Find package providing file: apk info --who-owns /path/to/file
#-----------------------------------------------------------------------------
elif [[ -f /etc/alpine-release ]]; then
sudo sed -i '/http.*\/alpine\/v/s/^#//' /etc/apk/repositories
pkglist="bash coreutils diffutils procps util-linux linux-headers git make g++ dos2unix curl tar zip dpkg doxygen graphviz libedit-dev pcsc-lite-dev curl-dev libsrt-dev python3 openjdk11 dpkg"
sudo apk add $PKGOPTS $pkglist
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
#-----------------------------------------------------------------------------
# Gentoo Linux
#
# Update command: sudo emerge --sync
# or (??): sudo emerge -auvND --with-bdeps=y world
# or (??): sudo emerge --update --deep --changed-use @world
# Find package providing file: equery b /path/to/file
#-----------------------------------------------------------------------------
elif [[ -f /etc/gentoo-release ]]; then
pkglist="sys-devel/gcc app-text/dos2unix net-misc/curl app-arch/tar app-arch/zip app-arch/unzip app-doc/doxygen media-gfx/graphviz sys-kernel/linux-headers dev-libs/libedit sys-apps/pcsc-lite net-libs/srt dev-lang/python dev-java/openjdk"
sudo emerge -n $PKGOPTS $pkglist
fi