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