2015-10-27 01:49:05 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
set -eu
|
|
|
|
set -o pipefail
|
|
|
|
|
2019-03-17 09:54:38 +00:00
|
|
|
if [[ $DISTRO_NAME =~ (opensuse|fedora|centos|centos7|rhel|rhel7) ]]; then
|
2017-04-11 02:05:35 +00:00
|
|
|
|
2018-04-16 03:16:35 +00:00
|
|
|
# Default packages
|
2017-04-11 02:05:35 +00:00
|
|
|
_do_py3=0
|
2018-04-16 03:16:35 +00:00
|
|
|
_extra_repo=''
|
2019-02-22 07:03:50 +00:00
|
|
|
# see notes below on this var...
|
|
|
|
_clear_old_files=0
|
2018-04-16 03:16:35 +00:00
|
|
|
case "$DISTRO_NAME" in
|
|
|
|
centos*|rhel7)
|
|
|
|
# note python2-pip in epel
|
|
|
|
_extra_repo="--enablerepo=epel"
|
2018-04-20 05:16:24 +00:00
|
|
|
packages="python-virtualenv python2-pip"
|
|
|
|
if [[ "$(rpm -q --qf '[%{obsoletes}\n]' python2-setuptools)" == "python-setuptools" ]]; then
|
|
|
|
# If OpenStack release is installed, then python-setuptools is
|
|
|
|
# obsoleted by python2-setuptools
|
|
|
|
packages+=" python2-setuptools"
|
|
|
|
else
|
|
|
|
packages+=" python-setuptools"
|
|
|
|
fi
|
2019-02-22 07:03:50 +00:00
|
|
|
# see notes below
|
|
|
|
_clear_old_files=1
|
2018-04-16 03:16:35 +00:00
|
|
|
;;
|
|
|
|
fedora)
|
2020-04-22 01:08:19 +00:00
|
|
|
if [[ ${DIB_RELEASE} -gt 30 ]]; then
|
|
|
|
echo "This element is not supported for this version of Fedora"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-04-16 03:16:35 +00:00
|
|
|
_do_py3=1
|
|
|
|
packages="python2-virtualenv python2-pip python2-setuptools"
|
2020-02-18 15:23:02 +00:00
|
|
|
packages=" python3-virtualenv python3-pip python3-setuptools"
|
2018-04-16 03:16:35 +00:00
|
|
|
;;
|
2019-03-17 09:54:38 +00:00
|
|
|
rhel)
|
|
|
|
case "$DIB_RELEASE" in
|
|
|
|
8)
|
|
|
|
_do_py3=1
|
2019-07-08 11:24:30 +00:00
|
|
|
_clear_old_files=0
|
2019-03-17 09:54:38 +00:00
|
|
|
packages=" python3-virtualenv python3-pip python3-setuptools"
|
|
|
|
;;
|
|
|
|
7)
|
|
|
|
# note python2-pip in epel
|
|
|
|
_extra_repo="--enablerepo=epel"
|
2019-07-08 11:24:30 +00:00
|
|
|
_clear_old_files=1
|
2019-03-17 09:54:38 +00:00
|
|
|
packages="python-virtualenv python2-pip"
|
|
|
|
if [[ "$(rpm -q --qf '[%{obsoletes}\n]' python2-setuptools)" == "python-setuptools" ]]; then
|
|
|
|
packages+=" python2-setuptools"
|
|
|
|
else
|
|
|
|
packages+=" python-setuptools"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2018-04-16 03:16:35 +00:00
|
|
|
opensuse)
|
|
|
|
case "$DIB_RELEASE" in
|
|
|
|
42*)
|
|
|
|
packages="python-virtualenv python-pip python-setuptools"
|
2019-02-22 07:03:50 +00:00
|
|
|
_clear_old_files=1
|
2018-04-16 03:16:35 +00:00
|
|
|
;;
|
2020-03-31 21:18:56 +00:00
|
|
|
15*)
|
2020-04-22 01:08:19 +00:00
|
|
|
_do_py3=1
|
|
|
|
_clear_old_files=1
|
|
|
|
# python*-six gets dragged in, and then is a
|
|
|
|
# distutils package and won't uninstall. put it
|
|
|
|
# here so it gets cleaned.
|
|
|
|
packages="python2-virtualenv python2-pip python2-setuptools python2-six"
|
|
|
|
packages+=" python3-virtualenv python3-pip python3-setuptools python3-six"
|
2020-03-31 21:18:56 +00:00
|
|
|
;;
|
|
|
|
tumbleweed)
|
2020-04-22 01:08:19 +00:00
|
|
|
echo "This element is not supported for this platform"
|
|
|
|
exit 1
|
2018-04-16 03:16:35 +00:00
|
|
|
;;
|
|
|
|
esac
|
2019-03-17 09:54:38 +00:00
|
|
|
;;
|
2018-04-16 03:16:35 +00:00
|
|
|
esac
|
2017-04-11 02:05:35 +00:00
|
|
|
|
2017-07-18 04:50:09 +00:00
|
|
|
# force things to happen so our assumptions hold
|
|
|
|
pip_args="-U --force-reinstall"
|
|
|
|
|
2016-07-14 03:43:06 +00:00
|
|
|
# GENERAL WARNING : mixing packaged python libraries with
|
|
|
|
# pip-installed versions always creates issues. Upstream
|
|
|
|
# openstack-infra uses this a lot (especially devstack) but be
|
|
|
|
# warned: here be dragons :)
|
|
|
|
|
|
|
|
# Firstly we want to install the system packages. Otherwise later
|
|
|
|
# on somebody does a "yum install python-virtualenv" and goes and
|
|
|
|
# overwrites the pip installed version with the packaged version,
|
|
|
|
# leading to all sorts of weird version issues.
|
2017-02-22 18:59:44 +00:00
|
|
|
if [[ $DISTRO_NAME = opensuse ]]; then
|
2017-06-28 16:59:25 +00:00
|
|
|
zypper -n install $packages
|
2017-02-22 18:59:44 +00:00
|
|
|
else
|
2018-04-16 03:16:35 +00:00
|
|
|
${YUM:-yum} ${_extra_repo} install -y $packages
|
2017-02-22 18:59:44 +00:00
|
|
|
fi
|
2016-07-14 03:43:06 +00:00
|
|
|
|
2019-01-25 05:27:49 +00:00
|
|
|
# pip10 onwards (unlike earlier versions) will not uninstall
|
|
|
|
# packages installed by distutils (note this is only a subset of
|
|
|
|
# packages that don't use setuptools for various reasons; the
|
|
|
|
# problem is essentially they do not include a manifest of files
|
|
|
|
# in the package to delete, so pip was just guessing). We give it
|
|
|
|
# a little help by clearing out the files from the packages we are
|
|
|
|
# about to re-install so pip doesn't think anything is installed.
|
|
|
|
# See: https://github.com/pypa/pip/issues/4805
|
|
|
|
#
|
2019-02-22 07:03:50 +00:00
|
|
|
# This is only necessary on old CentOS and suse -- for complicated
|
|
|
|
# reasons of course. On Fedora, the Python2 virtualenv packages
|
|
|
|
# are *not* distutils based and pip overwrites them correctly.
|
|
|
|
# For python3, pip has changed to not overwrite system packages (a
|
|
|
|
# long standing difference between Debuntu and Fedora), but a
|
|
|
|
# number of tools run with "python3 -Es" to isolate themselves to
|
|
|
|
# the package installed versions. So we definitely don't want to
|
2019-01-25 05:27:49 +00:00
|
|
|
# clear the packaged versions out in that case.
|
2019-02-22 07:03:50 +00:00
|
|
|
if [[ ${_clear_old_files} == 1 ]]; then
|
2019-01-25 05:27:49 +00:00
|
|
|
for pkg in $packages; do
|
|
|
|
rpm -ql $pkg | xargs rm -rf
|
|
|
|
done
|
|
|
|
fi
|
2018-04-16 03:16:35 +00:00
|
|
|
|
2017-04-11 02:05:35 +00:00
|
|
|
# install the latest python2 pip; this overwrites packaged pip
|
2017-07-18 04:50:09 +00:00
|
|
|
python /tmp/get-pip.py ${pip_args}
|
2016-07-14 03:43:06 +00:00
|
|
|
|
2018-04-16 03:16:35 +00:00
|
|
|
# Install latest setuptools; there is a slight chicken-egg issue in
|
|
|
|
# that pip requires setuptools for some operations like building a
|
|
|
|
# wheel. But this simple install should be fine.
|
2017-07-18 04:50:09 +00:00
|
|
|
pip install ${pip_args} setuptools
|
2016-07-14 03:43:06 +00:00
|
|
|
|
2017-04-11 02:05:35 +00:00
|
|
|
if [[ $_do_py3 -eq 1 ]]; then
|
|
|
|
# Repeat above for python3
|
2018-04-16 03:16:35 +00:00
|
|
|
|
|
|
|
# python2 on fedora always installs into /usr/bin. Move pip2
|
|
|
|
# binary out, as we want "pip" in the final image to be
|
|
|
|
# python2 for historical reasons.
|
|
|
|
mv /usr/bin/pip /usr/bin/pip2
|
|
|
|
|
2017-04-11 02:05:35 +00:00
|
|
|
# You would think that installing python3 bits first, then
|
|
|
|
# python2 would work -- alas get-pip.py doesn't seem to leave
|
|
|
|
# python3 alone:
|
|
|
|
# https://github.com/pypa/pip/issues/4435
|
2017-07-18 04:50:09 +00:00
|
|
|
python3 /tmp/get-pip.py ${pip_args}
|
|
|
|
pip3 install ${pip_args} setuptools
|
2018-04-16 03:16:35 +00:00
|
|
|
|
|
|
|
# on < 27, this installed pip3 to /usr/bin/pip. On >=27 it's
|
|
|
|
# /usr/local/bin/pip. reclaim /usr/bin/pip back to pip2 and
|
|
|
|
# remove the /usr/local/bin/pip (i.e. python3 version) if it
|
|
|
|
# exists, so that "pip" calls pip2 always. if we want pip3 we
|
|
|
|
# call it explicitly.
|
2017-04-11 02:05:35 +00:00
|
|
|
ln -sf /usr/bin/pip2 /usr/bin/pip
|
2018-04-16 03:16:35 +00:00
|
|
|
rm -f /usr/local/bin/pip
|
2019-01-25 05:27:49 +00:00
|
|
|
|
|
|
|
# So on Fedora, there are now supposed to be two versions of
|
|
|
|
# python3 setuptools installed; the one installed by pip in
|
|
|
|
# /usr/local and the one installed by the system
|
|
|
|
# python3-setuptools rpm package in /usr/local. The idea is
|
|
|
|
# that packaged python tools use the "system" python (with -Es
|
|
|
|
# flag) and are isolated from pip installs ... except there is
|
|
|
|
# an issue where pip clears out the RPM version files before
|
|
|
|
# installing it's isolated version:
|
|
|
|
# https://bugzilla.redhat.com/show_bug.cgi?id=1550368
|
|
|
|
#
|
|
|
|
# Thus we need to *reinstall* the RPM version now, so those
|
|
|
|
# files come back and system tools continue to work
|
2020-04-22 01:08:19 +00:00
|
|
|
if [[ $DISTRO_NAME != opensuse ]]; then
|
|
|
|
dnf reinstall -y python3-setuptools
|
|
|
|
fi
|
2017-04-11 02:05:35 +00:00
|
|
|
fi
|
|
|
|
|
2016-07-14 03:43:06 +00:00
|
|
|
# now install latest virtualenv. it vendors stuff it needs so
|
|
|
|
# doesn't have issues with other system packages.
|
2017-04-11 02:05:35 +00:00
|
|
|
|
|
|
|
# python[2|3]-virtualenv package has installed versioned scripts
|
|
|
|
# (/usr/bin/virtualenv-[2|3]) but upstream does not! (see [2]).
|
2018-04-16 03:16:35 +00:00
|
|
|
# For consistency, reinstall so we're just left with python2's
|
|
|
|
# version. Note this is a rather moot point, the usual way we get
|
|
|
|
# a python3 environment is to call "virtualenv -p python3 foo" and
|
|
|
|
# that works to create a python3 virtualenv, even if using
|
|
|
|
# python2's version. Thus we probably don't *really* need to
|
|
|
|
# "pip3 install virtualenv". What we don't want is "virtualenv
|
|
|
|
# foo" creating a python3 virtualenv by default, because that
|
|
|
|
# confuses a lot of legacy code.
|
|
|
|
#
|
|
|
|
#[2] http://pkgs.fedoraproject.org/cgit/rpms/python-virtualenv.git/tree/python-virtualenv.spec#n116)
|
|
|
|
pip install ${pip_args} virtualenv
|
|
|
|
mv /usr/bin/virtualenv /usr/bin/virtualenv2
|
2017-04-11 02:05:35 +00:00
|
|
|
if [[ $_do_py3 -eq 1 ]]; then
|
2017-07-18 04:50:09 +00:00
|
|
|
pip3 install ${pip_args} virtualenv
|
2017-04-11 02:05:35 +00:00
|
|
|
fi
|
2018-04-16 03:16:35 +00:00
|
|
|
|
|
|
|
# Reclaim virtualenv to virtualenv2; similar to above, on fedora
|
|
|
|
# >27 the pip3 version has gone into /usr/local/bin; remove it so
|
|
|
|
# only /usr/bin/virtualenv exists
|
|
|
|
ln -sf /usr/bin/virtualenv2 /usr/bin/virtualenv
|
|
|
|
rm -f /usr/local/bin/virtualenv
|
2016-07-14 03:43:06 +00:00
|
|
|
|
2017-04-11 02:05:35 +00:00
|
|
|
# at this point, we should have the latest
|
|
|
|
# pip/setuptools/virtualenv packages for python2 & 3, and
|
|
|
|
# "/usr/bin/pip" and "/usr/bin/virtualenv" should be python2
|
|
|
|
# versions.
|
|
|
|
|
2017-02-22 18:59:44 +00:00
|
|
|
if [[ $DISTRO_NAME = opensuse ]]; then
|
|
|
|
for pkg in virtualenv pip setuptools; do
|
|
|
|
cat - >> /etc/zypp/locks <<EOF
|
|
|
|
type: package
|
|
|
|
match_type: glob
|
|
|
|
case_sensitive: on
|
|
|
|
solvable_name: python-$pkg
|
|
|
|
EOF
|
|
|
|
done
|
2016-07-14 03:43:06 +00:00
|
|
|
else
|
2017-02-22 18:59:44 +00:00
|
|
|
# Add this to exclude so that we don't install a later package
|
|
|
|
# over it if it updates. Note that fedora-minimal, bootstrapped
|
|
|
|
# via yum, can have an old yum.conf around, so look for dnf first.
|
|
|
|
if [[ -f /etc/dnf/dnf.conf ]]; then
|
|
|
|
conf=/etc/dnf/dnf.conf
|
|
|
|
elif [[ -f /etc/yum.conf ]]; then
|
|
|
|
conf=/etc/yum.conf
|
|
|
|
else
|
|
|
|
die "No conf to modify?"
|
|
|
|
fi
|
2017-04-11 02:05:35 +00:00
|
|
|
echo "exclude=$packages" >> ${conf}
|
2016-07-14 03:43:06 +00:00
|
|
|
fi
|
2017-11-11 00:00:50 +00:00
|
|
|
elif [[ $DISTRO_NAME = gentoo ]]; then
|
|
|
|
packages="dev-python/pip dev-python/virtualenv"
|
|
|
|
emerge -U $packages
|
2016-07-14 03:43:06 +00:00
|
|
|
else
|
2017-05-31 04:16:17 +00:00
|
|
|
# pre-install packages so dependencies are there. We will
|
2017-04-11 19:49:47 +00:00
|
|
|
# overwrite with latest below.
|
|
|
|
packages="python-pip python3-pip python-virtualenv"
|
2018-04-10 00:44:10 +00:00
|
|
|
|
|
|
|
# Unfortunately older ubuntu (trusty) doesn't have a
|
2017-04-11 19:49:47 +00:00
|
|
|
# python3-virtualenv package -- it seems it wasn't ready at the
|
|
|
|
# time and you had to use "python -m venv". Since then virtualenv
|
|
|
|
# has gained 3.4 support so the pip install below will work
|
|
|
|
if [[ ${DIB_PYTHON_VERSION} == 3 ]]; then
|
2018-04-10 00:44:10 +00:00
|
|
|
packages+=" python3-virtualenv"
|
2017-04-11 19:49:47 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
apt-get -y install $packages
|
|
|
|
|
|
|
|
# force things to happen so our assumptions hold
|
|
|
|
pip_args="-U --force-reinstall"
|
2017-04-11 02:05:35 +00:00
|
|
|
|
|
|
|
# These install into /usr/local/bin so override any packages, even
|
|
|
|
# if installed later.
|
|
|
|
|
2018-01-10 04:43:45 +00:00
|
|
|
python3 /tmp/get-pip.py $pip_args
|
|
|
|
python2 /tmp/get-pip.py $pip_args
|
2017-04-11 19:49:47 +00:00
|
|
|
|
2018-01-10 04:43:45 +00:00
|
|
|
pip3 install $pip_args virtualenv
|
|
|
|
pip install $pip_args virtualenv
|
2016-07-14 03:43:06 +00:00
|
|
|
fi
|