Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # **install_pip.sh** |
| 4 | |
| 5 | # install_pip.sh [--pip-version <version>] [--use-get-pip] [--setuptools] [--force] |
| 6 | # |
| 7 | # Update pip and friends to a known common version |
| 8 | |
| 9 | # Assumptions: |
| 10 | # - currently we try to leave the system setuptools alone, install |
| 11 | # the system package if it is not already present |
| 12 | # - update pip to $INSTALL_PIP_VERSION |
| 13 | |
| 14 | # Keep track of the current directory |
| 15 | TOOLS_DIR=$(cd $(dirname "$0") && pwd) |
| 16 | TOP_DIR=`cd $TOOLS_DIR/..; pwd` |
| 17 | |
| 18 | # Change dir to top of devstack |
| 19 | cd $TOP_DIR |
| 20 | |
| 21 | # Import common functions |
| 22 | source $TOP_DIR/functions |
| 23 | |
| 24 | FILES=$TOP_DIR/files |
| 25 | |
| 26 | # Handle arguments |
| 27 | |
| 28 | INSTALL_PIP_VERSION=${INSTALL_PIP_VERSION:-"1.4"} |
| 29 | while [[ -n "$1" ]]; do |
| 30 | case $1 in |
| 31 | --force) |
| 32 | FORCE=1 |
| 33 | ;; |
| 34 | --pip-version) |
| 35 | INSTALL_PIP_VERSION="$2" |
| 36 | shift |
| 37 | ;; |
| 38 | --setuptools) |
| 39 | SETUPTOOLS=1 |
| 40 | ;; |
| 41 | --use-get-pip) |
| 42 | USE_GET_PIP=1; |
| 43 | ;; |
| 44 | esac |
| 45 | shift |
| 46 | done |
| 47 | |
| 48 | SETUPTOOLS_EZ_SETUP_URL=https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py |
| 49 | PIP_GET_PIP_URL=https://raw.github.com/pypa/pip/master/contrib/get-pip.py |
| 50 | PIP_TAR_URL=https://pypi.python.org/packages/source/p/pip/pip-$INSTALL_PIP_VERSION.tar.gz |
| 51 | |
| 52 | GetDistro |
| 53 | echo "Distro: $DISTRO" |
| 54 | |
| 55 | function get_versions() { |
| 56 | PIP=$(which pip 2>/dev/null || which pip-python 2>/dev/null) |
| 57 | if [[ -n $PIP ]]; then |
| 58 | DISTRIBUTE_VERSION=$($PIP freeze | grep 'distribute==') |
| 59 | SETUPTOOLS_VERSION=$($PIP freeze | grep 'setuptools==') |
| 60 | PIP_VERSION=$($PIP --version | awk '{ print $2}') |
| 61 | echo "pip: $PIP_VERSION setuptools: $SETUPTOOLS_VERSION distribute: $DISTRIBUTE_VERSION" |
| 62 | fi |
| 63 | } |
| 64 | |
| 65 | function setuptools_ez_setup() { |
| 66 | if [[ ! -r $FILES/ez_setup.py ]]; then |
| 67 | (cd $FILES; \ |
| 68 | curl -OR $SETUPTOOLS_EZ_SETUP_URL; \ |
| 69 | ) |
| 70 | fi |
| 71 | sudo python $FILES/ez_setup.py |
| 72 | } |
| 73 | |
| 74 | function install_get_pip() { |
| 75 | if [[ ! -r $FILES/get-pip.py ]]; then |
| 76 | (cd $FILES; \ |
| 77 | curl $PIP_GET_PIP_URL; \ |
| 78 | ) |
| 79 | fi |
| 80 | sudo python $FILES/get-pip.py |
| 81 | } |
| 82 | |
| 83 | function install_pip_tarball() { |
Dean Troyer | 9acc12a | 2013-08-09 15:09:31 -0500 | [diff] [blame^] | 84 | (cd $FILES; \ |
| 85 | curl -O $PIP_TAR_URL; \ |
| 86 | tar xvfz pip-$INSTALL_PIP_VERSION.tar.gz; \ |
| 87 | cd pip-$INSTALL_PIP_VERSION; \ |
| 88 | sudo python setup.py install; \ |
| 89 | ) |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | # Show starting versions |
| 93 | get_versions |
| 94 | |
| 95 | # Do setuptools |
| 96 | if [[ -n "$SETUPTOOLS" ]]; then |
| 97 | # We want it from source |
| 98 | uninstall_package python-setuptools |
| 99 | setuptools_ez_setup |
| 100 | else |
| 101 | # See about installing the distro setuptools |
| 102 | if ! python -c "import setuptools"; then |
| 103 | install_package python-setuptools |
| 104 | fi |
| 105 | fi |
| 106 | |
| 107 | # Do pip |
| 108 | if [[ -z $PIP || "$PIP_VERSION" != "$INSTALL_PIP_VERSION" || -n $FORCE ]]; then |
| 109 | |
| 110 | # Eradicate any and all system packages |
| 111 | uninstall_package python-pip |
| 112 | |
| 113 | if [[ -n "$USE_GET_PIP" ]]; then |
| 114 | install_get_pip |
| 115 | else |
| 116 | install_pip_tarball |
| 117 | fi |
| 118 | |
| 119 | get_versions |
| 120 | fi |