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 | |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 19 | # Change dir to top of DevStack |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 20 | cd $TOP_DIR |
| 21 | |
| 22 | # Import common functions |
Clark Boylan | 05aa384 | 2015-08-03 11:14:13 -0700 | [diff] [blame] | 23 | source $TOP_DIR/stackrc |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 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 | 0280f6f | 2015-10-07 09:19:53 -0400 | [diff] [blame] | 45 | # If get-pip.py isn't python, delete it. This was probably an |
| 46 | # outage on the server. |
| 47 | if [[ -r $LOCAL_PIP ]]; then |
| 48 | if ! head -1 $LOCAL_PIP | grep -q '#!/usr/bin/env python'; then |
| 49 | echo "WARNING: Corrupt $LOCAL_PIP found removing" |
| 50 | rm $LOCAL_PIP |
| 51 | fi |
| 52 | fi |
| 53 | |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 54 | # The OpenStack gate and others put a cached version of get-pip.py |
Ian Wienand | 7c4ce9e | 2015-03-10 11:32:26 +1100 | [diff] [blame] | 55 | # for this to find, explicitly to avoid download issues. |
| 56 | # |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 57 | # However, if DevStack *did* download the file, we want to check |
| 58 | # for updates; people can leave their stacks around for a long |
Ian Wienand | 7c4ce9e | 2015-03-10 11:32:26 +1100 | [diff] [blame] | 59 | # time and in the mean-time pip might get upgraded. |
| 60 | # |
| 61 | # Thus we use curl's "-z" feature to always check the modified |
| 62 | # since and only download if a new version is out -- but only if |
| 63 | # it seems we downloaded the file originally. |
| 64 | if [[ ! -r $LOCAL_PIP || -r $LOCAL_PIP.downloaded ]]; then |
Sean Dague | a0cc291 | 2015-10-07 09:06:42 -0400 | [diff] [blame] | 65 | # only test freshness if LOCAL_PIP is actually there, |
| 66 | # otherwise we generate a scary warning. |
| 67 | local timecond="" |
| 68 | if [[ -r $LOCAL_PIP ]]; then |
| 69 | timecond="-z $LOCAL_PIP" |
| 70 | fi |
| 71 | |
Sean Dague | fa41b5b | 2015-10-08 06:05:20 -0400 | [diff] [blame] | 72 | curl -f --retry 6 --retry-delay 5 \ |
Sean Dague | a0cc291 | 2015-10-07 09:06:42 -0400 | [diff] [blame] | 73 | $timecond -o $LOCAL_PIP $PIP_GET_PIP_URL || \ |
Sean Dague | f625ffe | 2014-06-05 07:04:41 -0400 | [diff] [blame] | 74 | die $LINENO "Download of get-pip.py failed" |
Ian Wienand | 7c4ce9e | 2015-03-10 11:32:26 +1100 | [diff] [blame] | 75 | touch $LOCAL_PIP.downloaded |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 76 | fi |
Adam Gandelman | 130efef | 2014-12-27 14:01:00 -0800 | [diff] [blame] | 77 | sudo -H -E python $LOCAL_PIP |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 78 | } |
| 79 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 80 | |
Franck Yelles | 683ff42 | 2014-06-19 02:14:42 -0700 | [diff] [blame] | 81 | function configure_pypi_alternative_url { |
| 82 | PIP_ROOT_FOLDER="$HOME/.pip" |
| 83 | PIP_CONFIG_FILE="$PIP_ROOT_FOLDER/pip.conf" |
| 84 | if [[ ! -d $PIP_ROOT_FOLDER ]]; then |
| 85 | echo "Creating $PIP_ROOT_FOLDER" |
| 86 | mkdir $PIP_ROOT_FOLDER |
| 87 | fi |
| 88 | if [[ ! -f $PIP_CONFIG_FILE ]]; then |
| 89 | echo "Creating $PIP_CONFIG_FILE" |
| 90 | touch $PIP_CONFIG_FILE |
| 91 | fi |
| 92 | if ! ini_has_option "$PIP_CONFIG_FILE" "global" "index-url"; then |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 93 | # It means that the index-url does not exist |
Franck Yelles | 683ff42 | 2014-06-19 02:14:42 -0700 | [diff] [blame] | 94 | iniset "$PIP_CONFIG_FILE" "global" "index-url" "$PYPI_OVERRIDE" |
| 95 | fi |
| 96 | |
| 97 | } |
| 98 | |
Jeremy Stanley | 35b5283 | 2014-12-18 17:27:22 +0000 | [diff] [blame] | 99 | # Setuptools 8 implements PEP 440, and 8.0.4 adds a warning triggered any time |
| 100 | # pkg_resources inspects the list of installed Python packages if there are |
| 101 | # non-compliant version numbers in the egg-info (for example, from distro |
| 102 | # system packaged Python libraries). This is off by default after 8.2 but can |
| 103 | # be enabled by uncommenting the lines below. |
| 104 | #PYTHONWARNINGS=$PYTHONWARNINGS,always::RuntimeWarning:pkg_resources |
| 105 | #export PYTHONWARNINGS |
Franck Yelles | 683ff42 | 2014-06-19 02:14:42 -0700 | [diff] [blame] | 106 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 107 | # Show starting versions |
| 108 | get_versions |
| 109 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 110 | # Do pip |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 111 | |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 112 | # Eradicate any and all system packages |
| 113 | uninstall_package python-pip |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 114 | |
Sean Dague | 7b63c5e | 2014-06-04 16:25:52 -0400 | [diff] [blame] | 115 | install_get_pip |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 116 | |
Franck Yelles | 683ff42 | 2014-06-19 02:14:42 -0700 | [diff] [blame] | 117 | if [[ -n $PYPI_ALTERNATIVE_URL ]]; then |
| 118 | configure_pypi_alternative_url |
| 119 | fi |
| 120 | |
Jeremy Stanley | b7ebc47 | 2014-12-17 03:32:42 +0000 | [diff] [blame] | 121 | pip_install -U setuptools |
Mathieu Gagné | 76ed427 | 2014-06-05 16:50:40 -0400 | [diff] [blame] | 122 | |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 123 | get_versions |