]> git.proxmox.com Git - ceph.git/blob - ceph/install-deps.sh
import ceph quincy 17.2.4
[ceph.git] / ceph / install-deps.sh
1 #!/usr/bin/env bash
2 # -*- mode:sh; tab-width:8; indent-tabs-mode:t -*-
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 #
15 set -e
16 DIR=/tmp/install-deps.$$
17 trap "rm -fr $DIR" EXIT
18 mkdir -p $DIR
19 if test $(id -u) != 0 ; then
20 SUDO=sudo
21 fi
22 export LC_ALL=C # the following is vulnerable to i18n
23
24 ARCH=$(uname -m)
25
26 function munge_ceph_spec_in {
27 local with_seastar=$1
28 shift
29 local with_zbd=$1
30 shift
31 local for_make_check=$1
32 shift
33 local with_jaeger=$1
34 shift
35 local OUTFILE=$1
36 sed -e 's/@//g' < ceph.spec.in > $OUTFILE
37 # http://rpm.org/user_doc/conditional_builds.html
38 if $with_seastar; then
39 sed -i -e 's/%bcond_with seastar/%bcond_without seastar/g' $OUTFILE
40 fi
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
47 if $for_make_check; then
48 sed -i -e 's/%bcond_with make_check/%bcond_without make_check/g' $OUTFILE
49 fi
50 }
51
52 function munge_debian_control {
53 local version=$1
54 shift
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
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
66 echo $control
67 }
68
69 function 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)
73 local new=$1
74 local codename=$2
75 if dpkg --compare-versions $old ge ${new}.0; then
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
81 deb [lang=none] http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu $codename main
82 deb [arch=amd64 lang=none] http://mirror.nullivex.com/ppa/ubuntu-toolchain-r-test $codename main
83 EOF
84 # import PPA's signing key into APT's keyring
85 cat << ENDOFKEY | $SUDO apt-key add -
86 -----BEGIN PGP PUBLIC KEY BLOCK-----
87 Version: SKS 1.1.6
88 Comment: Hostname: keyserver.ubuntu.com
89
90 mI0ESuBvRwEEAMi4cDba7xlKaaoXjO1n1HX8RKrkW+HEIl79nSOSJyvzysajs7zUow/OzCQp
91 9NswqrDmNuH1+lPTTRNAGtK8r2ouq2rnXT1mTl23dpgHZ9spseR73s4ZBGw/ag4bpU5dNUSt
92 vfmHhIjVCuiSpNn7cyy1JSSvSs3N2mxteKjXLBf7ABEBAAG0GkxhdW5jaHBhZCBUb29sY2hh
93 aW4gYnVpbGRziLYEEwECACAFAkrgb0cCGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAAKCRAe
94 k3eiup7yfzGKA/4xzUqNACSlB+k+DxFFHqkwKa/ziFiAlkLQyyhm+iqz80htRZr7Ls/ZRYZl
95 0aSU56/hLe0V+TviJ1s8qdN2lamkKdXIAFfavA04nOnTzyIBJ82EAUT3Nh45skMxo4z4iZMN
96 msyaQpNl/m/lNtOLhR64v5ZybofB2EWkMxUzX8D/FQ==
97 =LcUQ
98 -----END PGP PUBLIC KEY BLOCK-----
99 ENDOFKEY
100 $SUDO env DEBIAN_FRONTEND=noninteractive apt-get update -y || true
101 $SUDO env DEBIAN_FRONTEND=noninteractive apt-get install -y g++-${new}
102 fi
103
104 case "$codename" in
105 trusty)
106 old=4.8;;
107 xenial)
108 old=5;;
109 bionic)
110 old=7;;
111 esac
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
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
122
123 $SUDO update-alternatives --auto gcc
124
125 # cmake uses the latter by default
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++
128 }
129
130 function 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
140 function install_pkg_on_ubuntu {
141 local project=$1
142 shift
143 local sha1=$1
144 shift
145 local codename=$1
146 shift
147 local force=$1
148 shift
149 local pkgs=$@
150 local missing_pkgs
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
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
166 }
167
168 function install_boost_on_ubuntu {
169 local ver=1.75
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
181 fi
182 local codename=$1
183 local project=libboost
184 local sha1=7aba8a1882670522ee1d1ee1bba0ea170b292dec
185 install_pkg_on_ubuntu \
186 $project \
187 $sha1 \
188 $codename \
189 check \
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
206 }
207
208 function 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
218 }
219
220 function version_lt {
221 test $1 != $(echo -e "$1\n$2" | sort -rV | head -n 1)
222 }
223
224 for_make_check=false
225 if tty -s; then
226 # interactive
227 for_make_check=true
228 elif [ $FOR_MAKE_CHECK ]; then
229 for_make_check=true
230 else
231 for_make_check=false
232 fi
233
234 if [ x$(uname)x = xFreeBSDx ]; then
235 $SUDO pkg install -yq \
236 devel/babeltrace \
237 devel/binutils \
238 devel/git \
239 devel/gperf \
240 devel/gmake \
241 devel/cmake \
242 devel/nasm \
243 devel/boost-all \
244 devel/boost-python-libs \
245 devel/valgrind \
246 devel/pkgconf \
247 devel/libedit \
248 devel/libtool \
249 devel/google-perftools \
250 lang/cython \
251 databases/leveldb \
252 net/openldap24-client \
253 archivers/snappy \
254 archivers/liblz4 \
255 ftp/curl \
256 misc/e2fsprogs-libuuid \
257 misc/getopt \
258 net/socat \
259 textproc/expat2 \
260 textproc/gsed \
261 lang/gawk \
262 textproc/libxml2 \
263 textproc/xmlstarlet \
264 textproc/jq \
265 textproc/py-sphinx \
266 emulators/fuse \
267 java/junit \
268 lang/python36 \
269 devel/py-pip \
270 devel/py-flake8 \
271 devel/py-tox \
272 devel/py-argparse \
273 devel/py-nose \
274 devel/py-prettytable \
275 devel/py-yaml \
276 www/py-routes \
277 www/py-flask \
278 www/node \
279 www/npm \
280 www/fcgi \
281 security/nss \
282 security/krb5 \
283 security/oath-toolkit \
284 sysutils/flock \
285 sysutils/fusefs-libs \
286
287 # Now use pip to install some extra python modules
288 pip install pecan
289
290 exit
291 else
292 [ $WITH_SEASTAR ] && with_seastar=true || with_seastar=false
293 [ $WITH_JAEGER ] && with_jaeger=true || with_jaeger=false
294 [ $WITH_ZBD ] && with_zbd=true || with_zbd=false
295 source /etc/os-release
296 case "$ID" in
297 debian|ubuntu|devuan|elementary|softiron)
298 echo "Using apt-get to install dependencies"
299 $SUDO apt-get install -y devscripts equivs
300 $SUDO apt-get install -y dpkg-dev
301 ensure_python3_sphinx_on_ubuntu
302 case "$VERSION" in
303 *Bionic*)
304 ensure_decent_gcc_on_ubuntu 9 bionic
305 [ ! $NO_BOOST_PKGS ] && install_boost_on_ubuntu bionic
306 $with_zbd && install_libzbd_on_ubuntu bionic
307 ;;
308 *Focal*)
309 [ ! $NO_BOOST_PKGS ] && install_boost_on_ubuntu focal
310 $with_zbd && install_libzbd_on_ubuntu focal
311 ;;
312 *)
313 $SUDO apt-get install -y gcc
314 ;;
315 esac
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=""
323 control=$(munge_debian_control "$VERSION" "debian/control")
324 case "$VERSION" in
325 *squeeze*|*wheezy*)
326 backports="-t $codename-backports"
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
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
348 $SUDO env DEBIAN_FRONTEND=noninteractive apt-get -y remove ceph-build-deps
349 if [ "$control" != "debian/control" ] ; then rm $control; fi
350 ;;
351 centos|fedora|rhel|ol|virtuozzo)
352 builddepcmd="dnf -y builddep --allowerasing"
353 echo "Using dnf to install dependencies"
354 case "$ID" in
355 fedora)
356 $SUDO dnf install -y dnf-utils
357 ;;
358 centos|rhel|ol|virtuozzo)
359 MAJOR_VERSION="$(echo $VERSION_ID | cut -d. -f1)"
360 $SUDO dnf install -y dnf-utils selinux-policy-targeted
361 rpm --quiet --query epel-release || \
362 $SUDO dnf -y install --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-$MAJOR_VERSION.noarch.rpm
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*
365 if test $ID = centos -a $MAJOR_VERSION = 8 ; then
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}')
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
371 elif test $ID = rhel -a $MAJOR_VERSION = 8 ; then
372 $SUDO dnf config-manager --set-enabled "codeready-builder-for-rhel-8-${ARCH}-rpms"
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
375 fi
376 ;;
377 esac
378 munge_ceph_spec_in $with_seastar $with_zbd $for_make_check $with_jaeger $DIR/ceph.spec
379 # for python3_pkgversion macro defined by python-srpm-macros, which is required by python3-devel
380 $SUDO dnf install -y python3-devel
381 $SUDO $builddepcmd $DIR/ceph.spec 2>&1 | tee $DIR/yum-builddep.out
382 [ ${PIPESTATUS[0]} -ne 0 ] && exit 1
383 IGNORE_YUM_BUILDEP_ERRORS="ValueError: SELinux policy is not managed or store cannot be accessed."
384 sed "/$IGNORE_YUM_BUILDEP_ERRORS/d" $DIR/yum-builddep.out | grep -i "error:" && exit 1
385 ;;
386 opensuse*|suse|sles)
387 echo "Using zypper to install dependencies"
388 zypp_install="zypper --gpg-auto-import-keys --non-interactive install --no-recommends"
389 $SUDO $zypp_install systemd-rpm-macros rpm-build || exit 1
390 munge_ceph_spec_in $with_seastar false $for_make_check $with_jaeger $DIR/ceph.spec
391 $SUDO $zypp_install $(rpmspec -q --buildrequires $DIR/ceph.spec) || exit 1
392 ;;
393 *)
394 echo "$ID is unknown, dependencies will have to be installed manually."
395 exit 1
396 ;;
397 esac
398 fi
399
400 function 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
406 PIP_OPTS="--timeout 300 --exists-action i"
407 pip $PIP_OPTS $install \
408 'setuptools >= 0.8' 'pip >= 21.0' 'wheel >= 0.24' 'tox >= 2.9.1' || return 1
409 if test $# != 0 ; then
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
414 fi
415 }
416
417 function activate_virtualenv() {
418 local top_srcdir=$1
419 local env_dir=$top_srcdir/install-deps-python3
420
421 if ! test -d $env_dir ; then
422 python3 -m venv ${env_dir}
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
432 function 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
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
460 if $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)
474 fi