{% raw %}
#!/bin/bash
set -ex
export PATH=/usr/local/bin:$PATH
export LANG=C.UTF-8
export GPG_KEY=0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D
export PYTHON_VERSION=3.9
rm -rf /var/lib/apt/lists/* && \
apt-get update && apt-get install -y --no-install-recommends tcl tk libssl-dev && rm -rf /var/lib/apt/lists/* && \
apt-get update && apt-get install -y dpkg-dev tcl-dev tk-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* && \
wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" && \
wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" && \
export GNUPGHOME="$(mktemp -d)" && \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" && \
gpg --batch --verify python.tar.xz.asc python.tar.xz && \
rm -rf "$GNUPGHOME" python.tar.xz.asc && \
mkdir -p /usr/src/python && \
tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz && \
rm python.tar.xz && \
cd /usr/src/python/ && \
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" && \
./configure --build="$gnuArch" --enable-loadable-sqlite-extensions --enable-shared --with-system-expat --with-system-ffi && \
make -j "$(nproc)" && \
make install && \
apt-get purge -y --auto-remove dpkg-dev tcl-dev tk-dev && \
find /usr/local -depth \( \( -type d -a \( -name test -o -name tests \) \) -o \( -type f -a \( -name "*.pyc" -o -name "*.pyo" \) \) \) -exec rm -rf '{}' + && \
cd $HOME && \
rm -rf /usr/src/python
export PYTHON_PIP_VERSION=10.0.1
wget -O get-pip.py 'https://bootstrap.pypa.io/get-pip.py'
python3 get-pip.py --disable-pip-version-check "pip==$PYTHON_PIP_VERSION"
find /usr/local -depth \( \( -type d -a \( -name test -o -name tests \) \) -o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \) -exec rm -rf '{}' +;
rm -f get-pip.py
{% endraw %}