]> git.proxmox.com Git - ceph.git/blob - ceph/install-deps.sh
e73e05f6b534216117d1970cbee76bf5a5102d40
[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 lang/gawk \
94 textproc/libxml2 \
95 textproc/xmlstarlet \
96 textproc/jq \
97 textproc/py-sphinx \
98 emulators/fuse \
99 java/junit \
100 lang/python \
101 lang/python27 \
102 devel/py-pip \
103 devel/py-argparse \
104 devel/py-nose \
105 devel/py-prettytable \
106 www/py-flask \
107 www/fcgi \
108 sysutils/flock \
109 sysutils/fusefs-libs \
110
111 # Now use pip to install some extra python modules
112 pip install pecan
113
114 exit
115 else
116 source /etc/os-release
117 case $ID in
118 debian|ubuntu|devuan)
119 echo "Using apt-get to install dependencies"
120 $SUDO apt-get install -y lsb-release devscripts equivs
121 $SUDO apt-get install -y dpkg-dev gcc
122 case "$VERSION" in
123 *Trusty*)
124 ensure_decent_gcc_on_deb 4.8
125 ;;
126 *Xenial*)
127 ensure_decent_gcc_on_deb 5
128 ;;
129 esac
130 if ! test -r debian/control ; then
131 echo debian/control is not a readable file
132 exit 1
133 fi
134 touch $DIR/status
135
136 backports=""
137 control="debian/control"
138 case $(lsb_release -sc) in
139 squeeze|wheezy)
140 control="/tmp/control.$$"
141 grep -v babeltrace debian/control > $control
142 backports="-t $(lsb_release -sc)-backports"
143 ;;
144 esac
145
146 # make a metapackage that expresses the build dependencies,
147 # install it, rm the .deb; then uninstall the package as its
148 # work is done
149 $SUDO env DEBIAN_FRONTEND=noninteractive mk-build-deps --install --remove --tool="apt-get -y --no-install-recommends $backports" $control || exit 1
150 $SUDO env DEBIAN_FRONTEND=noninteractive apt-get -y remove ceph-build-deps
151 if [ -n "$backports" ] ; then rm $control; fi
152 ;;
153 centos|fedora|rhel|ol|virtuozzo)
154 yumdnf="yum"
155 builddepcmd="yum-builddep -y"
156 if test "$(echo "$VERSION_ID >= 22" | bc)" -ne 0; then
157 yumdnf="dnf"
158 builddepcmd="dnf -y builddep --allowerasing"
159 fi
160 echo "Using $yumdnf to install dependencies"
161 $SUDO $yumdnf install -y redhat-lsb-core
162 case $(lsb_release -si) in
163 Fedora)
164 if test $yumdnf = yum; then
165 $SUDO $yumdnf install -y yum-utils
166 fi
167 ;;
168 CentOS|RedHatEnterpriseServer|VirtuozzoLinux)
169 $SUDO yum install -y yum-utils
170 MAJOR_VERSION=$(lsb_release -rs | cut -f1 -d.)
171 if test $(lsb_release -si) = RedHatEnterpriseServer ; then
172 $SUDO yum install subscription-manager
173 $SUDO subscription-manager repos --enable=rhel-$MAJOR_VERSION-server-optional-rpms
174 fi
175 $SUDO yum-config-manager --add-repo https://dl.fedoraproject.org/pub/epel/$MAJOR_VERSION/x86_64/
176 $SUDO yum install --nogpgcheck -y epel-release
177 $SUDO rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$MAJOR_VERSION
178 $SUDO rm -f /etc/yum.repos.d/dl.fedoraproject.org*
179 if test $(lsb_release -si) = CentOS -a $MAJOR_VERSION = 7 ; then
180 $SUDO yum-config-manager --enable cr
181 fi
182 if test $(lsb_release -si) = VirtuozzoLinux -a $MAJOR_VERSION = 7 ; then
183 $SUDO yum-config-manager --enable cr
184 fi
185 ;;
186 esac
187 munge_ceph_spec_in $DIR/ceph.spec
188 $SUDO $builddepcmd $DIR/ceph.spec 2>&1 | tee $DIR/yum-builddep.out
189 ! grep -q -i error: $DIR/yum-builddep.out || exit 1
190 ;;
191 opensuse*|suse|sles)
192 echo "Using zypper to install dependencies"
193 $SUDO zypper --gpg-auto-import-keys --non-interactive install lsb-release systemd-rpm-macros
194 munge_ceph_spec_in $DIR/ceph.spec
195 $SUDO zypper --non-interactive install $(rpmspec -q --buildrequires $DIR/ceph.spec) || exit 1
196 ;;
197 alpine)
198 # for now we need the testing repo for leveldb
199 TESTREPO="http://nl.alpinelinux.org/alpine/edge/testing"
200 if ! grep -qF "$TESTREPO" /etc/apk/repositories ; then
201 $SUDO echo "$TESTREPO" | sudo tee -a /etc/apk/repositories > /dev/null
202 fi
203 source alpine/APKBUILD.in
204 $SUDO apk --update add abuild build-base ccache $makedepends
205 if id -u build >/dev/null 2>&1 ; then
206 $SUDO addgroup build abuild
207 fi
208 ;;
209 *)
210 echo "$ID is unknown, dependencies will have to be installed manually."
211 exit 1
212 ;;
213 esac
214 fi
215
216 function populate_wheelhouse() {
217 local install=$1
218 shift
219
220 # although pip comes with virtualenv, having a recent version
221 # of pip matters when it comes to using wheel packages
222 # workaround of https://github.com/pypa/setuptools/issues/1042
223 pip --timeout 300 $install 'setuptools >= 0.8,< 36' 'pip >= 7.0' 'wheel >= 0.24' || return 1
224 if test $# != 0 ; then
225 pip --timeout 300 $install $@ || return 1
226 fi
227 }
228
229 function activate_virtualenv() {
230 local top_srcdir=$1
231 local interpreter=$2
232 local env_dir=$top_srcdir/install-deps-$interpreter
233
234 if ! test -d $env_dir ; then
235 # Make a temporary virtualenv to get a fresh version of virtualenv
236 # because CentOS 7 has a buggy old version (v1.10.1)
237 # https://github.com/pypa/virtualenv/issues/463
238 virtualenv ${env_dir}_tmp
239 ${env_dir}_tmp/bin/pip install --upgrade virtualenv
240 ${env_dir}_tmp/bin/virtualenv --python $interpreter $env_dir
241 rm -rf ${env_dir}_tmp
242
243 . $env_dir/bin/activate
244 if ! populate_wheelhouse install ; then
245 rm -rf $env_dir
246 return 1
247 fi
248 fi
249 . $env_dir/bin/activate
250 }
251
252 # use pip cache if possible but do not store it outside of the source
253 # tree
254 # see https://pip.pypa.io/en/stable/reference/pip_install.html#caching
255 mkdir -p install-deps-cache
256 top_srcdir=$(pwd)
257 export XDG_CACHE_HOME=$top_srcdir/install-deps-cache
258 wip_wheelhouse=wheelhouse-wip
259
260 #
261 # preload python modules so that tox can run without network access
262 #
263 find . -name tox.ini | while read ini ; do
264 (
265 cd $(dirname $ini)
266 require=$(ls *requirements.txt 2>/dev/null | sed -e 's/^/-r /')
267 if test "$require" && ! test -d wheelhouse ; then
268 for interpreter in python2.7 python3 ; do
269 type $interpreter > /dev/null 2>&1 || continue
270 activate_virtualenv $top_srcdir $interpreter || exit 1
271 populate_wheelhouse "wheel -w $wip_wheelhouse" $require || exit 1
272 done
273 mv $wip_wheelhouse wheelhouse
274 fi
275 )
276 done
277
278 for interpreter in python2.7 python3 ; do
279 rm -rf $top_srcdir/install-deps-$interpreter
280 done
281 rm -rf $XDG_CACHE_HOME