]> git.proxmox.com Git - ceph.git/blame - ceph/install-deps.sh
import ceph quincy 17.2.4
[ceph.git] / ceph / install-deps.sh
CommitLineData
11fdf7f2
TL
1#!/usr/bin/env bash
2# -*- mode:sh; tab-width:8; indent-tabs-mode:t -*-
7c673cae
FG
3#
4# Ceph distributed storage system
5#
6# Copyright (C) 2014, 2015 Red Hat <contact@redhat.com>
7#
8# Author: Loic Dachary <loic@dachary.org>
9#
10# This library is free software; you can redistribute it and/or
11# modify it under the terms of the GNU Lesser General Public
12# License as published by the Free Software Foundation; either
13# version 2.1 of the License, or (at your option) any later version.
14#
11fdf7f2 15set -e
7c673cae
FG
16DIR=/tmp/install-deps.$$
17trap "rm -fr $DIR" EXIT
18mkdir -p $DIR
19if test $(id -u) != 0 ; then
20 SUDO=sudo
21fi
22export LC_ALL=C # the following is vulnerable to i18n
23
11fdf7f2
TL
24ARCH=$(uname -m)
25
c07f9fc5 26function munge_ceph_spec_in {
9f95a23c
TL
27 local with_seastar=$1
28 shift
f67539c2
TL
29 local with_zbd=$1
30 shift
11fdf7f2
TL
31 local for_make_check=$1
32 shift
20effc67
TL
33 local with_jaeger=$1
34 shift
c07f9fc5 35 local OUTFILE=$1
11fdf7f2
TL
36 sed -e 's/@//g' < ceph.spec.in > $OUTFILE
37 # http://rpm.org/user_doc/conditional_builds.html
9f95a23c 38 if $with_seastar; then
11fdf7f2
TL
39 sed -i -e 's/%bcond_with seastar/%bcond_without seastar/g' $OUTFILE
40 fi
f67539c2
TL
41 if $with_jaeger; then
42 sed -i -e 's/%bcond_with jaeger/%bcond_without jaeger/g' $OUTFILE
43 fi
44 if $with_zbd; then
45 sed -i -e 's/%bcond_with zbd/%bcond_without zbd/g' $OUTFILE
46 fi
11fdf7f2
TL
47 if $for_make_check; then
48 sed -i -e 's/%bcond_with make_check/%bcond_without make_check/g' $OUTFILE
49 fi
c07f9fc5
FG
50}
51
11fdf7f2
TL
52function munge_debian_control {
53 local version=$1
54 shift
11fdf7f2
TL
55 local control=$1
56 case "$version" in
57 *squeeze*|*wheezy*)
58 control="/tmp/control.$$"
59 grep -v babeltrace debian/control > $control
60 ;;
61 esac
f67539c2
TL
62 if $with_jaeger; then
63 sed -i -e 's/^# Jaeger[[:space:]]//g' $control
64 sed -i -e 's/^# Crimson libyaml-cpp-dev,/d' $control
65 fi
11fdf7f2
TL
66 echo $control
67}
68
69function ensure_decent_gcc_on_ubuntu {
70 # point gcc to the one offered by g++-7 if the used one is not
71 # new enough
72 local old=$(gcc -dumpfullversion -dumpversion)
b32b8144 73 local new=$1
11fdf7f2 74 local codename=$2
eafe8130 75 if dpkg --compare-versions $old ge ${new}.0; then
11fdf7f2
TL
76 return
77 fi
78
79 if [ ! -f /usr/bin/g++-${new} ]; then
80 $SUDO tee /etc/apt/sources.list.d/ubuntu-toolchain-r.list <<EOF
81deb [lang=none] http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu $codename main
9f95a23c 82deb [arch=amd64 lang=none] http://mirror.nullivex.com/ppa/ubuntu-toolchain-r-test $codename main
11fdf7f2
TL
83EOF
84 # import PPA's signing key into APT's keyring
85 cat << ENDOFKEY | $SUDO apt-key add -
86-----BEGIN PGP PUBLIC KEY BLOCK-----
87Version: SKS 1.1.6
88Comment: Hostname: keyserver.ubuntu.com
89
90mI0ESuBvRwEEAMi4cDba7xlKaaoXjO1n1HX8RKrkW+HEIl79nSOSJyvzysajs7zUow/OzCQp
919NswqrDmNuH1+lPTTRNAGtK8r2ouq2rnXT1mTl23dpgHZ9spseR73s4ZBGw/ag4bpU5dNUSt
92vfmHhIjVCuiSpNn7cyy1JSSvSs3N2mxteKjXLBf7ABEBAAG0GkxhdW5jaHBhZCBUb29sY2hh
93aW4gYnVpbGRziLYEEwECACAFAkrgb0cCGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAAKCRAe
94k3eiup7yfzGKA/4xzUqNACSlB+k+DxFFHqkwKa/ziFiAlkLQyyhm+iqz80htRZr7Ls/ZRYZl
950aSU56/hLe0V+TviJ1s8qdN2lamkKdXIAFfavA04nOnTzyIBJ82EAUT3Nh45skMxo4z4iZMN
96msyaQpNl/m/lNtOLhR64v5ZybofB2EWkMxUzX8D/FQ==
97=LcUQ
98-----END PGP PUBLIC KEY BLOCK-----
99ENDOFKEY
100 $SUDO env DEBIAN_FRONTEND=noninteractive apt-get update -y || true
eafe8130 101 $SUDO env DEBIAN_FRONTEND=noninteractive apt-get install -y g++-${new}
b32b8144
FG
102 fi
103
eafe8130 104 case "$codename" in
11fdf7f2 105 trusty)
b32b8144 106 old=4.8;;
11fdf7f2 107 xenial)
b32b8144 108 old=5;;
9f95a23c
TL
109 bionic)
110 old=7;;
b32b8144 111 esac
b32b8144
FG
112 $SUDO update-alternatives --remove-all gcc || true
113 $SUDO update-alternatives \
114 --install /usr/bin/gcc gcc /usr/bin/gcc-${new} 20 \
115 --slave /usr/bin/g++ g++ /usr/bin/g++-${new}
116
11fdf7f2
TL
117 if [ -f /usr/bin/g++-${old} ]; then
118 $SUDO update-alternatives \
119 --install /usr/bin/gcc gcc /usr/bin/gcc-${old} 10 \
120 --slave /usr/bin/g++ g++ /usr/bin/g++-${old}
121 fi
b32b8144
FG
122
123 $SUDO update-alternatives --auto gcc
124
125 # cmake uses the latter by default
eafe8130
TL
126 $SUDO ln -nsf /usr/bin/gcc /usr/bin/${ARCH}-linux-gnu-gcc
127 $SUDO ln -nsf /usr/bin/g++ /usr/bin/${ARCH}-linux-gnu-g++
11fdf7f2
TL
128}
129
f67539c2
TL
130function ensure_python3_sphinx_on_ubuntu {
131 local sphinx_command=/usr/bin/sphinx-build
132 # python-sphinx points $sphinx_command to
133 # ../share/sphinx/scripts/python2/sphinx-build when it's installed
134 # let's "correct" this
135 if test -e $sphinx_command && head -n1 $sphinx_command | grep -q python$; then
136 $SUDO env DEBIAN_FRONTEND=noninteractive apt-get -y remove python-sphinx
137 fi
138}
139
11fdf7f2
TL
140function install_pkg_on_ubuntu {
141 local project=$1
142 shift
143 local sha1=$1
144 shift
145 local codename=$1
146 shift
9f95a23c
TL
147 local force=$1
148 shift
11fdf7f2
TL
149 local pkgs=$@
150 local missing_pkgs
9f95a23c
TL
151 if [ $force = "force" ]; then
152 missing_pkgs="$@"
153 else
154 for pkg in $pkgs; do
155 if ! apt -qq list $pkg 2>/dev/null | grep -q installed; then
156 missing_pkgs+=" $pkg"
157 fi
158 done
159 fi
11fdf7f2
TL
160 if test -n "$missing_pkgs"; then
161 local shaman_url="https://shaman.ceph.com/api/repos/${project}/master/${sha1}/ubuntu/${codename}/repo"
162 $SUDO curl --silent --location $shaman_url --output /etc/apt/sources.list.d/$project.list
163 $SUDO env DEBIAN_FRONTEND=noninteractive apt-get update -y -o Acquire::Languages=none -o Acquire::Translation=none || true
164 $SUDO env DEBIAN_FRONTEND=noninteractive apt-get install --allow-unauthenticated -y $missing_pkgs
165 fi
b32b8144
FG
166}
167
11fdf7f2 168function install_boost_on_ubuntu {
20effc67 169 local ver=1.75
f67539c2
TL
170 local installed_ver=$(apt -qq list --installed ceph-libboost*-dev 2>/dev/null |
171 grep -e 'libboost[0-9].[0-9]\+-dev' |
172 cut -d' ' -f2 |
173 cut -d'.' -f1,2)
174 if test -n "$installed_ver"; then
175 if echo "$installed_ver" | grep -q "^$ver"; then
176 return
177 else
178 $SUDO env DEBIAN_FRONTEND=noninteractive apt-get -y remove "ceph-libboost.*${installed_ver}.*"
179 $SUDO rm -f /etc/apt/sources.list.d/ceph-libboost${installed_ver}.list
180 fi
92f5a8d4 181 fi
f67539c2 182 local codename=$1
92f5a8d4 183 local project=libboost
f67539c2 184 local sha1=7aba8a1882670522ee1d1ee1bba0ea170b292dec
11fdf7f2 185 install_pkg_on_ubuntu \
92f5a8d4
TL
186 $project \
187 $sha1 \
11fdf7f2 188 $codename \
9f95a23c 189 check \
92f5a8d4
TL
190 ceph-libboost-atomic$ver-dev \
191 ceph-libboost-chrono$ver-dev \
192 ceph-libboost-container$ver-dev \
193 ceph-libboost-context$ver-dev \
194 ceph-libboost-coroutine$ver-dev \
195 ceph-libboost-date-time$ver-dev \
196 ceph-libboost-filesystem$ver-dev \
197 ceph-libboost-iostreams$ver-dev \
198 ceph-libboost-program-options$ver-dev \
199 ceph-libboost-python$ver-dev \
200 ceph-libboost-random$ver-dev \
201 ceph-libboost-regex$ver-dev \
202 ceph-libboost-system$ver-dev \
203 ceph-libboost-test$ver-dev \
204 ceph-libboost-thread$ver-dev \
205 ceph-libboost-timer$ver-dev
11fdf7f2
TL
206}
207
f67539c2
TL
208function install_libzbd_on_ubuntu {
209 local codename=$1
210 local project=libzbd
211 local sha1=1fadde94b08fab574b17637c2bebd2b1e7f9127b
212 install_pkg_on_ubuntu \
213 $project \
214 $sha1 \
215 $codename \
216 check \
217 libzbd-dev
11fdf7f2
TL
218}
219
f67539c2
TL
220function version_lt {
221 test $1 != $(echo -e "$1\n$2" | sort -rV | head -n 1)
11fdf7f2
TL
222}
223
9f95a23c
TL
224for_make_check=false
225if tty -s; then
226 # interactive
227 for_make_check=true
228elif [ $FOR_MAKE_CHECK ]; then
229 for_make_check=true
230else
231 for_make_check=false
232fi
233
11fdf7f2 234if [ x$(uname)x = xFreeBSDx ]; then
7c673cae 235 $SUDO pkg install -yq \
c07f9fc5 236 devel/babeltrace \
11fdf7f2 237 devel/binutils \
7c673cae 238 devel/git \
31f18b77 239 devel/gperf \
7c673cae
FG
240 devel/gmake \
241 devel/cmake \
f67539c2 242 devel/nasm \
7c673cae
FG
243 devel/boost-all \
244 devel/boost-python-libs \
245 devel/valgrind \
246 devel/pkgconf \
7c673cae
FG
247 devel/libedit \
248 devel/libtool \
249 devel/google-perftools \
250 lang/cython \
7c673cae 251 databases/leveldb \
11fdf7f2 252 net/openldap24-client \
7c673cae 253 archivers/snappy \
11fdf7f2 254 archivers/liblz4 \
7c673cae
FG
255 ftp/curl \
256 misc/e2fsprogs-libuuid \
257 misc/getopt \
224ce89b 258 net/socat \
7c673cae
FG
259 textproc/expat2 \
260 textproc/gsed \
f64942e4 261 lang/gawk \
7c673cae
FG
262 textproc/libxml2 \
263 textproc/xmlstarlet \
c07f9fc5
FG
264 textproc/jq \
265 textproc/py-sphinx \
7c673cae
FG
266 emulators/fuse \
267 java/junit \
11fdf7f2 268 lang/python36 \
c07f9fc5 269 devel/py-pip \
11fdf7f2 270 devel/py-flake8 \
9f95a23c 271 devel/py-tox \
7c673cae
FG
272 devel/py-argparse \
273 devel/py-nose \
c07f9fc5 274 devel/py-prettytable \
20effc67 275 devel/py-yaml \
11fdf7f2 276 www/py-routes \
7c673cae 277 www/py-flask \
11fdf7f2
TL
278 www/node \
279 www/npm \
7c673cae 280 www/fcgi \
11fdf7f2 281 security/nss \
9f95a23c 282 security/krb5 \
11fdf7f2 283 security/oath-toolkit \
7c673cae
FG
284 sysutils/flock \
285 sysutils/fusefs-libs \
286
31f18b77
FG
287 # Now use pip to install some extra python modules
288 pip install pecan
289
7c673cae
FG
290 exit
291else
9f95a23c 292 [ $WITH_SEASTAR ] && with_seastar=true || with_seastar=false
f67539c2
TL
293 [ $WITH_JAEGER ] && with_jaeger=true || with_jaeger=false
294 [ $WITH_ZBD ] && with_zbd=true || with_zbd=false
7c673cae 295 source /etc/os-release
eafe8130 296 case "$ID" in
20effc67 297 debian|ubuntu|devuan|elementary|softiron)
7c673cae 298 echo "Using apt-get to install dependencies"
11fdf7f2
TL
299 $SUDO apt-get install -y devscripts equivs
300 $SUDO apt-get install -y dpkg-dev
f67539c2 301 ensure_python3_sphinx_on_ubuntu
b32b8144 302 case "$VERSION" in
11fdf7f2 303 *Bionic*)
9f95a23c
TL
304 ensure_decent_gcc_on_ubuntu 9 bionic
305 [ ! $NO_BOOST_PKGS ] && install_boost_on_ubuntu bionic
f67539c2 306 $with_zbd && install_libzbd_on_ubuntu bionic
11fdf7f2 307 ;;
20effc67
TL
308 *Focal*)
309 [ ! $NO_BOOST_PKGS ] && install_boost_on_ubuntu focal
310 $with_zbd && install_libzbd_on_ubuntu focal
20effc67 311 ;;
11fdf7f2
TL
312 *)
313 $SUDO apt-get install -y gcc
b32b8144
FG
314 ;;
315 esac
7c673cae
FG
316 if ! test -r debian/control ; then
317 echo debian/control is not a readable file
318 exit 1
319 fi
320 touch $DIR/status
321
322 backports=""
20effc67 323 control=$(munge_debian_control "$VERSION" "debian/control")
11fdf7f2
TL
324 case "$VERSION" in
325 *squeeze*|*wheezy*)
326 backports="-t $codename-backports"
7c673cae
FG
327 ;;
328 esac
329
330 # make a metapackage that expresses the build dependencies,
331 # install it, rm the .deb; then uninstall the package as its
332 # work is done
20effc67
TL
333 build_profiles=""
334 if $for_make_check; then
335 build_profiles+=",pkg.ceph.check"
336 fi
337 if $with_seastar; then
338 build_profiles+=",pkg.ceph.crimson"
339 fi
340 if $with_jaeger; then
341 build_profiles+=",pkg.ceph.jaeger"
342 fi
343
344 $SUDO env DEBIAN_FRONTEND=noninteractive mk-build-deps \
345 --build-profiles "${build_profiles#,}" \
346 --install --remove \
347 --tool="apt-get -y --no-install-recommends $backports" $control || exit 1
7c673cae 348 $SUDO env DEBIAN_FRONTEND=noninteractive apt-get -y remove ceph-build-deps
11fdf7f2 349 if [ "$control" != "debian/control" ] ; then rm $control; fi
7c673cae
FG
350 ;;
351 centos|fedora|rhel|ol|virtuozzo)
9f95a23c 352 builddepcmd="dnf -y builddep --allowerasing"
f67539c2 353 echo "Using dnf to install dependencies"
eafe8130 354 case "$ID" in
11fdf7f2 355 fedora)
f67539c2 356 $SUDO dnf install -y dnf-utils
7c673cae 357 ;;
11fdf7f2
TL
358 centos|rhel|ol|virtuozzo)
359 MAJOR_VERSION="$(echo $VERSION_ID | cut -d. -f1)"
2a845540 360 $SUDO dnf install -y dnf-utils selinux-policy-targeted
eafe8130 361 rpm --quiet --query epel-release || \
f67539c2 362 $SUDO dnf -y install --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-$MAJOR_VERSION.noarch.rpm
7c673cae
FG
363 $SUDO rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$MAJOR_VERSION
364 $SUDO rm -f /etc/yum.repos.d/dl.fedoraproject.org*
f67539c2 365 if test $ID = centos -a $MAJOR_VERSION = 8 ; then
adb31ebb
TL
366 # Enable 'powertools' or 'PowerTools' repo
367 $SUDO dnf config-manager --set-enabled $(dnf repolist --all 2>/dev/null|gawk 'tolower($0) ~ /^powertools\s/{print $1}')
9f95a23c
TL
368 # before EPEL8 and PowerTools provide all dependencies, we use sepia for the dependencies
369 $SUDO dnf config-manager --add-repo http://apt-mirror.front.sepia.ceph.com/lab-extras/8/
370 $SUDO dnf config-manager --setopt=apt-mirror.front.sepia.ceph.com_lab-extras_8_.gpgcheck=0 --save
9f95a23c 371 elif test $ID = rhel -a $MAJOR_VERSION = 8 ; then
20effc67 372 $SUDO dnf config-manager --set-enabled "codeready-builder-for-rhel-8-${ARCH}-rpms"
9f95a23c
TL
373 $SUDO dnf config-manager --add-repo http://apt-mirror.front.sepia.ceph.com/lab-extras/8/
374 $SUDO dnf config-manager --setopt=apt-mirror.front.sepia.ceph.com_lab-extras_8_.gpgcheck=0 --save
7c673cae
FG
375 fi
376 ;;
377 esac
20effc67 378 munge_ceph_spec_in $with_seastar $with_zbd $for_make_check $with_jaeger $DIR/ceph.spec
9f95a23c 379 # for python3_pkgversion macro defined by python-srpm-macros, which is required by python3-devel
f67539c2 380 $SUDO dnf install -y python3-devel
7c673cae 381 $SUDO $builddepcmd $DIR/ceph.spec 2>&1 | tee $DIR/yum-builddep.out
11fdf7f2 382 [ ${PIPESTATUS[0]} -ne 0 ] && exit 1
9f95a23c 383 IGNORE_YUM_BUILDEP_ERRORS="ValueError: SELinux policy is not managed or store cannot be accessed."
2a845540 384 sed "/$IGNORE_YUM_BUILDEP_ERRORS/d" $DIR/yum-builddep.out | grep -i "error:" && exit 1
7c673cae 385 ;;
1adf2230 386 opensuse*|suse|sles)
7c673cae 387 echo "Using zypper to install dependencies"
11fdf7f2 388 zypp_install="zypper --gpg-auto-import-keys --non-interactive install --no-recommends"
92f5a8d4 389 $SUDO $zypp_install systemd-rpm-macros rpm-build || exit 1
20effc67 390 munge_ceph_spec_in $with_seastar false $for_make_check $with_jaeger $DIR/ceph.spec
11fdf7f2 391 $SUDO $zypp_install $(rpmspec -q --buildrequires $DIR/ceph.spec) || exit 1
7c673cae 392 ;;
7c673cae
FG
393 *)
394 echo "$ID is unknown, dependencies will have to be installed manually."
395 exit 1
396 ;;
397 esac
398fi
399
400function populate_wheelhouse() {
401 local install=$1
402 shift
403
404 # although pip comes with virtualenv, having a recent version
405 # of pip matters when it comes to using wheel packages
9f95a23c
TL
406 PIP_OPTS="--timeout 300 --exists-action i"
407 pip $PIP_OPTS $install \
20effc67 408 'setuptools >= 0.8' 'pip >= 21.0' 'wheel >= 0.24' 'tox >= 2.9.1' || return 1
7c673cae 409 if test $# != 0 ; then
20effc67
TL
410 # '--use-feature=fast-deps --use-deprecated=legacy-resolver' added per
411 # https://github.com/pypa/pip/issues/9818 These should be able to be
412 # removed at some point in the future.
413 pip --use-feature=fast-deps --use-deprecated=legacy-resolver $PIP_OPTS $install $@ || return 1
7c673cae
FG
414 fi
415}
416
417function activate_virtualenv() {
418 local top_srcdir=$1
9f95a23c 419 local env_dir=$top_srcdir/install-deps-python3
7c673cae
FG
420
421 if ! test -d $env_dir ; then
a4b75251 422 python3 -m venv ${env_dir}
7c673cae
FG
423 . $env_dir/bin/activate
424 if ! populate_wheelhouse install ; then
425 rm -rf $env_dir
426 return 1
427 fi
428 fi
429 . $env_dir/bin/activate
430}
431
9f95a23c
TL
432function preload_wheels_for_tox() {
433 local ini=$1
434 shift
435 pushd . > /dev/null
436 cd $(dirname $ini)
437 local require_files=$(ls *requirements*.txt 2>/dev/null) || true
438 local constraint_files=$(ls *constraints*.txt 2>/dev/null) || true
439 local require=$(echo -n "$require_files" | sed -e 's/^/-r /')
440 local constraint=$(echo -n "$constraint_files" | sed -e 's/^/-c /')
441 local md5=wheelhouse/md5
442 if test "$require"; then
443 if ! test -f $md5 || ! md5sum -c $md5 > /dev/null; then
444 rm -rf wheelhouse
445 fi
446 fi
447 if test "$require" && ! test -d wheelhouse ; then
448 type python3 > /dev/null 2>&1 || continue
449 activate_virtualenv $top_srcdir || exit 1
450 populate_wheelhouse "wheel -w $wip_wheelhouse" $require $constraint || exit 1
451 mv $wip_wheelhouse wheelhouse
452 md5sum $require_files $constraint_files > $md5
453 fi
454 popd > /dev/null
455}
456
7c673cae
FG
457# use pip cache if possible but do not store it outside of the source
458# tree
459# see https://pip.pypa.io/en/stable/reference/pip_install.html#caching
9f95a23c
TL
460if $for_make_check; then
461 mkdir -p install-deps-cache
462 top_srcdir=$(pwd)
463 export XDG_CACHE_HOME=$top_srcdir/install-deps-cache
464 wip_wheelhouse=wheelhouse-wip
465 #
466 # preload python modules so that tox can run without network access
467 #
468 find . -name tox.ini | while read ini ; do
469 preload_wheels_for_tox $ini
470 done
471 rm -rf $top_srcdir/install-deps-python3
472 rm -rf $XDG_CACHE_HOME
473 type git > /dev/null || (echo "Dashboard uses git to pull dependencies." ; false)
474fi