-
Notifications
You must be signed in to change notification settings - Fork 3
/
install-python
executable file
·114 lines (100 loc) · 2.26 KB
/
install-python
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
#!/bin/bash
# set -x
function error_exit {
echo
echo "Error on line $@"
exit 1
}
trap 'error_exit ${LINENO}' ERR
usage () {
echo "install-python <version> /install/directory/prefix"
echo "Likely versions listed at http://python.org/download/releases/"
exit 1
}
version=$1 ; shift
if [ -z "$1" ] ; then
usage
fi
prefix="$(readlink -m $1)"
if [ ! -f "$prefix" ] ; then
mkdir -p $prefix
fi
# derived
srcdir="Python-$version"
tarball="$srcdir.tgz"
url="http://python.org/ftp/python/$version/$tarball"
# a better way to get just the first two digits?
version_2digit="$(echo $version | tr '.' ' ' | awk '{print $1"."$2}')"
executable="$prefix/bin/python${version_2digit}"
download () {
if [ -f "$tarball" ] ; then
echo " - file already exists: $tarball"
return
fi
if [ -n "$(which wget)" ] ; then
echo " + wget'ing $url"
wget --no-check-certificate -q $url
return
fi
if [ -n "$(which curl)" ] ; then
echo " + curl'ing $url"
curl -s $url
return
fi
echo "** Error: no download method **"
exit 1
}
unpack () {
if [ -d "$srcdir" ] ; then
echo " - directory already exists: $srcdir"
return
fi
echo " + unpacking $tarball"
tar -xzf $tarball
}
install () {
pushd $srcdir > /dev/null 2>&1
if [ -f "config.status" ] ; then
echo " - source already configured: $(pwd)"
else
local log="log.configure"
echo " + configuring, log to $srcdir/$log"
./configure --prefix=$prefix --disable-shared > $log 2>&1
fi
if [ -f "python" ] ; then
echo " - already built: $(pwd)"
else
local log="log.make"
echo " + building, log to $srcdir/$log"
make > $log 2>&1
fi
if [ -f "$executable" ] ; then
echo " - already installed: $executable"
else
local log="log.install"
echo " + installing, log to $srcdir/$log"
make prefix=$prefix install > $log 2>&1
fi
if [ ! -x "$executable" ] ; then
echo "Nothing at $executable"
echo "Something's broken."
exit 1
fi
popd > /dev/null 2>&1
}
blurb () {
echo
echo "Python installed into $prefix"
echo "You may remove the temporary files:"
echo
echo " \$ rm -rf $tarball $srcdir"
echo
echo "To use this Python set these variables:"
echo
echo " PATH=$prefix/bin:\$PATH"
echo
}
download
unpack
install
blurb