-
Notifications
You must be signed in to change notification settings - Fork 33
/
python-install
executable file
·57 lines (49 loc) · 1.54 KB
/
python-install
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
#!/bin/bash
while getopts fh OPT
do
case $OPT in
"f") FLAG_FORCE="TRUE" ;;
"h") FLAG_HELP="TRUE" ;;
* ) FLAG_HELP="TRUE" ;;
esac
done
shift `expr $OPTIND - 1`
TARGET_VERSION="$1"
LOCATION="$2"
if [ "x"$FLAG_HELP != "x" -o "x$LOCATION" = "x" ]; then
echo "[usage] python-install [-f] VERSION LOCATION"
echo " ex: python-install 2.7.6 ~/local/python-2.7.6"
exit 0
fi
cd $(dirname $0)
XBUILD_PATH=$(pwd)
if [ ! -d ./var/python-build ]; then
(
set -e
mkdir -p var
cd var
git clone -q https://github.com/pyenv/pyenv.git pyenv-repo
cd pyenv-repo/plugins/python-build
PREFIX="$XBUILD_PATH"/var/python-build ./install.sh >/dev/null 2>&1
)
if [ $? -ne 0 ]; then
echo "failed to download python-build"
exit 1
fi
fi
if [ "x"$FLAG_FORCE = "x" -a -d "$LOCATION" -a -x "$LOCATION/bin/python" ]; then
current_ver=$("$LOCATION"/bin/python -V 2>&1 )
if [ "x$current_ver" = "xPython $TARGET_VERSION" ]; then
echo "python $TARGET_VERSION already installed on $LOCATION"
echo "To do force re-install, use '-f' option"
exit 0
fi
fi
echo "Start to build python $TARGET_VERSION ..."
./var/python-build/bin/python-build "$TARGET_VERSION" "$LOCATION" > /tmp/$USER-python-install.log 2>&1
if [ $? -ne 0 ]; then
echo "python-build failed. see log: /tmp/$USER-python-install.log"
exit 1
fi
echo "python $TARGET_VERSION successfully installed on $LOCATION"
echo "To use this python, do 'export PATH=$LOCATION/bin:\$PATH'."