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