-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
install_prereqs.sh
executable file
·187 lines (164 loc) · 5.67 KB
/
install_prereqs.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
#!/bin/bash
#
# Install development prerequisites for source distributions of Drake on
# Ubuntu 20.04 (Focal) or 22.04 (Jammy).
#
# The development and runtime prerequisites for binary distributions should be
# installed before running this script.
set -euo pipefail
with_doc_only=0
with_maintainer_only=0
with_clang=1
with_test_only=1
with_update=1
with_asking=1
# TODO(jwnimmer-tri) Eventually we should default to with_clang=0.
while [ "${1:-}" != "" ]; do
case "$1" in
# Install prerequisites that are only needed to build documentation,
# i.e., those prerequisites that are dependencies of bazel run //doc:build.
--with-doc-only)
with_doc_only=1
;;
# Install prerequisites that are only needed for --config clang, i.e.,
# opts-in to the ability to compile Drake's C++ code using Clang.
--with-clang)
with_clang=1
;;
# Do NOT install prerequisites that are only needed for --config clang,
# i.e., opts-out of the ability to compile Drake's C++ code using Clang.
--without-clang)
with_clang=0
;;
# Install prerequisites that are only needed to run select maintainer
# scripts. Most developers will not need to install these dependencies.
--with-maintainer-only)
with_maintainer_only=1
;;
# Do NOT install prerequisites that are only needed to build and/or run
# unit tests, i.e., those prerequisites that are not dependencies of
# bazel { build, run } //:install.
--without-test-only)
with_test_only=0
;;
# Do NOT call apt-get update during execution of this script.
--without-update)
with_update=0
;;
# Pass -y along to apt-get.
-y)
with_asking=0
;;
*)
echo 'Invalid command line argument' >&2
exit 3
esac
shift
done
if [[ "${EUID}" -ne 0 ]]; then
echo 'ERROR: This script must be run as root' >&2
exit 1
fi
if [[ "${with_asking}" -eq 0 ]]; then
maybe_yes='-y'
else
maybe_yes=''
fi
if [[ "${with_update}" -eq 1 && "${binary_distribution_called_update:-0}" -ne 1 ]]; then
apt-get update || (sleep 30; apt-get update)
fi
apt-get install ${maybe_yes} --no-install-recommends $(cat <<EOF
ca-certificates
wget
EOF
)
codename=$(lsb_release -sc)
packages=$(cat "${BASH_SOURCE%/*}/packages-${codename}.txt")
apt-get install ${maybe_yes} --no-install-recommends ${packages}
# Ensure that we have available a locale that supports UTF-8 for generating a
# C++ header containing Python API documentation during the build.
apt-get install ${maybe_yes} --no-install-recommends locales
locale-gen en_US.UTF-8
# We need a working /usr/bin/python (of any version).
if [[ ! -e /usr/bin/python ]]; then
apt-get install ${maybe_yes} --no-install-recommends python-is-python3
else
echo "/usr/bin/python is already installed"
fi
if [[ "${with_doc_only}" -eq 1 ]]; then
packages=$(cat "${BASH_SOURCE%/*}/packages-${codename}-doc-only.txt")
apt-get install ${maybe_yes} --no-install-recommends ${packages}
fi
if [[ "${with_clang}" -eq 1 ]]; then
packages=$(cat "${BASH_SOURCE%/*}/packages-${codename}-clang.txt")
apt-get install ${maybe_yes} --no-install-recommends ${packages}
fi
if [[ "${with_test_only}" -eq 1 ]]; then
packages=$(cat "${BASH_SOURCE%/*}/packages-${codename}-test-only.txt")
# Suppress Python 3.8 warnings when installing python3-pandas on Focal.
PYTHONWARNINGS=ignore::SyntaxWarning \
apt-get install ${maybe_yes} --no-install-recommends ${packages}
fi
if [[ "${with_maintainer_only}" -eq 1 ]]; then
packages=$(cat "${BASH_SOURCE%/*}/packages-${codename}-maintainer-only.txt")
apt-get install ${maybe_yes} --no-install-recommends ${packages}
fi
dpkg_install_from_wget() {
package="$1"
version="$2"
url="$3"
checksum="$4"
# Skip the install if we're already at the exact version.
installed=$(dpkg-query --showformat='${Version}\n' --show "${package}" 2>/dev/null || true)
if [[ "${installed}" == "${version}" ]]; then
echo "${package} is already at the desired version ${version}"
return
fi
# If installing our desired version would be a downgrade, ask the user first.
if dpkg --compare-versions "${installed}" gt "${version}"; then
echo "This system has ${package} version ${installed} installed."
echo "Drake suggests downgrading to version ${version}, our supported version."
read -r -p 'Do you want to downgrade? [Y/n] ' reply
if [[ ! "${reply}" =~ ^([yY][eE][sS]|[yY])*$ ]]; then
echo "Skipping ${package} ${version} installation."
return
fi
fi
# Download and verify.
tmpdeb="/tmp/${package}_${version}-amd64.deb"
wget -O "${tmpdeb}" "${url}"
if echo "${checksum} ${tmpdeb}" | sha256sum -c -; then
echo # Blank line between checkout output and dpkg output.
else
echo "ERROR: The ${package} deb does NOT have the expected SHA256. Not installing." >&2
exit 2
fi
# Install.
dpkg -i "${tmpdeb}"
rm "${tmpdeb}"
}
# Install bazel package dependencies (these may duplicate dependencies of
# drake).
apt-get install ${maybe_yes} --no-install-recommends $(cat <<EOF
g++
unzip
zlib1g-dev
EOF
)
# Install bazel.
# Keep this version number in sync with the drake/.bazeliskrc version number.
if [[ $(arch) = "aarch64" ]]; then
# Check if bazel is already installed.
if [[ "$(which bazel)" ]]; then
echo "Bazel is already installed." >&2
else
echo "WARNING: On Ubuntu arm64 systems, Drake's install_prereqs does not" \
"automatically install Bazel on your behalf. You will need to install" \
"Bazel yourself. See https://bazel.build for instructions." >&2
fi
else
dpkg_install_from_wget \
bazel 5.3.1 \
https://releases.bazel.build/5.3.1/release/bazel_5.3.1-linux-x86_64.deb \
1e939b50d90f68d30fa4f3c12dfdf31429b83ddd8076c622429854f64253c23d
fi