@@ -8,88 +8,103 @@ set -ex
88declare -r REPO_DIR=$( cd $( dirname " $0 " ) && cd .. && pwd )
99
1010pythonVersionGPG=' '
11+ python_sha=' '
1112
1213version=" $1 "
1314
1415buildPythonfromSource ()
1516{
1617 pythonVersion=$PYTHON_VERSION
17-
18- if [ ! -z " $1 " ]; then
19- echo " $1 "
20- pythonVersion=$1
21- fi
2218
23- if [ ! -z " $2 " ]; then
24- echo " $2 "
25- gpgKey=$2
26- fi
19+ # Parse named parameters
20+ while [[ $# -gt 0 ]]; do
21+ case $1 in
22+ version=* )
23+ pythonVersion=" ${1#* =} "
24+ shift
25+ ;;
26+ gpg=* )
27+ gpgKey=" ${1#* =} "
28+ shift
29+ ;;
30+ python_sha=* )
31+ python_sha=" ${1#* =} "
32+ shift
33+ ;;
34+ * )
35+ echo " Unknown parameter: $1 "
36+ shift
37+ ;;
38+ esac
39+ done
2740
2841 mkdir -p " tmpFiles"
2942 wget https://www.python.org/ftp/python/${pythonVersion%% [a-z]* } /Python-$pythonVersion .tar.xz -O /tmpFiles/python.tar.xz
30- wget https://www.python.org/ftp/python/${pythonVersion%% [a-z]* } /Python-$pythonVersion .tar.xz.asc -O /tmpFiles/python.tar.xz.asc
43+
44+ if [ -n " $python_sha " ]; then
45+ echo " Verifying Python source code using SHA256 checksum..."
46+ echo " $python_sha /tmpFiles/python.tar.xz" | sha256sum -c -
47+ echo " SHA256 verification successful!"
48+ fi
49+
50+ if [ -n " $gpgKey " ]
51+ then
52+ wget https://www.python.org/ftp/python/${pythonVersion%% [a-z]* } /Python-$pythonVersion .tar.xz.asc -O /tmpFiles/python.tar.xz.asc
53+
54+ # Try getting the keys 5 times at most
55+ /tmp/receiveGpgKeys.sh $gpgKey
56+ gpg --batch --verify /tmpFiles/python.tar.xz.asc /tmpFiles/python.tar.xz
57+ fi
3158
3259 PYTHON_GET_PIP_URL=" https://bootstrap.pypa.io/get-pip.py"
3360
3461 # for buster and ubuntu we would need following libraries
35- apt-get update && \
36- apt-get upgrade -y && \
37- DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
38- # Adding additional python packages to support all optional python modules:
39- # https://devguide.python.org/getting-started/setup-building/index.html#install-dependencies
40- build-essential \
41- gdb \
42- lcov \
43- libbluetooth-dev \
44- libbz2-dev \
45- libffi-dev \
46- libgdbm-dev \
47- libgdm-dev \
48- libgeos-dev \
49- liblzma-dev \
50- libncurses5-dev \
51- libreadline-dev \
52- libreadline6-dev \
53- libsqlite3-dev \
54- libssl-dev \
55- lzma \
56- lzma-dev \
57- pkg-config \
58- python3-dev \
59- tk-dev \
60- uuid-dev
61- uuid-dev \
62- zlib1g-dev \
63-
64- # Try getting the keys 5 times at most
65- /tmp/receiveGpgKeys.sh $gpgKey
66-
67- gpg --batch --verify /tmpFiles/python.tar.xz.asc /tmpFiles/python.tar.xz
62+ apt-get update && \
63+ apt-get upgrade -y && \
64+ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
65+ build-essential \
66+ gdb \
67+ lcov \
68+ libbluetooth-dev \
69+ libbz2-dev \
70+ libffi-dev \
71+ libgdbm-dev \
72+ libgdm-dev \
73+ libgeos-dev \
74+ liblzma-dev \
75+ libncurses5-dev \
76+ libreadline-dev \
77+ libreadline6-dev \
78+ libsqlite3-dev \
79+ libssl-dev \
80+ lzma \
81+ lzma-dev \
82+ pkg-config \
83+ python3-dev \
84+ tk-dev \
85+ uuid-dev \
86+ zlib1g-dev
87+
6888 tar -xJf /tmpFiles/python.tar.xz --strip-components=1 -C .
6989
7090 INSTALLATION_PREFIX=/opt/python/$PYTHON_VERSION
7191
72- if [ " ${PYTHON_VERSION:: 1} " == " 2" ]; then
73- ./configure \
74- --prefix=$INSTALLATION_PREFIX \
75- --build=$( dpkg-architecture --query DEB_BUILD_GNU_TYPE) \
76- --enable-shared \
77- --enable-unicode=ucs4
78- else
79- ./configure \
80- --prefix=$INSTALLATION_PREFIX \
81- --build=$( dpkg-architecture --query DEB_BUILD_GNU_TYPE) \
82- --enable-loadable-sqlite-extensions \
83- --enable-shared \
84- --with-system-expat \
85- --with-system-ffi \
86- --without-ensurepip
87- fi
92+
93+ ./configure \
94+ --prefix=$INSTALLATION_PREFIX \
95+ --build=$( dpkg-architecture --query DEB_BUILD_GNU_TYPE) \
96+ --enable-loadable-sqlite-extensions \
97+ --enable-shared \
98+ --with-system-expat \
99+ --with-system-ffi \
100+ --without-ensurepip
88101
89102 make -j $( nproc)
90103
91104 make install
92105
106+ export LD_LIBRARY_PATH=" /opt/python/$PYTHON_VERSION /lib/"
107+ $INSTALLATION_PREFIX /bin/python3 --version
93108 rm -rf /usr/src/python
94109 find /usr/local -depth \
95110 \( \
@@ -98,21 +113,18 @@ buildPythonfromSource()
98113 \) -exec rm -rf ' {}' + \
99114
100115 ldconfig
101- python3 --version
102116
103- # make some useful symlinks that are expected to exist
104- cd /usr/local /bin
117+ # make some useful symlinks that are expected to exist in the installation prefix
118+ cd $INSTALLATION_PREFIX /bin
105119 ln -s idle3 idle
106120 ln -s pydoc3 pydoc
107121 ln -s python3 python
108122 ln -s python3-config python-config
109123
110- PYTHON_GET_PIP_SHA256=" c518250e91a70d7b20cceb15272209a4ded2a0c263ae5776f129e0d9b5674309"
111-
112124 # Install pip
113125 wget " $PYTHON_GET_PIP_URL " -O /tmpFiles/get-pip.py
114126
115- python3 /tmpFiles/get-pip.py \
127+ $INSTALLATION_PREFIX /bin/ python3 /tmpFiles/get-pip.py \
116128 --trusted-host pypi.python.org \
117129 --trusted-host pypi.org \
118130 --trusted-host files.pythonhosted.org \
@@ -139,7 +151,7 @@ buildPythonfromSource()
139151 rm -rf /Python /PCbuild /Grammar /python /Objects /Parser /Misc /Tools /Programs /Modules /Include /Mac /Doc /PC /Lib
140152}
141153
142- getPythonGpgByVersion () {
154+ getPythonGpgAndShaByVersion () {
143155 local versionFile=" $1 "
144156 local versionPython=" $2 "
145157
@@ -153,24 +165,25 @@ getPythonGpgByVersion() {
153165 arg=" $( echo -e " ${VERSION_INFO} " | sed -e ' s/^[[:space:]]*//' ) "
154166 test1=$( echo $arg | cut -d' ,' -f 1)
155167 test2=$( echo $arg | cut -d' ,' -f 2)
168+ test3=$( echo $arg | cut -d' ,' -f 3)
156169
157170 if [ " $versionPython " == " $test1 " ]; then
158171 pythonVersionGPG=" $test2 "
172+ python_sha=" $test3 "
159173 fi
160174 done < " $versionFile "
161175}
162176
163-
164177echo
165- # TODO: Determine if we need to continue building newer versions of Python from scratch
166178echo " Building python 3.14 or newer from source code..."
167179
168- getPythonGpgByVersion " /tmp/versionsToBuild.txt" $version
169- IFS=' .' read -ra SPLIT_VERSION <<< " $PYTHON_VERSION "
180+ getPythonGpgAndShaByVersion " /tmp/versionsToBuild.txt" $version
181+ IFS=' .' read -ra SPLIT_VERSION <<< " $version "
170182
171183if [ " ${SPLIT_VERSION[0]} " == " 3" ] && [ " ${SPLIT_VERSION[1]} " -ge " 14" ]
172184then
173- buildPythonfromSource $version $pythonVersionGPG
185+ echo " version=$version , gpg='$pythonVersionGPG ', sha='$python_sha '"
186+ buildPythonfromSource version=$version gpg=" $pythonVersionGPG " python_sha=" $python_sha "
174187else
175188 source /tmp/oryx/images/installPlatform.sh python $version --dir /opt/python/$version --links false
176189fi
0 commit comments