#!/bin/bash

# Set failfast
set -e
set -o pipefail

# Install Python 3.10
PYTHON_VERSION=3.10.9
yum install -y gcc
yum install -y epel-release
yum install -y openssl11-devel
yum install -y bzip2-devel
yum install -y libffi-devel

cd /opt
wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz
tar xzf Python-$PYTHON_VERSION.tgz && cd Python-$PYTHON_VERSION
# tragic workaround to make Python find openssl 1.1 instead of not finding 1.0
sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure
./configure --enable-optimizations
make altinstall
cd ..
rm -rf Python-$PYTHON_VERSION.tgz
yum clean all
rm -rf /var/cache/yum

# Make symbolic link of python3 install to where it's installed on dev
mkdir -p /home/ssa/bin
ln -s "$(which python3.10)" /home/ssa/bin/python3.10