]> git.proxmox.com Git - ceph.git/blob - ceph/install-deps.sh
9ead1056d97dfb5f7671e86476f8353d62f78b4d
[ceph.git] / ceph / install-deps.sh
1 #!/bin/bash -e
2 #
3 # Ceph distributed storage system
4 #
5 # Copyright (C) 2014, 2015 Red Hat <contact@redhat.com>
6 #
7 # Author: Loic Dachary <loic@dachary.org>
8 #
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
13 #
14 DIR=/tmp/install-deps.$$
15 trap "rm -fr $DIR" EXIT
16 mkdir -p $DIR
17 if test $(id -u) != 0 ; then
18 SUDO=sudo
19 fi
20 export LC_ALL=C # the following is vulnerable to i18n
21
22 function munge_ceph_spec_in {
23 local OUTFILE=$1
24 sed -e 's/@//g' -e 's/%bcond_with make_check/%bcond_without make_check/g' < ceph.spec.in > $OUTFILE
25 }
26
27 function ensure_decent_gcc_on_deb {
28 # point gcc to the one offered by distro if the used one is different
29 local old=$(gcc -dumpversion)
30 local new=$1
31 if dpkg --compare-versions $old eq $new; then
32 return
33 fi
34
35 case $old in
36 4*)
37 old=4.8;;
38 5*)
39 old=5;;
40 7*)
41 old=7;;
42 esac
43
44 cat <<EOF
45 /usr/bin/gcc now points to gcc-$old, which is not the version shipped with the
46 distro: gcc-$new. Reverting...
47 EOF
48
49 $SUDO update-alternatives --remove-all gcc || true
50 $SUDO update-alternatives \
51 --install /usr/bin/gcc gcc /usr/bin/gcc-${new} 20 \
52 --slave /usr/bin/g++ g++ /usr/bin/g++-${new}
53
54 $SUDO update-alternatives \
55 --install /usr/bin/gcc gcc /usr/bin/gcc-${old} 10 \
56 --slave /usr/bin/g++ g++ /usr/bin/g++-${old}
57
58 $SUDO update-alternatives --auto gcc
59
60 # cmake uses the latter by default
61 $SUDO ln -nsf /usr/bin/gcc /usr/bin/x86_64-linux-gnu-gcc
62 $SUDO ln -nsf /usr/bin/g++ /usr/bin/x86_64-linux-gnu-g++
63 }
64
65 if [ x`uname`x = xFreeBSDx ]; then
66 $SUDO pkg install -yq \
67 devel/babeltrace \
68 devel/git \
69 devel/gperf \
70 devel/gmake \
71 devel/cmake \
72 devel/yasm \
73 devel/boost-all \
74 devel/boost-python-libs \
75 devel/valgrind \
76 devel/pkgconf \
77 devel/libedit \
78 devel/libtool \
79 devel/google-perftools \
80 lang/cython \
81 devel/py-virtualenv \
82 databases/leveldb \
83 net/openldap-client \
84 security/nss \
85 security/cryptopp \
86 archivers/snappy \
87 ftp/curl \
88 misc/e2fsprogs-libuuid \
89 misc/getopt \
90 net/socat \
91 textproc/expat2 \
92 textproc/gsed \
93 textproc/libxml2 \
94 textproc/xmlstarlet \
95 textproc/jq \
96 textproc/py-sphinx \
97 emulators/fuse \
98 java/junit \
99 lang/python \
100 lang/python27 \
101 devel/py-pip \
102 devel/py-argparse \
103 devel/py-nose \
104 devel/py-prettytable \
105 www/py-flask \
106 www/fcgi \
107 sysutils/flock \
108 sysutils/fusefs-libs \
109
110 # Now use pip to install some extra python modules
111 pip install pecan
112
113 exit
114 else
115 source /etc/os-release
116 case $ID in
117 debian|ubuntu|devuan)
118 echo "Using apt-get to install dependencies"
119 $SUDO apt-get install -y lsb-release devscripts equivs
120 $SUDO apt-get install -y dpkg-dev gcc
121 case "$VERSION" in
122 *Trusty*)
123 ensure_decent_gcc_on_deb 4.8
124 ;;
125 *Xenial*)
126 ensure_decent_gcc_on_deb 5
127 ;;
128 esac
129 if ! test -r debian/control ; then
130 echo debian/control is not a readable file
131 exit 1
132 fi
133 touch $DIR/status
134
135 backports=""
136 control="debian/control"
137 case $(lsb_release -sc) in
138 squeeze|wheezy)
139 control="/tmp/control.$$"
140 grep -v babeltrace debian/control > $control
141 backports="-t $(lsb_release -sc)-backports"
142 ;;
143 esac
144
145 # make a metapackage that expresses the build dependencies,
146 # install it, rm the .deb; then uninstall the package as its
147 # work is done
148 $SUDO env DEBIAN_FRONTEND=noninteractive mk-build-deps --install --remove --tool="apt-get -y --no-install-recommends $backports" $control || exit 1
149 $SUDO env DEBIAN_FRONTEND=noninteractive apt-get -y remove ceph-build-deps
150 if [ -n "$backports" ] ; then rm $control; fi
151 ;;
152 centos|fedora|rhel|ol|virtuozzo)
153 yumdnf="yum"
154 builddepcmd="yum-builddep -y"
155 if test "$(echo "$VERSION_ID >= 22" | bc)" -ne 0; then
156 yumdnf="dnf"
157 builddepcmd="dnf -y builddep --allowerasing"
158 fi
159 echo "Using $yumdnf to install dependencies"
160 $SUDO $yumdnf install -y redhat-lsb-core
161 case $(lsb_release -si) in
162 Fedora)
163 if test $yumdnf = yum; then
164 $SUDO $yumdnf install -y yum-utils
165 fi
166 ;;
167 CentOS|RedHatEnterpriseServer|VirtuozzoLinux)
168 $SUDO yum install -y yum-utils
169 MAJOR_VERSION=$(lsb_release -rs | cut -f1 -d.)
170 if test $(lsb_release -si) = RedHatEnterpriseServer ; then
171 $SUDO yum install subscription-manager
172 $SUDO subscription-manager repos --enable=rhel-$MAJOR_VERSION-server-optional-rpms
173 fi
174 $SUDO yum-config-manager --add-repo https://dl.fedoraproject.org/pub/epel/$MAJOR_VERSION/x86_64/
175 $SUDO yum install --nogpgcheck -y epel-release
176 $SUDO rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$MAJOR_VERSION
177 $SUDO rm -f /etc/yum.repos.d/dl.fedoraproject.org*
178 if test $(lsb_release -si) = CentOS -a $MAJOR_VERSION = 7 ; then
179 $SUDO yum-config-manager --enable cr
180 fi
181 if test $(lsb_release -si) = VirtuozzoLinux -a $MAJOR_VERSION = 7 ; then
182 $SUDO yum-config-manager --enable cr
183 fi
184 ;;
185 esac
186 munge_ceph_spec_in $DIR/ceph.spec
187 $SUDO $builddepcmd $DIR/ceph.spec 2>&1 | tee $DIR/yum-builddep.out
188 ! grep -q -i error: $DIR/yum-builddep.out || exit 1
189 ;;
190 opensuse*|suse|sles)
191 echo "Using zypper to install dependencies"
192 $SUDO zypper --gpg-auto-import-keys --non-interactive install lsb-release systemd-rpm-macros
193 munge_ceph_spec_in $DIR/ceph.spec
194 $SUDO zypper --non-interactive install $(rpmspec -q --buildrequires $DIR/ceph.spec) || exit 1
195 ;;
196 alpine)
197 # for now we need the testing repo for leveldb
198 TESTREPO="http://nl.alpinelinux.org/alpine/edge/testing"
199 if ! grep -qF "$TESTREPO" /etc/apk/repositories ; then
200 $SUDO echo "$TESTREPO" | sudo tee -a /etc/apk/repositories > /dev/null
201 fi
202 source alpine/APKBUILD.in
203 $SUDO apk --update add abuild build-base ccache $makedepends
204 if id -u build >/dev/null 2>&1 ; then
205 $SUDO addgroup build abuild
206 fi
207 ;;
208 *)
209 echo "$ID is unknown, dependencies will have to be installed manually."
210 exit 1
211 ;;
212 esac
213 fi
214
215 function populate_wheelhouse() {
216 local install=$1
217 shift
218
219 # although pip comes with virtualenv, having a recent version
220 # of pip matters when it comes to using wheel packages
221 # workaround of https://github.com/pypa/setuptools/issues/1042
222 pip --timeout 300 $install 'setuptools >= 0.8,< 36' 'pip >= 7.0' 'wheel >= 0.24' || return 1
223 if test $# != 0 ; then
224 pip --timeout 300 $install $@ || return 1
225 fi
226 }
227
228 function activate_virtualenv() {
229 local top_srcdir=$1
230 local interpreter=$2
231 local env_dir=$top_srcdir/install-deps-$interpreter
232
233 if ! test -d $env_dir ; then
234 # Make a temporary virtualenv to get a fresh version of virtualenv
235 # because CentOS 7 has a buggy old version (v1.10.1)
236 # https://github.com/pypa/virtualenv/issues/463
237 virtualenv ${env_dir}_tmp
238 ${env_dir}_tmp/bin/pip install --upgrade virtualenv
239 ${env_dir}_tmp/bin/virtualenv --python $interpreter $env_dir
240 rm -rf ${env_dir}_tmp
241
242 . $env_dir/bin/activate
243 if ! populate_wheelhouse install ; then
244 rm -rf $env_dir
245 return 1
246 fi
247 fi
248 . $env_dir/bin/activate
249 }
250
251 # use pip cache if possible but do not store it outside of the source
252 # tree
253 # see https://pip.pypa.io/en/stable/reference/pip_install.html#caching
254 mkdir -p install-deps-cache
255 top_srcdir=$(pwd)
256 export XDG_CACHE_HOME=$top_srcdir/install-deps-cache
257 wip_wheelhouse=wheelhouse-wip
258
259 #
260 # preload python modules so that tox can run without network access
261 #
262 find . -name tox.ini | while read ini ; do
263 (
264 cd $(dirname $ini)
265 require=$(ls *requirements.txt 2>/dev/null | sed -e 's/^/-r /')
266 if test "$require" && ! test -d wheelhouse ; then
267 for interpreter in python2.7 python3 ; do
268 type $interpreter > /dev/null 2>&1 || continue
269 activate_virtualenv $top_srcdir $interpreter || exit 1
270 populate_wheelhouse "wheel -w $wip_wheelhouse" $require || exit 1
271 done
272 mv $wip_wheelhouse wheelhouse
273 fi
274 )
275 done
276
277 for interpreter in python2.7 python3 ; do
278 rm -rf $top_srcdir/install-deps-$interpreter
279 done
280 rm -rf $XDG_CACHE_HOME