blob: 940bd8c84a387933bb46ef8162f8cdd49a0828fb [file] [log] [blame]
Dean Troyer62d1d692013-08-01 17:40:40 -05001#!/usr/bin/env bash
2
3# **install_pip.sh**
4
Monty Taylordace92f2013-08-10 23:49:47 -03005# install_pip.sh [--pip-version <version>] [--use-get-pip] [--force]
Dean Troyer62d1d692013-08-01 17:40:40 -05006#
7# Update pip and friends to a known common version
8
9# Assumptions:
Dean Troyer62d1d692013-08-01 17:40:40 -050010# - update pip to $INSTALL_PIP_VERSION
11
Adam Spiersc85ade72013-10-01 00:35:16 +010012set -o errexit
13set -o xtrace
14
Dean Troyer62d1d692013-08-01 17:40:40 -050015# Keep track of the current directory
16TOOLS_DIR=$(cd $(dirname "$0") && pwd)
17TOP_DIR=`cd $TOOLS_DIR/..; pwd`
18
19# Change dir to top of devstack
20cd $TOP_DIR
21
22# Import common functions
23source $TOP_DIR/functions
24
25FILES=$TOP_DIR/files
26
27# Handle arguments
28
Chmouel Boudjnah59178682013-09-06 16:14:17 +020029INSTALL_PIP_VERSION=${INSTALL_PIP_VERSION:-"1.4.1"}
Dean Troyer62d1d692013-08-01 17:40:40 -050030while [[ -n "$1" ]]; do
31 case $1 in
32 --force)
33 FORCE=1
34 ;;
35 --pip-version)
36 INSTALL_PIP_VERSION="$2"
37 shift
38 ;;
Dean Troyer62d1d692013-08-01 17:40:40 -050039 --use-get-pip)
40 USE_GET_PIP=1;
41 ;;
42 esac
43 shift
44done
45
Dean Troyer62d1d692013-08-01 17:40:40 -050046PIP_GET_PIP_URL=https://raw.github.com/pypa/pip/master/contrib/get-pip.py
47PIP_TAR_URL=https://pypi.python.org/packages/source/p/pip/pip-$INSTALL_PIP_VERSION.tar.gz
48
49GetDistro
50echo "Distro: $DISTRO"
51
52function get_versions() {
Attila Fazekas46ea7232013-10-07 07:29:27 +020053 PIP=$(which pip 2>/dev/null || which pip-python 2>/dev/null || true)
Dean Troyer62d1d692013-08-01 17:40:40 -050054 if [[ -n $PIP ]]; then
Dean Troyer62d1d692013-08-01 17:40:40 -050055 PIP_VERSION=$($PIP --version | awk '{ print $2}')
Monty Taylordace92f2013-08-10 23:49:47 -030056 echo "pip: $PIP_VERSION"
Attila Fazekas46ea7232013-10-07 07:29:27 +020057 else
58 echo "pip: Not Installed"
Dean Troyer62d1d692013-08-01 17:40:40 -050059 fi
60}
61
Dean Troyer62d1d692013-08-01 17:40:40 -050062
63function install_get_pip() {
64 if [[ ! -r $FILES/get-pip.py ]]; then
65 (cd $FILES; \
66 curl $PIP_GET_PIP_URL; \
67 )
68 fi
69 sudo python $FILES/get-pip.py
70}
71
72function install_pip_tarball() {
Dean Troyer9acc12a2013-08-09 15:09:31 -050073 (cd $FILES; \
74 curl -O $PIP_TAR_URL; \
75 tar xvfz pip-$INSTALL_PIP_VERSION.tar.gz; \
76 cd pip-$INSTALL_PIP_VERSION; \
77 sudo python setup.py install; \
78 )
Dean Troyer62d1d692013-08-01 17:40:40 -050079}
80
81# Show starting versions
82get_versions
83
Dean Troyer62d1d692013-08-01 17:40:40 -050084# Do pip
Dean Troyer62d1d692013-08-01 17:40:40 -050085
Monty Taylordace92f2013-08-10 23:49:47 -030086# Eradicate any and all system packages
87uninstall_package python-pip
Dean Troyer62d1d692013-08-01 17:40:40 -050088
Monty Taylordace92f2013-08-10 23:49:47 -030089if [[ -n "$USE_GET_PIP" ]]; then
90 install_get_pip
91else
92 install_pip_tarball
Dean Troyer62d1d692013-08-01 17:40:40 -050093fi
Monty Taylordace92f2013-08-10 23:49:47 -030094
95get_versions