-
Notifications
You must be signed in to change notification settings - Fork 69
/
pythonz-install
executable file
·110 lines (88 loc) · 2.56 KB
/
pythonz-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
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
#!/usr/bin/env bash
shopt -s extglob
PYTHONS="`command -v python` /usr/bin/python /usr/bin/python2 /usr/bin/python3"
CURL=`command -v curl`
FETCH=`command -v fetch`
trim()
{
trimmed=$1
trimmed="${trimmed#"${trimmed%%[![:space:]]*}"}" # remove leading whitespace characters
trimmed="${trimmed%"${trimmed##*[![:space:]]}"}" # remove trailing whitespace characters
echo $trimmed
}
usage()
{
printf "
Usage:
${0} [options]
options:
--python : Python interpreter.
"
}
parse_arguments()
{
for arg do
val=`echo "$arg" | sed -e "s;--[^=]*=;;"`
case "$arg" in
--python=*) PYTHONS="$val $PYTHONS" ;;
--help) usage ;;
*) echo "Can't find the option. :$arg";;
esac
done
}
parse_arguments $@
if [[ ! -x $CURL ]] && [[ ! -x $FETCH ]] ; then
echo "pythonz required curl or fetch. Neigher of them were not found in your path."
exit 1
fi
for PYTHON in $PYTHONS ; do
if [[ ! -x $PYTHON ]] ; then
continue
fi
PYTHON_VERSION=`$PYTHON -V 2>&1`
PYTHON_VERSION=${PYTHON_VERSION/"Python "/""}
PYTHON_VERSION_S=`echo $PYTHON_VERSION | sed -e "s/\(^[[:digit:]]\{1,\}.[[:digit:]]\{1,\}\).*/\1/"`
if [[ $PYTHON_VERSION_S = "2.6" ]] || [[ $PYTHON_VERSION_S = "2.7" ]] || [[ ${PYTHON_VERSION_S:0:1} = "3" ]] ; then
PYTHON_FOUND='1'
break
fi
done
if [[ $PYTHON_FOUND != '1' ]] ; then
echo "pythonz requires Python 2.6, 2.7 or higher"
exit 1
fi
systemwide_install=0
if [[ -n "$PYTHONZ_ROOT" ]] ; then
ROOT="$PYTHONZ_ROOT"
else
if (( UID == 0 )) ; then
systemwide_install=1
ROOT="/usr/local/pythonz"
else
ROOT="$HOME/.pythonz"
fi
fi
PATH_DISTS="$ROOT/dists"
TEMP_TARBALL="pythonz-latest.tar.gz"
DOWNLOAD_URL="https:/saghul/pythonz/tarball/master"
mkdir -p "$PATH_DISTS"
rm -rf "$PATH_DISTS/pythonz*"
echo "Downloading $DOWNLOAD_URL"
if [[ -x $CURL ]] ; then
builtin cd $PATH_DISTS ; curl --progress-bar -kL $DOWNLOAD_URL -o "$TEMP_TARBALL"
elif [[ -x $FETCH ]] ; then
builtin cd $PATH_DISTS ; fetch -o "$TEMP_TARBALL" $DOWNLOAD_URL
fi
echo "Extracting $PATH_DISTS/$TEMP_TARBALL"
builtin cd $PATH_DISTS ; tar zxf $TEMP_TARBALL
TEMP_FILE=`tar -tf $TEMP_TARBALL | head -n1 | sed 's/\///g'`
echo "Installing pythonz into $ROOT"
if (( systemwide_install == 1 )) ; then
PYTHONZ_ROOT="$ROOT" $PYTHON $PATH_DISTS/$TEMP_FILE/pythonz_install.py --systemwide
else
$PYTHON $PATH_DISTS/$TEMP_FILE/pythonz_install.py
fi
if [[ $? == 1 ]] ; then
echo "Failed to install pythonz."
exit 1
fi