Merge pull request #19684 from taoCH/wip-librgw-symbolic-link
[ceph.git] / 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 install_seastar_deps {
27     if [ $WITH_SEASTAR ]; then
28         $SUDO env DEBIAN_FRONTEND=noninteractive apt-get install -y \
29               ragel libc-ares-dev libhwloc-dev libnuma-dev libpciaccess-dev \
30               libcrypto++-dev libgnutls28-dev libsctp-dev libprotobuf-dev \
31               protobuf-compiler systemtap-sdt-dev libyaml-cpp-dev
32     fi
33 }
34
35 function munge_ceph_spec_in {
36     local OUTFILE=$1
37     sed -e 's/@//g' -e 's/%bcond_with make_check/%bcond_without make_check/g' < ceph.spec.in > $OUTFILE
38     if type python2 > /dev/null 2>&1 ; then
39         sed -i -e 's/%bcond_with python2/%bcond_without python2/g' $OUTFILE
40     else
41         sed -i -e 's/%bcond_without python2/%bcond_with python2/g' $OUTFILE
42     fi
43     if [ $WITH_SEASTAR ]; then
44         sed -i -e 's/%bcond_with seastar/%bcond_without seastar/g' $OUTFILE
45     fi
46 }
47
48 function ensure_decent_gcc_on_ubuntu {
49     # point gcc to the one offered by g++-7 if the used one is not
50     # new enough
51     local old=$(gcc -dumpfullversion -dumpversion)
52     local new=$1
53     local codename=$2
54     if dpkg --compare-versions $old ge 7.0; then
55         return
56     fi
57
58     if [ ! -f /usr/bin/g++-${new} ]; then
59         $SUDO tee /etc/apt/sources.list.d/ubuntu-toolchain-r.list <<EOF
60 deb [lang=none] http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu $codename main
61 deb [arch=amd64 lang=none] http://mirror.cs.uchicago.edu/ubuntu-toolchain-r $codename main
62 deb [arch=amd64,i386 lang=none] http://mirror.yandex.ru/mirrors/launchpad/ubuntu-toolchain-r $codename main
63 EOF
64         # import PPA's signing key into APT's keyring
65         cat << ENDOFKEY | $SUDO apt-key add -
66 -----BEGIN PGP PUBLIC KEY BLOCK-----
67 Version: SKS 1.1.6
68 Comment: Hostname: keyserver.ubuntu.com
69
70 mI0ESuBvRwEEAMi4cDba7xlKaaoXjO1n1HX8RKrkW+HEIl79nSOSJyvzysajs7zUow/OzCQp
71 9NswqrDmNuH1+lPTTRNAGtK8r2ouq2rnXT1mTl23dpgHZ9spseR73s4ZBGw/ag4bpU5dNUSt
72 vfmHhIjVCuiSpNn7cyy1JSSvSs3N2mxteKjXLBf7ABEBAAG0GkxhdW5jaHBhZCBUb29sY2hh
73 aW4gYnVpbGRziLYEEwECACAFAkrgb0cCGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAAKCRAe
74 k3eiup7yfzGKA/4xzUqNACSlB+k+DxFFHqkwKa/ziFiAlkLQyyhm+iqz80htRZr7Ls/ZRYZl
75 0aSU56/hLe0V+TviJ1s8qdN2lamkKdXIAFfavA04nOnTzyIBJ82EAUT3Nh45skMxo4z4iZMN
76 msyaQpNl/m/lNtOLhR64v5ZybofB2EWkMxUzX8D/FQ==
77 =LcUQ
78 -----END PGP PUBLIC KEY BLOCK-----
79 ENDOFKEY
80         $SUDO env DEBIAN_FRONTEND=noninteractive apt-get update -y || true
81         $SUDO env DEBIAN_FRONTEND=noninteractive apt-get install -y g++-7
82     fi
83
84     case $codename in
85         trusty)
86             old=4.8;;
87         xenial)
88             old=5;;
89     esac
90     $SUDO update-alternatives --remove-all gcc || true
91     $SUDO update-alternatives \
92          --install /usr/bin/gcc gcc /usr/bin/gcc-${new} 20 \
93          --slave   /usr/bin/g++ g++ /usr/bin/g++-${new}
94
95     if [ -f /usr/bin/g++-${old} ]; then
96       $SUDO update-alternatives \
97          --install /usr/bin/gcc gcc /usr/bin/gcc-${old} 10 \
98          --slave   /usr/bin/g++ g++ /usr/bin/g++-${old}
99     fi
100
101     $SUDO update-alternatives --auto gcc
102
103     # cmake uses the latter by default
104     $SUDO ln -nsf /usr/bin/gcc /usr/bin/$(uname -m)-linux-gnu-gcc
105     $SUDO ln -nsf /usr/bin/g++ /usr/bin/$(uname -m)-linux-gnu-g++
106 }
107
108 function install_pkg_on_ubuntu {
109     local project=$1
110     shift
111     local sha1=$1
112     shift
113     local codename=$1
114     shift
115     local pkgs=$@
116     local missing_pkgs
117     for pkg in $pkgs; do
118         if ! dpkg -s $pkg &> /dev/null; then
119             missing_pkgs+=" $pkg"
120         fi
121     done
122     if test -n "$missing_pkgs"; then
123         local shaman_url="https://shaman.ceph.com/api/repos/${project}/master/${sha1}/ubuntu/${codename}/repo"
124         $SUDO curl --silent --location $shaman_url --output /etc/apt/sources.list.d/$project.list
125         $SUDO env DEBIAN_FRONTEND=noninteractive apt-get update -y -o Acquire::Languages=none -o Acquire::Translation=none || true
126         $SUDO env DEBIAN_FRONTEND=noninteractive apt-get install --allow-unauthenticated -y $missing_pkgs
127     fi
128 }
129
130 function install_boost_on_ubuntu {
131     local codename=$1
132     install_pkg_on_ubuntu \
133         ceph-libboost1.67 \
134         dd38c27740c1f9a9e6719a07eef84a1369dc168b \
135         $codename \
136         ceph-libboost-atomic1.67-dev \
137         ceph-libboost-chrono1.67-dev \
138         ceph-libboost-container1.67-dev \
139         ceph-libboost-context1.67-dev \
140         ceph-libboost-coroutine1.67-dev \
141         ceph-libboost-date-time1.67-dev \
142         ceph-libboost-filesystem1.67-dev \
143         ceph-libboost-iostreams1.67-dev \
144         ceph-libboost-program-options1.67-dev \
145         ceph-libboost-python1.67-dev \
146         ceph-libboost-random1.67-dev \
147         ceph-libboost-regex1.67-dev \
148         ceph-libboost-system1.67-dev \
149         ceph-libboost-thread1.67-dev \
150         ceph-libboost-timer1.67-dev
151 }
152
153 function version_lt {
154     test $1 != $(echo -e "$1\n$2" | sort -rV | head -n 1)
155 }
156
157 function ensure_decent_gcc_on_rh {
158     local old=$(gcc -dumpversion)
159     local expected=5.1
160     local dts_ver=$1
161     if version_lt $old $expected; then
162         if test -t 1; then
163             # interactive shell
164             cat <<EOF
165 Your GCC is too old. Please run following command to add DTS to your environment:
166
167 scl enable devtoolset-7 bash
168
169 Or add following line to the end of ~/.bashrc to add it permanently:
170
171 source scl_source enable devtoolset-7
172
173 see https://www.softwarecollections.org/en/scls/rhscl/devtoolset-7/ for more details.
174 EOF
175         else
176             # non-interactive shell
177             source /opt/rh/devtoolset-$dts_ver/enable
178         fi
179     fi
180 }
181
182 if [ x$(uname)x = xFreeBSDx ]; then
183     $SUDO pkg install -yq \
184         devel/babeltrace \
185         devel/git \
186         devel/gperf \
187         devel/gmake \
188         devel/cmake \
189         devel/yasm \
190         devel/boost-all \
191         devel/boost-python-libs \
192         devel/valgrind \
193         devel/pkgconf \
194         devel/libedit \
195         devel/libtool \
196         devel/google-perftools \
197         lang/cython \
198         devel/py-virtualenv \
199         databases/leveldb \
200         net/openldap24-client \
201         security/nss \
202         archivers/snappy \
203         archivers/liblz4 \
204         ftp/curl \
205         misc/e2fsprogs-libuuid \
206         misc/getopt \
207         net/socat \
208         textproc/expat2 \
209         textproc/gsed \
210         lang/gawk \
211         textproc/libxml2 \
212         textproc/xmlstarlet \
213         textproc/jq \
214         textproc/py-sphinx \
215         emulators/fuse \
216         java/junit \
217         lang/python \
218         lang/python27 \
219         devel/py-pip \
220         devel/py-argparse \
221         devel/py-nose \
222         devel/py-prettytable \
223         www/py-routes \
224         www/py-flask \
225         www/node \
226         www/npm \
227         www/fcgi \
228         security/oath-toolkit \
229         sysutils/flock \
230         sysutils/fusefs-libs \
231
232         # Now use pip to install some extra python modules
233         pip install pecan
234
235     exit
236 else
237     source /etc/os-release
238     case $ID in
239     debian|ubuntu|devuan)
240         echo "Using apt-get to install dependencies"
241         $SUDO apt-get install -y devscripts equivs
242         $SUDO apt-get install -y dpkg-dev
243         case "$VERSION" in
244             *Trusty*)
245                 ensure_decent_gcc_on_ubuntu 7 trusty
246                 ;;
247             *Xenial*)
248                 ensure_decent_gcc_on_ubuntu 7 xenial
249                 install_boost_on_ubuntu xenial
250                 ;;
251             *Bionic*)
252                 install_boost_on_ubuntu bionic
253                 ;;
254             *)
255                 $SUDO apt-get install -y gcc
256                 ;;
257         esac
258         if ! test -r debian/control ; then
259             echo debian/control is not a readable file
260             exit 1
261         fi
262         touch $DIR/status
263
264         backports=""
265         control="debian/control"
266         case "$VERSION" in
267             *squeeze*|*wheezy*)
268                 control="/tmp/control.$$"
269                 grep -v babeltrace debian/control > $control
270                 backports="-t $codename-backports"
271                 ;;
272         esac
273
274         # make a metapackage that expresses the build dependencies,
275         # install it, rm the .deb; then uninstall the package as its
276         # work is done
277         $SUDO env DEBIAN_FRONTEND=noninteractive mk-build-deps --install --remove --tool="apt-get -y --no-install-recommends $backports" $control || exit 1
278         $SUDO env DEBIAN_FRONTEND=noninteractive apt-get -y remove ceph-build-deps
279         install_seastar_deps
280         if [ -n "$backports" ] ; then rm $control; fi
281         $SUDO apt-get install -y libxmlsec1 libxmlsec1-nss libxmlsec1-openssl libxmlsec1-dev
282         ;;
283     centos|fedora|rhel|ol|virtuozzo)
284         yumdnf="yum"
285         builddepcmd="yum-builddep -y"
286         if test "$(echo "$VERSION_ID >= 22" | bc)" -ne 0; then
287             yumdnf="dnf"
288             builddepcmd="dnf -y builddep --allowerasing"
289         fi
290         echo "Using $yumdnf to install dependencies"
291         if [ "$ID" = "centos" -a $(uname -m) = aarch64 ]; then
292             $SUDO yum-config-manager --disable centos-sclo-sclo || true
293             $SUDO yum-config-manager --disable centos-sclo-rh || true
294             $SUDO yum remove centos-release-scl || true
295         fi
296
297         case $ID in
298             fedora)
299                 if test $yumdnf = yum; then
300                     $SUDO $yumdnf install -y yum-utils
301                 fi
302                 ;;
303             centos|rhel|ol|virtuozzo)
304                 $SUDO yum install -y yum-utils
305                 if test $ID = rhel ; then
306                     $SUDO yum-config-manager --enable rhel-$VERSION_ID-server-optional-rpms
307                 fi
308                 $SUDO yum-config-manager --add-repo https://dl.fedoraproject.org/pub/epel/$VERSION_ID/x86_64/
309                 $SUDO yum install --nogpgcheck -y epel-release
310                 $SUDO rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$VERSION_ID
311                 $SUDO rm -f /etc/yum.repos.d/dl.fedoraproject.org*
312                 if test $ID = centos -a $VERSION_ID = 7 ; then
313                     $SUDO yum-config-manager --enable cr
314                     case $(uname -m) in
315                         x86_64)
316                             $SUDO yum -y install centos-release-scl
317                             dts_ver=7
318                             ;;
319                         aarch64)
320                             $SUDO yum -y install centos-release-scl-rh
321                             $SUDO yum-config-manager --disable centos-sclo-rh
322                             $SUDO yum-config-manager --enable centos-sclo-rh-testing
323                             dts_ver=7
324                             ;;
325                     esac
326                 elif test $ID = rhel -a $MAJOR_VERSION = 7 ; then
327                     $SUDO yum-config-manager --enable rhel-server-rhscl-7-rpms
328                     dts_ver=7
329                 elif test $ID = virtuozzo -a $MAJOR_VERSION = 7 ; then
330                     $SUDO yum-config-manager --enable cr
331                 fi
332                 ;;
333         esac
334         munge_ceph_spec_in $DIR/ceph.spec
335         $SUDO $builddepcmd $DIR/ceph.spec 2>&1 | tee $DIR/yum-builddep.out
336         [ ${PIPESTATUS[0]} -ne 0 ] && exit 1
337         if [ -n "$dts_ver" ]; then
338             ensure_decent_gcc_on_rh $dts_ver
339         fi
340         ! grep -q -i error: $DIR/yum-builddep.out || exit 1
341         # for building python-saml and its dependencies
342         $SUDO $yumdnf install -y xmlsec1 xmlsec1-nss xmlsec1-openssl xmlsec1-devel xmlsec1-openssl-devel libtool-ltdl-devel
343         ;;
344     opensuse*|suse|sles)
345         echo "Using zypper to install dependencies"
346         zypp_install="zypper --gpg-auto-import-keys --non-interactive install --no-recommends"
347         $SUDO $zypp_install systemd-rpm-macros
348         munge_ceph_spec_in $DIR/ceph.spec
349         $SUDO $zypp_install $(rpmspec -q --buildrequires $DIR/ceph.spec) || exit 1
350         $SUDO $zypp_install libxmlsec1-1 libxmlsec1-nss1 libxmlsec1-openssl1 xmlsec1-devel xmlsec1-openssl-devel
351         ;;
352     alpine)
353         # for now we need the testing repo for leveldb
354         TESTREPO="http://nl.alpinelinux.org/alpine/edge/testing"
355         if ! grep -qF "$TESTREPO" /etc/apk/repositories ; then
356             $SUDO echo "$TESTREPO" | sudo tee -a /etc/apk/repositories > /dev/null
357         fi
358         source alpine/APKBUILD.in
359         $SUDO apk --update add abuild build-base ccache $makedepends
360         if id -u build >/dev/null 2>&1 ; then
361            $SUDO addgroup build abuild
362         fi
363         ;;
364     *)
365         echo "$ID is unknown, dependencies will have to be installed manually."
366         exit 1
367         ;;
368     esac
369 fi
370
371 function populate_wheelhouse() {
372     local install=$1
373     shift
374
375     # although pip comes with virtualenv, having a recent version
376     # of pip matters when it comes to using wheel packages
377     # workaround of https://github.com/pypa/setuptools/issues/1042
378     pip --timeout 300 $install 'setuptools >= 0.8,< 36' 'pip >= 7.0' 'wheel >= 0.24' || return 1
379     if test $# != 0 ; then
380         pip --timeout 300 $install $@ || return 1
381     fi
382 }
383
384 function activate_virtualenv() {
385     local top_srcdir=$1
386     local interpreter=$2
387     local env_dir=$top_srcdir/install-deps-$interpreter
388
389     if ! test -d $env_dir ; then
390         # Make a temporary virtualenv to get a fresh version of virtualenv
391         # because CentOS 7 has a buggy old version (v1.10.1)
392         # https://github.com/pypa/virtualenv/issues/463
393         virtualenv ${env_dir}_tmp
394         # install setuptools before upgrading virtualenv, as the latter needs
395         # a recent setuptools for setup commands like `extras_require`.
396         ${env_dir}_tmp/bin/pip install --upgrade setuptools
397         ${env_dir}_tmp/bin/pip install --upgrade virtualenv
398         ${env_dir}_tmp/bin/virtualenv --python $interpreter $env_dir
399         rm -rf ${env_dir}_tmp
400
401         . $env_dir/bin/activate
402         if ! populate_wheelhouse install ; then
403             rm -rf $env_dir
404             return 1
405         fi
406     fi
407     . $env_dir/bin/activate
408 }
409
410 # use pip cache if possible but do not store it outside of the source
411 # tree
412 # see https://pip.pypa.io/en/stable/reference/pip_install.html#caching
413 mkdir -p install-deps-cache
414 top_srcdir=$(pwd)
415 export XDG_CACHE_HOME=$top_srcdir/install-deps-cache
416 wip_wheelhouse=wheelhouse-wip
417
418 #
419 # preload python modules so that tox can run without network access
420 #
421 find . -name tox.ini | while read ini ; do
422     (
423         cd $(dirname $ini)
424         require=$(ls *requirements.txt 2>/dev/null | sed -e 's/^/-r /')
425         md5=wheelhouse/md5
426         if test "$require"; then
427             if ! test -f $md5 || ! md5sum -c $md5 ; then
428                 rm -rf wheelhouse
429             fi
430         fi
431         if test "$require" && ! test -d wheelhouse ; then
432             for interpreter in python2.7 python3 ; do
433                 type $interpreter > /dev/null 2>&1 || continue
434                 activate_virtualenv $top_srcdir $interpreter || exit 1
435                 populate_wheelhouse "wheel -w $wip_wheelhouse" $require || exit 1
436             done
437             mv $wip_wheelhouse wheelhouse
438             md5sum *requirements.txt > $md5
439         fi
440     )
441 done
442
443 for interpreter in python2.7 python3 ; do
444     rm -rf $top_srcdir/install-deps-$interpreter
445 done
446 rm -rf $XDG_CACHE_HOME
447 git --version || (echo "Dashboard uses git to pull dependencies." ; false)