blob: 1eb9e7a3f56f8f62bef83730c771022c421d937b [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
Monty Taylor480309e2013-11-23 13:02:45 -050029USE_GET_PIP=${USE_GET_PIP:-0}
Chmouel Boudjnah59178682013-09-06 16:14:17 +020030INSTALL_PIP_VERSION=${INSTALL_PIP_VERSION:-"1.4.1"}
Dean Troyer62d1d692013-08-01 17:40:40 -050031while [[ -n "$1" ]]; do
32 case $1 in
33 --force)
34 FORCE=1
35 ;;
36 --pip-version)
37 INSTALL_PIP_VERSION="$2"
38 shift
39 ;;
Dean Troyer62d1d692013-08-01 17:40:40 -050040 --use-get-pip)
41 USE_GET_PIP=1;
42 ;;
43 esac
44 shift
45done
46
Dean Troyer62d1d692013-08-01 17:40:40 -050047PIP_GET_PIP_URL=https://raw.github.com/pypa/pip/master/contrib/get-pip.py
48PIP_TAR_URL=https://pypi.python.org/packages/source/p/pip/pip-$INSTALL_PIP_VERSION.tar.gz
49
50GetDistro
51echo "Distro: $DISTRO"
52
Ian Wienandaee18c72014-02-21 15:35:08 +110053function get_versions {
Attila Fazekas46ea7232013-10-07 07:29:27 +020054 PIP=$(which pip 2>/dev/null || which pip-python 2>/dev/null || true)
Dean Troyer62d1d692013-08-01 17:40:40 -050055 if [[ -n $PIP ]]; then
Dean Troyer62d1d692013-08-01 17:40:40 -050056 PIP_VERSION=$($PIP --version | awk '{ print $2}')
Monty Taylordace92f2013-08-10 23:49:47 -030057 echo "pip: $PIP_VERSION"
Attila Fazekas46ea7232013-10-07 07:29:27 +020058 else
59 echo "pip: Not Installed"
Dean Troyer62d1d692013-08-01 17:40:40 -050060 fi
61}
62
Dean Troyer62d1d692013-08-01 17:40:40 -050063
Ian Wienandaee18c72014-02-21 15:35:08 +110064function install_get_pip {
Dean Troyer62d1d692013-08-01 17:40:40 -050065 if [[ ! -r $FILES/get-pip.py ]]; then
66 (cd $FILES; \
Monty Taylor480309e2013-11-23 13:02:45 -050067 curl -O $PIP_GET_PIP_URL; \
Dean Troyer62d1d692013-08-01 17:40:40 -050068 )
69 fi
sbauzaa49422e2013-12-05 14:56:14 +010070 sudo -E python $FILES/get-pip.py
Dean Troyer62d1d692013-08-01 17:40:40 -050071}
72
Ian Wienandaee18c72014-02-21 15:35:08 +110073function install_pip_tarball {
Sean Dague33ff33b2014-03-28 15:14:56 -040074 if [[ ! -r $FILES/pip-$INSTALL_PIP_VERSION.tar.gz ]]; then
75 (cd $FILES; \
76 curl -O $PIP_TAR_URL; \
77 tar xvfz pip-$INSTALL_PIP_VERSION.tar.gz 1>/dev/null)
78 fi
79 (cd $FILES/pip-$INSTALL_PIP_VERSION; \
80 sudo -E python setup.py install 1>/dev/null)
Dean Troyer62d1d692013-08-01 17:40:40 -050081}
82
83# Show starting versions
84get_versions
85
Dean Troyer62d1d692013-08-01 17:40:40 -050086# Do pip
Dean Troyer62d1d692013-08-01 17:40:40 -050087
Monty Taylordace92f2013-08-10 23:49:47 -030088# Eradicate any and all system packages
89uninstall_package python-pip
Dean Troyer62d1d692013-08-01 17:40:40 -050090
KIYOHIRO ADACHIa515a702013-12-11 16:11:28 +090091if [[ "$USE_GET_PIP" == "1" ]]; then
Monty Taylordace92f2013-08-10 23:49:47 -030092 install_get_pip
93else
94 install_pip_tarball
Dean Troyer62d1d692013-08-01 17:40:40 -050095fi
Monty Taylordace92f2013-08-10 23:49:47 -030096
97get_versions