forked from M0E-lnx/ubuntu-32bit
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build_install_pythons.sh
executable file
·112 lines (102 loc) · 3.89 KB
/
build_install_pythons.sh
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
#!/bin/bash
# Install Pythons 2.7 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 and matching pips
set -ex
echo "deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu trusty main" > /etc/apt/sources.list.d/deadsnakes.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6A755776
apt-get update
apt-get install -y wget
PIP_ROOT_URL="https://bootstrap.pypa.io"
wget $PIP_ROOT_URL/get-pip.py
for pyver in 3.4 ; do
pybin=python$pyver
apt-get install -y ${pybin}-dev ${pybin}-tk
get_pip_fname="get-pip.py"
# Older Pythons need older versions of pip
# These stored in URL directories named for the version.
get_pip_fname="get-pip-${pyver}.py"
wget $PIP_ROOT_URL/pip/${pyver}/get-pip.py -O $get_pip_fname
${pybin} ${get_pip_fname}
done
# Get virtualenv for Python 3.4
pip3.4 install --user virtualenv
BUILD_PKGS="zlib1g-dev libbz2-dev libncurses5-dev libreadline-gplv2-dev \
libsqlite3-dev libssl-dev libgdbm-dev tcl-dev tk-dev \
libffi-dev liblzma-dev uuid-dev"
apt-get -y install build-essential $BUILD_PKGS
function compile_python {
local py_ver="$1"
local extra_args="$2"
local default_abi_suff="m"
local py_nodot=$(echo ${py_ver} | awk -F "." '{ print $1$2 }')
# Python 3.8 and up no longer uses the PYMALLOC 'm' suffix
# https://github.com/pypa/wheel/pull/303
if [ ${py_nodot} -ge "38" ]; then
default_abi_suff=""
fi
local abi_suff="${3:-$default_abi_suff}"
local froot="Python-${py_ver}"
local ftgz="${froot}.tgz"
# Drop any suffix from three-digit version number
local py_nums=$(echo $py_ver | awk -F "." '{printf "%d.%d.%d", $1, $2, $3}')
wget https://www.python.org/ftp/python/${py_nums}/${ftgz}
tar zxf ${ftgz}
local out_root=/opt/cp${py_nodot}${abi_suff}
mkdir $out_root
(cd Python-${py_ver} \
&& ./configure --prefix=$out_root ${extra_args} \
&& make \
&& make install)
# Remove stray files
rm -rf ${froot} ${ftgz}
}
# Compile wide and narrow unicode Python
# Compiled Pythons need to be flagged in the choose_python.sh script.
compile_python 2.7.18 "--enable-unicode=ucs4" "mu"
/opt/cp27mu/bin/python -m ensurepip
compile_python 2.7.18 "--enable-unicode=ucs2"
/opt/cp27m/bin/python -m ensurepip
# Compile Python 3.7.0, pip comes along with.
# Python 3.7 from deadsnakes does not appear to have SSL.
# Compilation needs SSL 1.0.2, not available for Trusty.
function build_openssl {
local version=$1
local froot="openssl-${version}"
local ftgz="${froot}.tar.gz"
tar xvf ${ftgz}
(cd $froot &&
./config no-ssl2 no-shared -fPIC --prefix=/usr/local/ssl &&
make &&
make install)
rm -rf ${froot} ${ftgz}
}
build_openssl 1.1.1t
# Compiled Pythons need to be flagged in the choose_python.sh script.
compile_python 3.3.7 "--with-openssl=/usr/local/ssl"
compile_python 3.5.10 "--with-openssl=/usr/local/ssl"
compile_python 3.6.15 "--with-openssl=/usr/local/ssl"
compile_python 3.7.16 "--with-openssl=/usr/local/ssl"
compile_python 3.8.16 "--with-openssl=/usr/local/ssl"
compile_python 3.9.16 "--with-openssl=/usr/local/ssl"
compile_python 3.10.10 "--with-openssl=/usr/local/ssl"
compile_python 3.11.2 "--with-openssl=/usr/local/ssl"
# Install certificates from certifi, for Python 3.7
# Thanks to Github user Mr BitBucket for this fix.
# Make virtuelenv for certifi install.
/root/.local/bin/virtualenv --python=/opt/cp37m/bin/python3 venv
. venv/bin/activate
# Install certifi and copy .pem file to system locaation.
pip install certifi
CERTIFI_CERT=$(python -c "import certifi; print(certifi.where())")
DEFAULT_CERT=$(python -c"import ssl; print(ssl.get_default_verify_paths().openssl_cafile)")
echo "CERTIFI_CERT=$CERTIFI_CERT"
echo "DEFAULT_CERT=$DEFAULT_CERT"
cp ${CERTIFI_CERT} ${DEFAULT_CERT}
deactivate
# Remove virtualenv files from image
rm -rf venv
# Clean out not-needed packages
apt-get -y remove $BUILD_PKGS
apt-get -y autoremove
apt-get clean
# Remove stray files
rm -f get-pip*.py