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 |
Doug Hellmann | ddc3839 | 2015-05-07 21:06:24 +0000 | [diff] [blame] | 11 | # - if USE_PYTHON3=True, PYTHON3_VERSION refers to a version already installed |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 12 | |
Adam Spiers | c85ade7 | 2013-10-01 00:35:16 +0100 | [diff] [blame] | 13 | set -o errexit |
| 14 | set -o xtrace |
| 15 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 16 | # Keep track of the current directory |
| 17 | TOOLS_DIR=$(cd $(dirname "$0") && pwd) |
| 18 | TOP_DIR=`cd $TOOLS_DIR/..; pwd` |
| 19 | |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 20 | # Change dir to top of DevStack |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 21 | cd $TOP_DIR |
| 22 | |
| 23 | # Import common functions |
Clark Boylan | 05aa384 | 2015-08-03 11:14:13 -0700 | [diff] [blame] | 24 | source $TOP_DIR/stackrc |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 25 | |
| 26 | FILES=$TOP_DIR/files |
| 27 | |
Sean Dague | 7b63c5e | 2014-06-04 16:25:52 -0400 | [diff] [blame] | 28 | PIP_GET_PIP_URL=https://bootstrap.pypa.io/get-pip.py |
Sean Dague | f625ffe | 2014-06-05 07:04:41 -0400 | [diff] [blame] | 29 | LOCAL_PIP="$FILES/$(basename $PIP_GET_PIP_URL)" |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 30 | |
| 31 | GetDistro |
| 32 | echo "Distro: $DISTRO" |
| 33 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 34 | function get_versions { |
Doug Hellmann | ddc3839 | 2015-05-07 21:06:24 +0000 | [diff] [blame] | 35 | # FIXME(dhellmann): Deal with multiple python versions here? This |
| 36 | # is just used for reporting, so maybe not? |
Attila Fazekas | 46ea723 | 2013-10-07 07:29:27 +0200 | [diff] [blame] | 37 | 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] | 38 | if [[ -n $PIP ]]; then |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 39 | PIP_VERSION=$($PIP --version | awk '{ print $2}') |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 40 | echo "pip: $PIP_VERSION" |
Attila Fazekas | 46ea723 | 2013-10-07 07:29:27 +0200 | [diff] [blame] | 41 | else |
| 42 | echo "pip: Not Installed" |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 43 | fi |
| 44 | } |
| 45 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 46 | |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 47 | function install_get_pip { |
Sean Dague | 0280f6f | 2015-10-07 09:19:53 -0400 | [diff] [blame] | 48 | # If get-pip.py isn't python, delete it. This was probably an |
| 49 | # outage on the server. |
| 50 | if [[ -r $LOCAL_PIP ]]; then |
| 51 | if ! head -1 $LOCAL_PIP | grep -q '#!/usr/bin/env python'; then |
| 52 | echo "WARNING: Corrupt $LOCAL_PIP found removing" |
| 53 | rm $LOCAL_PIP |
| 54 | fi |
| 55 | fi |
| 56 | |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 57 | # 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] | 58 | # for this to find, explicitly to avoid download issues. |
| 59 | # |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 60 | # However, if DevStack *did* download the file, we want to check |
| 61 | # for updates; people can leave their stacks around for a long |
Ian Wienand | 7c4ce9e | 2015-03-10 11:32:26 +1100 | [diff] [blame] | 62 | # time and in the mean-time pip might get upgraded. |
| 63 | # |
| 64 | # Thus we use curl's "-z" feature to always check the modified |
| 65 | # since and only download if a new version is out -- but only if |
| 66 | # it seems we downloaded the file originally. |
| 67 | if [[ ! -r $LOCAL_PIP || -r $LOCAL_PIP.downloaded ]]; then |
Sean Dague | a0cc291 | 2015-10-07 09:06:42 -0400 | [diff] [blame] | 68 | # only test freshness if LOCAL_PIP is actually there, |
| 69 | # otherwise we generate a scary warning. |
| 70 | local timecond="" |
| 71 | if [[ -r $LOCAL_PIP ]]; then |
| 72 | timecond="-z $LOCAL_PIP" |
| 73 | fi |
| 74 | |
Sean Dague | fa41b5b | 2015-10-08 06:05:20 -0400 | [diff] [blame] | 75 | curl -f --retry 6 --retry-delay 5 \ |
Sean Dague | a0cc291 | 2015-10-07 09:06:42 -0400 | [diff] [blame] | 76 | $timecond -o $LOCAL_PIP $PIP_GET_PIP_URL || \ |
Sean Dague | f625ffe | 2014-06-05 07:04:41 -0400 | [diff] [blame] | 77 | die $LINENO "Download of get-pip.py failed" |
Ian Wienand | 7c4ce9e | 2015-03-10 11:32:26 +1100 | [diff] [blame] | 78 | touch $LOCAL_PIP.downloaded |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 79 | fi |
Matthew Treinish | 1d27155 | 2016-01-19 20:29:46 -0500 | [diff] [blame] | 80 | sudo -H -E python $LOCAL_PIP -c $TOOLS_DIR/cap-pip.txt |
Doug Hellmann | ddc3839 | 2015-05-07 21:06:24 +0000 | [diff] [blame] | 81 | if python3_enabled; then |
Matthew Treinish | 1d27155 | 2016-01-19 20:29:46 -0500 | [diff] [blame] | 82 | sudo -H -E python${PYTHON3_VERSION} $LOCAL_PIP -c $TOOLS_DIR/cap-pip.txt |
Doug Hellmann | ddc3839 | 2015-05-07 21:06:24 +0000 | [diff] [blame] | 83 | fi |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 84 | } |
| 85 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 86 | |
Franck Yelles | 683ff42 | 2014-06-19 02:14:42 -0700 | [diff] [blame] | 87 | function configure_pypi_alternative_url { |
| 88 | PIP_ROOT_FOLDER="$HOME/.pip" |
| 89 | PIP_CONFIG_FILE="$PIP_ROOT_FOLDER/pip.conf" |
| 90 | if [[ ! -d $PIP_ROOT_FOLDER ]]; then |
| 91 | echo "Creating $PIP_ROOT_FOLDER" |
| 92 | mkdir $PIP_ROOT_FOLDER |
| 93 | fi |
| 94 | if [[ ! -f $PIP_CONFIG_FILE ]]; then |
| 95 | echo "Creating $PIP_CONFIG_FILE" |
| 96 | touch $PIP_CONFIG_FILE |
| 97 | fi |
| 98 | if ! ini_has_option "$PIP_CONFIG_FILE" "global" "index-url"; then |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 99 | # It means that the index-url does not exist |
Franck Yelles | 683ff42 | 2014-06-19 02:14:42 -0700 | [diff] [blame] | 100 | iniset "$PIP_CONFIG_FILE" "global" "index-url" "$PYPI_OVERRIDE" |
| 101 | fi |
| 102 | |
| 103 | } |
| 104 | |
Jeremy Stanley | 35b5283 | 2014-12-18 17:27:22 +0000 | [diff] [blame] | 105 | # Setuptools 8 implements PEP 440, and 8.0.4 adds a warning triggered any time |
| 106 | # pkg_resources inspects the list of installed Python packages if there are |
| 107 | # non-compliant version numbers in the egg-info (for example, from distro |
| 108 | # system packaged Python libraries). This is off by default after 8.2 but can |
| 109 | # be enabled by uncommenting the lines below. |
| 110 | #PYTHONWARNINGS=$PYTHONWARNINGS,always::RuntimeWarning:pkg_resources |
| 111 | #export PYTHONWARNINGS |
Franck Yelles | 683ff42 | 2014-06-19 02:14:42 -0700 | [diff] [blame] | 112 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 113 | # Show starting versions |
| 114 | get_versions |
| 115 | |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 116 | # Do pip |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 117 | |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 118 | # Eradicate any and all system packages |
Attila Fazekas | 9127c1a | 2015-11-05 10:09:02 +0100 | [diff] [blame] | 119 | |
Steve Baker | bd4048a | 2015-11-18 10:55:22 +1300 | [diff] [blame] | 120 | # Python in f23 and f22 depends on the python-pip package so removing it |
| 121 | # results in a nonfunctional system. pip on fedora installs to /usr so pip |
| 122 | # can safely override the system pip for all versions of fedora |
| 123 | if ! is_fedora ; then |
Attila Fazekas | 9127c1a | 2015-11-05 10:09:02 +0100 | [diff] [blame] | 124 | uninstall_package python-pip |
Doug Hellmann | ddc3839 | 2015-05-07 21:06:24 +0000 | [diff] [blame] | 125 | uninstall_package python3-pip |
Attila Fazekas | 9127c1a | 2015-11-05 10:09:02 +0100 | [diff] [blame] | 126 | fi |
Dean Troyer | 62d1d69 | 2013-08-01 17:40:40 -0500 | [diff] [blame] | 127 | |
Sean Dague | 7b63c5e | 2014-06-04 16:25:52 -0400 | [diff] [blame] | 128 | install_get_pip |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 129 | |
Franck Yelles | 683ff42 | 2014-06-19 02:14:42 -0700 | [diff] [blame] | 130 | if [[ -n $PYPI_ALTERNATIVE_URL ]]; then |
| 131 | configure_pypi_alternative_url |
| 132 | fi |
| 133 | |
Doug Hellmann | ddc3839 | 2015-05-07 21:06:24 +0000 | [diff] [blame] | 134 | set -x |
Jeremy Stanley | b7ebc47 | 2014-12-17 03:32:42 +0000 | [diff] [blame] | 135 | pip_install -U setuptools |
Mathieu Gagné | 76ed427 | 2014-06-05 16:50:40 -0400 | [diff] [blame] | 136 | |
Monty Taylor | dace92f | 2013-08-10 23:49:47 -0300 | [diff] [blame] | 137 | get_versions |