#!/bin/bash
# 安装依赖以及升级索引
yum -y groupinstall "Development tools"
yum install -y zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
 
yum update -y
yum upgrade -y
 

wget https://www.openssl.org/source/openssl-1.1.1t.tar.gz
tar -zxvf openssl-1.1.1t.tar.gz
cd ./openssl-1.1.1t
./config --prefix=/usr/local/openssl11
make -j
make install
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl/ /usr/include/openssl.bak
ln -s /usr/local/openssl11/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl11/include/openssl /usr/include/openssl
ln -s /usr/local/openssl11/lib/libssl.so.1.1 /usr/local/lib64/libssl.so 
echo "/usr/local/openssl11/lib" >> /etc/ld.so.conf
ldconfig -v
# python的大版本号
py_version=3.11
# python的具体版本号
version=$py_version.9
# 要安装的路径
install_path=/usr/local/python3119
#-----可变参数-end-----
 
echo -e '即将安装python$version'
echo -e '安装路径为$install_path'
 

# 创建安装目录文件夹
mkdir -p $install_path
 
# 下载python
echo -e '正在下载'
# 使用官方网址下载--速度可能比较慢
# wget https://www.python.org/ftp/python/$version/Python-$version.tgz
# 使用国内华为镜像源下载python
wget https://mirrors.huaweicloud.com/python/$version/Python-$version.tgz
echo -e "正在解压"
# 静默解压
tar -xzf Python-$version.tgz
# 删除压缩包
echo -e "解压完成，移除压缩包"
rm -rf Python-$version.tgz
 
echo -e "正在安装"
cd Python-$version
./configure --prefix=$install_path --with-openssl=/usr/local/openssl11 --with-openssl-rpath=auto   # 配置安装位置
make
make install
 
echo -e "配置软连接"
rm -rf /usr/bin/python$py_version /usr/bin/pip$py_version
ln -s $install_path/bin/python$py_version /usr/bin/python$py_version
ln -s $install_path/bin/pip$py_version /usr/bin/pip$py_version
 
cd ..
rm -rf Python-$version
echo -e "完成安装Python-$version"
