-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpip_installer.sh
More file actions
executable file
·140 lines (119 loc) · 3.43 KB
/
Copy pathpip_installer.sh
File metadata and controls
executable file
·140 lines (119 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
#
# Pip Installer
#
# Copyright (C) 2014 Harrison Feng <feng.harrison@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
#
# Generally, py26 and py27 don't ship with pip, setuptools and
# virtualenv default. This script is used to install pip in
# py26/py27, then upgrade setuptools. Of course, virtualenv will
# be in place.
#
# Usage:
#
# # make sure you have root permission
# git clone https://github.com/harrisonfeng/pythoninstaller.git
# cd pythoninstaller
# ./pip_installer.sh
#
VERSION=0.1.3
PYTHON_VERSION=$1
INSTALL_DIR_PREFIX=$2
# dirs for use-installed python
PYTHON_BIN_DIR=${INSTALL_DIR_PREFIX}/python${PYTHON_VERSION}/bin
# paths for binaries
PYTHON_BIN=${PYTHON_BIN_DIR}/python
PIP_BIN=${PYTHON_BIN_DIR}/pip
VIRTUALENV_BIN=${PYTHON_BIN_DIR}/virtualenv
function usage {
echo
echo "./pip_installer [python_version]"
echo
echo "If python_version is missing, install pip \
for default python installation"
echo
}
if [ -z ${PYTHON_VERSION} ]; then
echo
echo "python_version is missing,\
install pip for default python installation"
echo
PYTHON_BIN=`which python`
fi
#
# Dist identification functions
#
function is_fedora {
[ -f /usr/bin/yum ] && cat /etc/*release | grep -q -e "Fedora"
}
function is_rhel6 {
[ -f /usr/bin/yum ] && \
cat /etc/*release | grep -q -e "Red Hat" -e "CentOS" && \
cat /etc/*release | grep -q 'release 6'
}
function is_rhel7 {
[ -f /usr/bin/yum ] && \
cat /etc/*release | grep -q -e "Red Hat" -e "CentOS" && \
cat /etc/*release | grep -q 'release 7'
}
function is_ubuntu {
[ -f /usr/bin/apt-get ]
}
function setup_pip {
# Install pip using get-pip
local GET_PIP_URL=https://bootstrap.pypa.io/get-pip.py
local ret=1
if [ -f ./get-pip.py ]; then
ret=0
elif type curl >/dev/null 2>&1; then
curl -O ${GET_PIP_URL}
ret=$?
elif type wget >/dev/null 2>&1; then
wget ${GET_PIP_URL}
ret=$?
fi
if [ $ret -ne 0 ]; then
echo "Failed to get get-pip.py"
exit 1
fi
if is_rhel6; then
echo
echo "Your system is `cat /etc/centos-release`"
echo "Clean up your old setuptools..."
yum erase -y python-setuptools
rm -rf /usr/lib/python2.6/site-packages/setuptools*
echo "================ cleanup ends ================"
echo
fi
# install pip
sudo ${PYTHON_BIN} get-pip.py
}
if [ -z ${PYTHON_VERSION} ]; then
echo
echo "python_version is missing,\
install pip for default python installation"
echo
PYTHON_BIN=`which python`
fi
setup_pip
if [ -z ${PYTHON_VERSION} ]; then
PIP_BIN=`which pip`
fi
echo "Upgrading setuptools..."
sudo ${PIP_BIN} install --upgrade setuptools
echo "Installing virtualenv ..."
sudo ${PIP_BIN} install --upgrade virtualenv
rm -rf get-pip.py