|
|
#!/bin/bash |
|
|
set -e |
|
|
|
|
|
apt update -y || { echo "apt update failed"; exit 1; } |
|
|
apt upgrade -y || { echo "apt upgrade failed"; exit 1; } |
|
|
|
|
|
apt install -y software-properties-common wget build-essential \ |
|
|
zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev \ |
|
|
libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev |
|
|
|
|
|
if [ -x "$(command -v add-apt-repository)" ]; then |
|
|
echo "Adding Python PPA repository (deadsnakes)..." |
|
|
add-apt-repository -y ppa:deadsnakes/ppa || { echo "Failed to add Python PPA repository"; exit 1; } |
|
|
fi |
|
|
|
|
|
apt update -y |
|
|
if apt install -y python3.12 python3.12-venv python3.12-dev; then |
|
|
echo "--------------------------------------" |
|
|
echo "Python 3.12 successfully installed from repositories." |
|
|
echo "--------------------------------------" |
|
|
python3.12 --version |
|
|
else |
|
|
echo "Python 3.12 not available in repositories, installing from source." |
|
|
PYTHON_VERSION="3.12.0" |
|
|
PYTHON_SRC="https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz" |
|
|
wget "$PYTHON_SRC" -O /tmp/Python-$PYTHON_VERSION.tgz |
|
|
cd /tmp |
|
|
tar -xf Python-$PYTHON_VERSION.tgz |
|
|
cd Python-$PYTHON_VERSION |
|
|
./configure --enable-optimizations |
|
|
CPU_CORES=$(nproc || echo 1) |
|
|
make -j"$CPU_CORES" || { echo "Compilation failed"; exit 1; } |
|
|
make altinstall || { echo "Make altinstall failed"; exit 1; } |
|
|
fi |
|
|
|
|
|
python3.12 --version |
|
|
|
|
|
if command -v python3.12 >/dev/null 2>&1; then |
|
|
echo "Installing pip for Python 3.12..." |
|
|
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.12 || { echo "pip installation failed"; exit 1; } |
|
|
echo "pip successfully installed." |
|
|
else |
|
|
echo "Python 3.12 not found, skipping pip installation." |
|
|
exit 1 |
|
|
fi |
|
|
|
|
|
cd ~ |
|
|
if [ -d /tmp/Python-$PYTHON_VERSION ]; then |
|
|
echo "Removing temporary files..." |
|
|
rm -rf /tmp/Python-$PYTHON_VERSION |
|
|
fi |
|
|
|
|
|
rm -f /tmp/Python-$PYTHON_VERSION.tgz 2>/dev/null || true |
|
|
|
|
|
echo "--------------------------------------" |
|
|
echo "Python 3.12 and pip installation completed successfully." |
|
|
echo "--------------------------------------" |
|
|
|
|
|
apt-get install -y python3-venv || true |
|
|
apt-get install -y python3.12-venv || true |
|
|
apt-get install -y libgl1-mesa-glx || true |
|
|
|
|
|
echo "--------------------------------------" |
|
|
echo "All done! The extra packages have been attempted." |
|
|
echo "If any failed, the script will have continued anyway." |
|
|
echo "--------------------------------------" |
|
|
|