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 | |
Chmouel Boudjnah | 5917868 | 2013-09-06 16:14:17 +0200 | [diff] [blame] | 29 | INSTALL_PIP_VERSION=${INSTALL_PIP_VERSION:-"1.4.1"} |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 30 | while [[ -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 Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 39 | --use-get-pip) |
| 40 | USE_GET_PIP=1; |
| 41 | ;; |
| 42 | esac |
| 43 | shift |
| 44 | done |
| 45 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 46 | PIP_GET_PIP_URL=https://raw.github.com/pypa/pip/master/contrib/get-pip.py |
| 47 | PIP_TAR_URL=https://pypi.python.org/packages/source/p/pip/pip-$INSTALL_PIP_VERSION.tar.gz |
| 48 | |
| 49 | GetDistro |
| 50 | echo "Distro: $DISTRO" |
| 51 | |
| 52 | function get_versions() { |
| 53 | PIP=$(which pip 2>/dev/null || which pip-python 2>/dev/null) |
| 54 | if [[ -n $PIP ]]; then |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 55 | PIP_VERSION=$($PIP --version | awk '{ print $2}') |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 56 | echo "pip: $PIP_VERSION" |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 57 | fi |
| 58 | } |
| 59 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 60 | |
| 61 | function install_get_pip() { |
| 62 | if [[ ! -r $FILES/get-pip.py ]]; then |
| 63 | (cd $FILES; \ |
| 64 | curl $PIP_GET_PIP_URL; \ |
| 65 | ) |
| 66 | fi |
| 67 | sudo python $FILES/get-pip.py |
| 68 | } |
| 69 | |
| 70 | function install_pip_tarball() { |
Dean Troyer | 9acc12a | 2013-08-09 15:09:31 -0500 | [diff] [blame] | 71 | (cd $FILES; \ |
| 72 | curl -O $PIP_TAR_URL; \ |
| 73 | tar xvfz pip-$INSTALL_PIP_VERSION.tar.gz; \ |
| 74 | cd pip-$INSTALL_PIP_VERSION; \ |
| 75 | sudo python setup.py install; \ |
| 76 | ) |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | # Show starting versions |
| 80 | get_versions |
| 81 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 82 | # Do pip |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 83 | |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 84 | # Eradicate any and all system packages |
| 85 | uninstall_package python-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 | if [[ -n "$USE_GET_PIP" ]]; then |
| 88 | install_get_pip |
| 89 | else |
| 90 | install_pip_tarball |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 91 | fi |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 92 | |
| 93 | get_versions |