blob: 9fa161e043a0b9495605cbf512f9fbb2120e2e70 [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 {
Dean Troyer9acc12a2013-08-09 15:09:31 -050074 (cd $FILES; \
75 curl -O $PIP_TAR_URL; \
DennyZhang39315732013-10-11 00:12:22 -050076 tar xvfz pip-$INSTALL_PIP_VERSION.tar.gz 1>/dev/null; \
Dean Troyer9acc12a2013-08-09 15:09:31 -050077 cd pip-$INSTALL_PIP_VERSION; \
sbauzaa49422e2013-12-05 14:56:14 +010078 sudo -E python setup.py install 1>/dev/null; \
Dean Troyer9acc12a2013-08-09 15:09:31 -050079 )
Dean Troyer62d1d692013-08-01 17:40:40 -050080}
81
82# Show starting versions
83get_versions
84
Dean Troyer62d1d692013-08-01 17:40:40 -050085# Do pip
Dean Troyer62d1d692013-08-01 17:40:40 -050086
Monty Taylordace92f2013-08-10 23:49:47 -030087# Eradicate any and all system packages
88uninstall_package python-pip
Dean Troyer62d1d692013-08-01 17:40:40 -050089
KIYOHIRO ADACHIa515a702013-12-11 16:11:28 +090090if [[ "$USE_GET_PIP" == "1" ]]; then
Monty Taylordace92f2013-08-10 23:49:47 -030091 install_get_pip
92else
93 install_pip_tarball
Dean Troyer62d1d692013-08-01 17:40:40 -050094fi
Monty Taylordace92f2013-08-10 23:49:47 -030095
96get_versions