-
-
Save molinav/1f3a50fbf645a1c0c8b4d2c00540155e to your computer and use it in GitHub Desktop.
#! /bin/bash | |
# | |
# Copyright (c) 2020 Víctor Molina García | |
# MIT License | |
# | |
# Script to install Python environments 2.6+ and 3.2+ using PyEnv | |
# and the installation steps for OpenSSL 1.0.2 mostly based on the | |
# information available in the following link: | |
# http://www.linuxfromscratch.org/blfs/view/7.7/postlfs/openssl.html | |
# | |
# Tested on Ubuntu 20.04; bash is required because otherwise the PyEnv | |
# initialisation command fails. | |
# | |
# Set to exit on error. | |
set -e | |
cwd=$(pwd) | |
# Install basic dependencies. | |
echo "Installing basic dependencies..." | |
sudo apt-get install -y build-essential wget curl llvm git libssl-dev tk-dev \ | |
libncursesw5-dev libreadline-dev libsqlite3-dev \ | |
libffi-dev xz-utils zlib1g-dev libbz2-dev liblzma-dev | |
sudo apt-get install -y openssl ca-certificates | |
# Download and install OpenSSL 1.0.2. | |
openssl_name=openssl-1.0.2 | |
openssl_targz=$openssl_name.tar.gz | |
openssl_patch=$openssl_name-fix_parallel_build-1.patch | |
openssl_dir=$HOME/.local/opt/$openssl_name | |
openssl_inc=$openssl_dir/include | |
openssl_lib=$openssl_dir/lib | |
openssl_ssl=$openssl_dir/ssl | |
echo "Downloading OpenSSL..." | |
wget https://www.openssl.org/source/$openssl_targz | |
wget https://www.linuxfromscratch.org/patches/downloads/openssl/$openssl_patch | |
echo "Decompressing OpenSSL..." | |
tar -xf $openssl_targz | |
echo "Patching OpenSSL..." | |
cd $openssl_name | |
patch -Np1 -i ../$openssl_patch | |
echo "Installing OpenSSL..." | |
./config --prefix=$openssl_dir --openssldir=$openssl_dir/ssl --libdir=lib \ | |
-Wl,-rpath=$openssl_dir/lib shared zlib-dynamic | |
make | |
make install | |
cd $cwd | |
rm -rf $openssl_name | |
echo "Linking CA certificates..." | |
rmdir $openssl_ssl/certs && ln -s /etc/ssl/certs $openssl_ssl/certs | |
# Download PyEnv from its GitHub repository. | |
export PYENV_ROOT=$HOME/.local/share/pyenv | |
export PATH=$PYENV_ROOT/bin:$PATH | |
git clone https://github.com/pyenv/pyenv.git $HOME/.local/share/pyenv | |
eval "$(pyenv init -)" | |
echo "Installing all Pythons..." | |
# Install Python versions that can use OpenSSL v1.1. | |
pyenv install 3.9.0 | |
pyenv install 3.8.6 | |
pyenv install 3.7.9 | |
pyenv install 3.6.12 | |
pyenv install 3.5.10 | |
pyenv install 2.7.18 | |
# Install Python versions that require the elder OpenSSL v1.0.2. | |
export CFLAGS="-I$openssl_inc" | |
export LDFLAGS="-L$openssl_lib" | |
export LD_LIBRARY_PATH="$openssl_lib" | |
pyenv install 3.4.10 | |
pyenv install 3.3.7 | |
pyenv install 3.2.6 | |
pyenv install 2.6.9 | |
echo "Remember to set LD_LIBRARY_PATH=$openssl_lib in your .bashrc file:" | |
echo " LD_LIBRARY_PATH=$openssl_lib:\$LD_LIBRARY_PATH" |
Thanks the old OpenSSL installation!
Thanks a lot bro, i was needing old python to test an arduino esp32 emulator, works like a charm! love and hugs for you.
@molinav I am getting a 403 error when trying to download the patch file from here: http://www.linuxfromscratch.org/patches/blfs/7.7/openssl-1.0.2-fix_parallel_build-1.patch Do you know where I can get that file from?
@fc2brown You can try commenting out lines 43-45. If I remember correctly, the patch was fixing the parallel build of OpenSSL 1.0.2 but nothing from the OpenSSL source code. It will simply compile with one single process.
You can also replace line 28 with openssl_name=openssl-1.0.2j
. OpenSSL 1.0.2j is the last version that works with all the EOL Python versions.
@fc2brown You can try commenting out lines 43-45. If I remember correctly, the patch was fixing the parallel build of OpenSSL 1.0.2 but nothing from the OpenSSL source code. It will simply compile with one single process.
You can also replace line 28 with
openssl_name=openssl-1.0.2j
. OpenSSL 1.0.2j is the last version that works with all the EOL Python versions.
Found this new patch link:
https://www.linuxfromscratch.org/patches/downloads/openssl/openssl-1.0.2-fix_parallel_build-1.patch
@ewertao Thanks! I have just updated the gist.
I have applied two main changes:
python < 3.5
,python != 2.7
) due to the lack of certificates. I workaround it by installingca-certificates
and adding a symbolic link to them for OpenSSL 1.0.2.