Advertisement
Hitesh_jadhav

install-deps.sh

Apr 9th, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.79 KB | None | 0 0
  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.75
  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. *Focal*)
  317. [ ! $NO_BOOST_PKGS ] && install_boost_on_ubuntu focal
  318. $with_zbd && install_libzbd_on_ubuntu focal
  319. ;;
  320. *)
  321. $SUDO apt-get install -y gcc
  322. ;;
  323. esac
  324. if ! test -r debian/control ; then
  325. echo debian/control is not a readable file
  326. exit 1
  327. fi
  328. touch $DIR/status
  329.  
  330. backports=""
  331. control=$(munge_debian_control "$VERSION" "$with_seastar" "$for_make_check" "debian/control")
  332. case "$VERSION" in
  333. *squeeze*|*wheezy*)
  334. backports="-t $codename-backports"
  335. ;;
  336. esac
  337.  
  338. # make a metapackage that expresses the build dependencies,
  339. # install it, rm the .deb; then uninstall the package as its
  340. # work is done
  341. $SUDO env DEBIAN_FRONTEND=noninteractive mk-build-deps --install --remove --tool="apt-get -y --no-install-recommends $backports" $control || exit 1
  342. $SUDO env DEBIAN_FRONTEND=noninteractive apt-get -y remove ceph-build-deps
  343. if [ "$control" != "debian/control" ] ; then rm $control; fi
  344. ;;
  345. centos|fedora|rhel|ol|virtuozzo)
  346. builddepcmd="dnf -y builddep --allowerasing"
  347. echo "Using dnf to install dependencies"
  348. case "$ID" in
  349. fedora)
  350. $SUDO dnf install -y dnf-utils
  351. ;;
  352. centos|rhel|ol|virtuozzo)
  353. MAJOR_VERSION="$(echo $VERSION_ID | cut -d. -f1)"
  354. $SUDO dnf install -y dnf-utils
  355. rpm --quiet --query epel-release || \
  356. $SUDO dnf -y install --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-$MAJOR_VERSION.noarch.rpm
  357. $SUDO rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$MAJOR_VERSION
  358. $SUDO rm -f /etc/yum.repos.d/dl.fedoraproject.org*
  359. if test $ID = centos -a $MAJOR_VERSION = 8 ; then
  360. # Enable 'powertools' or 'PowerTools' repo
  361. $SUDO dnf config-manager --set-enabled $(dnf repolist --all 2>/dev/null|gawk 'tolower($0) ~ /^powertools\s/{print $1}')
  362. # before EPEL8 and PowerTools provide all dependencies, we use sepia for the dependencies
  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. elif test $ID = rhel -a $MAJOR_VERSION = 8 ; then
  366. $SUDO dnf config-manager --set-enabled "codeready-builder-for-rhel-8-${ARCH}-rpms"
  367. $SUDO dnf config-manager --add-repo http://apt-mirror.front.sepia.ceph.com/lab-extras/8/
  368. $SUDO dnf config-manager --setopt=apt-mirror.front.sepia.ceph.com_lab-extras_8_.gpgcheck=0 --save
  369. fi
  370. ;;
  371. esac
  372. munge_ceph_spec_in $with_seastar $with_zbd $for_make_check $DIR/ceph.spec
  373. # for python3_pkgversion macro defined by python-srpm-macros, which is required by python3-devel
  374. $SUDO dnf install -y python3-devel
  375. $SUDO $builddepcmd $DIR/ceph.spec 2>&1 | tee $DIR/yum-builddep.out
  376. [ ${PIPESTATUS[0]} -ne 0 ] && exit 1
  377. IGNORE_YUM_BUILDEP_ERRORS="ValueError: SELinux policy is not managed or store cannot be accessed."
  378. sed "/$IGNORE_YUM_BUILDEP_ERRORS/d" $DIR/yum-builddep.out | grep -qi "error:" && exit 1
  379. ;;
  380. opensuse*|suse|sles)
  381. echo "Using zypper to install dependencies"
  382. zypp_install="zypper --gpg-auto-import-keys --non-interactive install --no-recommends"
  383. $SUDO $zypp_install systemd-rpm-macros rpm-build || exit 1
  384. munge_ceph_spec_in $with_seastar false $for_make_check $DIR/ceph.spec
  385. $SUDO $zypp_install $(rpmspec -q --buildrequires $DIR/ceph.spec) || exit 1
  386. ;;
  387. *)
  388. echo "$ID is unknown, dependencies will have to be installed manually."
  389. exit 1
  390. ;;
  391. esac
  392. fi
  393.  
  394. function populate_wheelhouse() {
  395. local install=$1
  396. shift
  397.  
  398. # although pip comes with virtualenv, having a recent version
  399. # of pip matters when it comes to using wheel packages
  400. PIP_OPTS="--timeout 300 --exists-action i"
  401. pip $PIP_OPTS $install \
  402. 'setuptools >= 0.8' 'pip >= 7.0' 'wheel >= 0.24' 'tox >= 2.9.1' || return 1
  403. if test $# != 0 ; then
  404. pip $PIP_OPTS $install $@ || return 1
  405. fi
  406. }
  407.  
  408. function activate_virtualenv() {
  409. local top_srcdir=$1
  410. local env_dir=$top_srcdir/install-deps-python3
  411.  
  412. if ! test -d $env_dir ; then
  413. virtualenv --python=python3 ${env_dir}
  414. . $env_dir/bin/activate
  415. if ! populate_wheelhouse install ; then
  416. rm -rf $env_dir
  417. return 1
  418. fi
  419. fi
  420. . $env_dir/bin/activate
  421. }
  422.  
  423. function preload_wheels_for_tox() {
  424. local ini=$1
  425. shift
  426. pushd . > /dev/null
  427. cd $(dirname $ini)
  428. local require_files=$(ls *requirements*.txt 2>/dev/null) || true
  429. local constraint_files=$(ls *constraints*.txt 2>/dev/null) || true
  430. local require=$(echo -n "$require_files" | sed -e 's/^/-r /')
  431. local constraint=$(echo -n "$constraint_files" | sed -e 's/^/-c /')
  432. local md5=wheelhouse/md5
  433. if test "$require"; then
  434. if ! test -f $md5 || ! md5sum -c $md5 > /dev/null; then
  435. rm -rf wheelhouse
  436. fi
  437. fi
  438. if test "$require" && ! test -d wheelhouse ; then
  439. type python3 > /dev/null 2>&1 || continue
  440. activate_virtualenv $top_srcdir || exit 1
  441. populate_wheelhouse "wheel -w $wip_wheelhouse" $require $constraint || exit 1
  442. mv $wip_wheelhouse wheelhouse
  443. md5sum $require_files $constraint_files > $md5
  444. fi
  445. popd > /dev/null
  446. }
  447.  
  448. # use pip cache if possible but do not store it outside of the source
  449. # tree
  450. # see https://pip.pypa.io/en/stable/reference/pip_install.html#caching
  451. if $for_make_check; then
  452. mkdir -p install-deps-cache
  453. top_srcdir=$(pwd)
  454. export XDG_CACHE_HOME=$top_srcdir/install-deps-cache
  455. wip_wheelhouse=wheelhouse-wip
  456. #
  457. # preload python modules so that tox can run without network access
  458. #
  459. find . -name tox.ini | while read ini ; do
  460. preload_wheels_for_tox $ini
  461. done
  462. rm -rf $top_srcdir/install-deps-python3
  463. rm -rf $XDG_CACHE_HOME
  464. type git > /dev/null || (echo "Dashboard uses git to pull dependencies." ; false)
  465. fi
  466.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement