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 | |
Sean Dague | 7b63c5e | 2014-06-04 16:25:52 -0400 | [diff] [blame] | 27 | PIP_GET_PIP_URL=https://bootstrap.pypa.io/get-pip.py |
Sean Dague | f625ffe | 2014-06-05 07:04:41 -0400 | [diff] [blame] | 28 | LOCAL_PIP="$FILES/$(basename $PIP_GET_PIP_URL)" |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 29 | |
| 30 | GetDistro |
| 31 | echo "Distro: $DISTRO" |
| 32 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 33 | function get_versions { |
Attila Fazekas | 46ea723 | 2013-10-07 07:29:27 +0200 | [diff] [blame] | 34 | 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] | 35 | if [[ -n $PIP ]]; then |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 36 | PIP_VERSION=$($PIP --version | awk '{ print $2}') |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 37 | echo "pip: $PIP_VERSION" |
Attila Fazekas | 46ea723 | 2013-10-07 07:29:27 +0200 | [diff] [blame] | 38 | else |
| 39 | echo "pip: Not Installed" |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 40 | fi |
| 41 | } |
| 42 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 43 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 44 | function install_get_pip { |
Sean Dague | f625ffe | 2014-06-05 07:04:41 -0400 | [diff] [blame] | 45 | if [[ ! -r $LOCAL_PIP ]]; then |
| 46 | curl -o $LOCAL_PIP $PIP_GET_PIP_URL || \ |
| 47 | die $LINENO "Download of get-pip.py failed" |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 48 | fi |
Sean Dague | f625ffe | 2014-06-05 07:04:41 -0400 | [diff] [blame] | 49 | sudo -E python $LOCAL_PIP |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 50 | } |
| 51 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 52 | |
Franck Yelles | 683ff42 | 2014-06-19 02:14:42 -0700 | [diff] [blame] | 53 | function configure_pypi_alternative_url { |
| 54 | PIP_ROOT_FOLDER="$HOME/.pip" |
| 55 | PIP_CONFIG_FILE="$PIP_ROOT_FOLDER/pip.conf" |
| 56 | if [[ ! -d $PIP_ROOT_FOLDER ]]; then |
| 57 | echo "Creating $PIP_ROOT_FOLDER" |
| 58 | mkdir $PIP_ROOT_FOLDER |
| 59 | fi |
| 60 | if [[ ! -f $PIP_CONFIG_FILE ]]; then |
| 61 | echo "Creating $PIP_CONFIG_FILE" |
| 62 | touch $PIP_CONFIG_FILE |
| 63 | fi |
| 64 | if ! ini_has_option "$PIP_CONFIG_FILE" "global" "index-url"; then |
| 65 | #it means that the index-url does not exist |
| 66 | iniset "$PIP_CONFIG_FILE" "global" "index-url" "$PYPI_OVERRIDE" |
| 67 | fi |
| 68 | |
| 69 | } |
| 70 | |
| 71 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 72 | # Show starting versions |
| 73 | get_versions |
| 74 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 75 | # Do pip |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 76 | |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 77 | # Eradicate any and all system packages |
| 78 | uninstall_package python-pip |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 79 | |
Sean Dague | 7b63c5e | 2014-06-04 16:25:52 -0400 | [diff] [blame] | 80 | install_get_pip |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 81 | |
Franck Yelles | 683ff42 | 2014-06-19 02:14:42 -0700 | [diff] [blame] | 82 | if [[ -n $PYPI_ALTERNATIVE_URL ]]; then |
| 83 | configure_pypi_alternative_url |
| 84 | fi |
| 85 | |
Mathieu Gagné | 76ed427 | 2014-06-05 16:50:40 -0400 | [diff] [blame] | 86 | pip_install -U setuptools |
| 87 | |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 88 | get_versions |