Created
October 26, 2018 11:23
-
-
Save vmagamedov/b7d7ec84f295179332b2d3885bf8c825 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export PYTHON_VERSION="3.7.1" | |
export PYTHON_PIP_VERSION="18.1" | |
export SYSTEM_PACKAGES="" | |
export SYSTEM_DEV_PACKAGES="" | |
export PYTHON_PACKAGES="$1" | |
export PYTHON_GPG_KEY="0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D" | |
apt-get update | |
apt-get install -y --no-install-recommends ca-certificates netbase ${SYSTEM_PACKAGES} | |
# DEB install | |
export savedAptMark="$(apt-mark showmanual)" | |
apt-get update && apt-get install -y --no-install-recommends \ | |
dpkg-dev \ | |
gcc \ | |
libbz2-dev \ | |
libc6-dev \ | |
libexpat1-dev \ | |
libffi-dev \ | |
libgdbm-dev \ | |
liblzma-dev \ | |
libncursesw5-dev \ | |
libreadline-dev \ | |
libsqlite3-dev \ | |
libssl-dev \ | |
make \ | |
tk-dev \ | |
uuid-dev \ | |
wget \ | |
xz-utils \ | |
zlib1g-dev \ | |
gnupg \ | |
dirmngr \ | |
${SYSTEM_DEV_PACKAGES} | |
# PY install | |
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 "$PYTHON_GPG_KEY" | |
gpg --batch --verify python.tar.xz.asc python.tar.xz | |
gpgconf --kill all | |
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 \ | |
--without-ensurepip | |
make -j "$(nproc)" | |
make install | |
ldconfig | |
cd / | |
rm -rf /usr/src/python | |
# PIP install | |
wget -O get-pip.py 'https://bootstrap.pypa.io/get-pip.py' | |
python3 get-pip.py \ | |
--disable-pip-version-check \ | |
--no-cache-dir \ | |
"pip==$PYTHON_PIP_VERSION" | |
rm -f get-pip.py | |
# PIP-INSTALL | |
if [ "$PYTHON_PACKAGES" != "" ]; then | |
pip3 install --no-cache-dir --disable-pip-version-check ${PYTHON_PACKAGES} | |
fi | |
# DEB cleanup | |
apt-mark auto '.*' > /dev/null | |
apt-mark manual $savedAptMark | |
find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \ | |
| awk '/=>/ { print $(NF-1) }' \ | |
| sort -u \ | |
| xargs -r dpkg-query --search \ | |
| cut -d: -f1 \ | |
| sort -u \ | |
| xargs -r apt-mark manual | |
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false | |
rm -rf /var/lib/apt/lists/* | |
# PYC cleanup??? | |
find /usr/local -depth \ | |
\( \ | |
\( -type d -a \( -name test -o -name tests \) \) \ | |
-o \ | |
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \ | |
\) -exec rm -rf '{}' + |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment