Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # **install_pip.sh** |
| 4 | |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 5 | # install_pip.sh [--pip-version <version>] [--use-get-pip] [--force] |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 6 | # |
| 7 | # Update pip and friends to a known common version |
| 8 | |
| 9 | # Assumptions: |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 10 | # - update pip to $INSTALL_PIP_VERSION |
| 11 | |
Adam Spiers | c85ade7 | 2013-10-01 00:35:16 +0100 | [diff] [blame] | 12 | set -o errexit |
| 13 | set -o xtrace |
| 14 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 15 | # Keep track of the current directory |
| 16 | TOOLS_DIR=$(cd $(dirname "$0") && pwd) |
| 17 | TOP_DIR=`cd $TOOLS_DIR/..; pwd` |
| 18 | |
| 19 | # Change dir to top of devstack |
| 20 | cd $TOP_DIR |
| 21 | |
| 22 | # Import common functions |
| 23 | source $TOP_DIR/functions |
| 24 | |
| 25 | FILES=$TOP_DIR/files |
| 26 | |
| 27 | # Handle arguments |
| 28 | |
Monty Taylor | 480309e | 2013-11-23 13:02:45 -0500 | [diff] [blame] | 29 | USE_GET_PIP=${USE_GET_PIP:-0} |
Chmouel Boudjnah | 5917868 | 2013-09-06 16:14:17 +0200 | [diff] [blame] | 30 | INSTALL_PIP_VERSION=${INSTALL_PIP_VERSION:-"1.4.1"} |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 31 | while [[ -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 Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 40 | --use-get-pip) |
| 41 | USE_GET_PIP=1; |
| 42 | ;; |
| 43 | esac |
| 44 | shift |
| 45 | done |
| 46 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 47 | PIP_GET_PIP_URL=https://raw.github.com/pypa/pip/master/contrib/get-pip.py |
| 48 | PIP_TAR_URL=https://pypi.python.org/packages/source/p/pip/pip-$INSTALL_PIP_VERSION.tar.gz |
| 49 | |
| 50 | GetDistro |
| 51 | echo "Distro: $DISTRO" |
| 52 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 53 | function get_versions { |
Attila Fazekas | 46ea723 | 2013-10-07 07:29:27 +0200 | [diff] [blame] | 54 | PIP=$(which pip 2>/dev/null || which pip-python 2>/dev/null || true) |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 55 | if [[ -n $PIP ]]; then |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 56 | PIP_VERSION=$($PIP --version | awk '{ print $2}') |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 57 | echo "pip: $PIP_VERSION" |
Attila Fazekas | 46ea723 | 2013-10-07 07:29:27 +0200 | [diff] [blame] | 58 | else |
| 59 | echo "pip: Not Installed" |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 60 | fi |
| 61 | } |
| 62 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 63 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 64 | function install_get_pip { |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 65 | if [[ ! -r $FILES/get-pip.py ]]; then |
| 66 | (cd $FILES; \ |
Monty Taylor | 480309e | 2013-11-23 13:02:45 -0500 | [diff] [blame] | 67 | curl -O $PIP_GET_PIP_URL; \ |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 68 | ) |
| 69 | fi |
sbauza | a49422e | 2013-12-05 14:56:14 +0100 | [diff] [blame] | 70 | sudo -E python $FILES/get-pip.py |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 71 | } |
| 72 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 73 | function install_pip_tarball { |
Dean Troyer | 9acc12a | 2013-08-09 15:09:31 -0500 | [diff] [blame] | 74 | (cd $FILES; \ |
| 75 | curl -O $PIP_TAR_URL; \ |
DennyZhang | 3931573 | 2013-10-11 00:12:22 -0500 | [diff] [blame] | 76 | tar xvfz pip-$INSTALL_PIP_VERSION.tar.gz 1>/dev/null; \ |
Dean Troyer | 9acc12a | 2013-08-09 15:09:31 -0500 | [diff] [blame] | 77 | cd pip-$INSTALL_PIP_VERSION; \ |
sbauza | a49422e | 2013-12-05 14:56:14 +0100 | [diff] [blame] | 78 | sudo -E python setup.py install 1>/dev/null; \ |
Dean Troyer | 9acc12a | 2013-08-09 15:09:31 -0500 | [diff] [blame] | 79 | ) |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | # Show starting versions |
| 83 | get_versions |
| 84 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 85 | # Do pip |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 86 | |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 87 | # Eradicate any and all system packages |
| 88 | uninstall_package python-pip |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 89 | |
KIYOHIRO ADACHI | a515a70 | 2013-12-11 16:11:28 +0900 | [diff] [blame] | 90 | if [[ "$USE_GET_PIP" == "1" ]]; then |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 91 | install_get_pip |
| 92 | else |
| 93 | install_pip_tarball |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 94 | fi |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 95 | |
| 96 | get_versions |