blob: 6e3e9d2104d6b4830bba17ddab53b67f96de9804 [file] [log] [blame]
Dean Troyer62d1d692013-08-01 17:40:40 -05001#!/usr/bin/env bash
2
3# **install_pip.sh**
4
5# install_pip.sh [--pip-version <version>] [--use-get-pip] [--setuptools] [--force]
6#
7# Update pip and friends to a known common version
8
9# Assumptions:
10# - currently we try to leave the system setuptools alone, install
11# the system package if it is not already present
12# - update pip to $INSTALL_PIP_VERSION
13
14# Keep track of the current directory
15TOOLS_DIR=$(cd $(dirname "$0") && pwd)
16TOP_DIR=`cd $TOOLS_DIR/..; pwd`
17
18# Change dir to top of devstack
19cd $TOP_DIR
20
21# Import common functions
22source $TOP_DIR/functions
23
24FILES=$TOP_DIR/files
25
26# Handle arguments
27
28INSTALL_PIP_VERSION=${INSTALL_PIP_VERSION:-"1.4"}
29while [[ -n "$1" ]]; do
30 case $1 in
31 --force)
32 FORCE=1
33 ;;
34 --pip-version)
35 INSTALL_PIP_VERSION="$2"
36 shift
37 ;;
38 --setuptools)
39 SETUPTOOLS=1
40 ;;
41 --use-get-pip)
42 USE_GET_PIP=1;
43 ;;
44 esac
45 shift
46done
47
48SETUPTOOLS_EZ_SETUP_URL=https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
49PIP_GET_PIP_URL=https://raw.github.com/pypa/pip/master/contrib/get-pip.py
50PIP_TAR_URL=https://pypi.python.org/packages/source/p/pip/pip-$INSTALL_PIP_VERSION.tar.gz
51
52GetDistro
53echo "Distro: $DISTRO"
54
55function get_versions() {
56 PIP=$(which pip 2>/dev/null || which pip-python 2>/dev/null)
57 if [[ -n $PIP ]]; then
58 DISTRIBUTE_VERSION=$($PIP freeze | grep 'distribute==')
59 SETUPTOOLS_VERSION=$($PIP freeze | grep 'setuptools==')
60 PIP_VERSION=$($PIP --version | awk '{ print $2}')
61 echo "pip: $PIP_VERSION setuptools: $SETUPTOOLS_VERSION distribute: $DISTRIBUTE_VERSION"
62 fi
63}
64
65function setuptools_ez_setup() {
66 if [[ ! -r $FILES/ez_setup.py ]]; then
67 (cd $FILES; \
68 curl -OR $SETUPTOOLS_EZ_SETUP_URL; \
69 )
70 fi
71 sudo python $FILES/ez_setup.py
72}
73
74function install_get_pip() {
75 if [[ ! -r $FILES/get-pip.py ]]; then
76 (cd $FILES; \
77 curl $PIP_GET_PIP_URL; \
78 )
79 fi
80 sudo python $FILES/get-pip.py
81}
82
83function install_pip_tarball() {
Dean Troyer9acc12a2013-08-09 15:09:31 -050084 (cd $FILES; \
85 curl -O $PIP_TAR_URL; \
86 tar xvfz pip-$INSTALL_PIP_VERSION.tar.gz; \
87 cd pip-$INSTALL_PIP_VERSION; \
88 sudo python setup.py install; \
89 )
Dean Troyer62d1d692013-08-01 17:40:40 -050090}
91
92# Show starting versions
93get_versions
94
95# Do setuptools
96if [[ -n "$SETUPTOOLS" ]]; then
97 # We want it from source
98 uninstall_package python-setuptools
99 setuptools_ez_setup
100else
101 # See about installing the distro setuptools
102 if ! python -c "import setuptools"; then
103 install_package python-setuptools
104 fi
105fi
106
107# Do pip
108if [[ -z $PIP || "$PIP_VERSION" != "$INSTALL_PIP_VERSION" || -n $FORCE ]]; then
109
110 # Eradicate any and all system packages
111 uninstall_package python-pip
112
113 if [[ -n "$USE_GET_PIP" ]]; then
114 install_get_pip
115 else
116 install_pip_tarball
117 fi
118
119 get_versions
120fi