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
|
|
|
|
|
2017-06-28 00:55:53 +00:00
|
|
|
if [[ $DISTRO_NAME =~ (opensuse|fedora|centos|centos7|rhel7) ]]; then
|
2017-04-11 02:05:35 +00:00
|
|
|
|
|
|
|
_do_py3=0
|
|
|
|
packages="python-virtualenv python-pip python-setuptools"
|
|
|
|
if [[ $DISTRO_NAME =~ (fedora) ]]; then
|
|
|
|
_do_py3=1
|
|
|
|
packages+=" python3-virtualenv python3-pip python3-setuptools"
|
|
|
|
fi
|
|
|
|
|
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
|
2017-04-11 02:05:35 +00:00
|
|
|
${YUM:-yum} install -y $packages
|
2017-02-22 18:59:44 +00:00
|
|
|
fi
|
2016-07-14 03:43:06 +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
|
|
|
|
|
|
|
# pip and setuptools are closely related; we want to ensure the
|
|
|
|
# latest for sanity. Because distro packages don't include enough
|
|
|
|
# info in the egg for pip to be certain it has fully uninstalled
|
|
|
|
# the old package, for safety we clear it out by hand (this seems
|
|
|
|
# to have been a problem with very old to new updates,
|
|
|
|
# e.g. centos6 to current-era, but less so for smaller jumps).
|
|
|
|
# There is a bit of chicken-and-egg problem with pip in that it
|
|
|
|
# requires setuptools for some operations, such as wheel creation.
|
|
|
|
# But just installing setuptools shouldn't require setuptools
|
|
|
|
# itself, so we are safe for this small section.
|
|
|
|
rm -rf /usr/lib/python2.7/site-packages/setuptools*
|
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
|
|
|
|
# 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}
|
2017-04-11 02:05:35 +00:00
|
|
|
rm -rf /usr/lib/python3.?/site-packages/setuptools*
|
2017-07-18 04:50:09 +00:00
|
|
|
pip3 install ${pip_args} setuptools
|
2017-04-11 02:05:35 +00:00
|
|
|
# reclaim /usr/bin/pip back to pip2
|
|
|
|
ln -sf /usr/bin/pip2 /usr/bin/pip
|
|
|
|
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]).
|
|
|
|
# For consistency, clear them out and then reinstall so we're just
|
|
|
|
# left with python2's version
|
|
|
|
# [2] http://pkgs.fedoraproject.org/cgit/rpms/python-virtualenv.git/tree/python-virtualenv.spec#n116)
|
|
|
|
rm /usr/bin/virtualenv*
|
|
|
|
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
|
2017-07-18 04:50:09 +00:00
|
|
|
pip install ${pip_args} 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
|
|
|
|
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"
|
|
|
|
# unfortunately older ubuntu (trusty) doesn't have a
|
|
|
|
# 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
|
2017-11-13 22:58:56 +00:00
|
|
|
packages=$(echo "$packages" | sed s/python-virtualenv/python3-virtualenv/ | sed s/python-pip/python3-pip/)
|
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.
|
|
|
|
|
2017-11-13 22:58:56 +00:00
|
|
|
if [[ ${DIB_PYTHON_VERSION} == 3 ]]; then
|
|
|
|
python3 /tmp/get-pip.py $pip_args
|
|
|
|
pip3 install $pip_args virtualenv
|
|
|
|
else
|
|
|
|
python2 /tmp/get-pip.py $pip_args
|
|
|
|
pip install $pip_args virtualenv
|
|
|
|
fi
|
2017-04-11 19:49:47 +00:00
|
|
|
|
2016-07-14 03:43:06 +00:00
|
|
|
fi
|