#!/bin/bash export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH source <(curl -f -s --connect-timeout 10 --retry 3 https://dl.acepanel.net/public.sh) if [ $? -ne 0 ]; then echo "Download public.sh failed, please check the network or try again later." exit 1 fi slug=${1} version=${2} python_path="${setup_path}/server/python/${slug}" in_china=$(curl --retry 2 -m 10 -L -k https://www.qualcomm.cn/cdn-cgi/trace 2>/dev/null | grep -qx 'loc=CN' && echo "true" || echo "false") j=$(calculate_j) # 预检查 if [ ! -f "${python_path}/bin/python3" ]; then error "Python ${slug} is not installed" fi # 下载Python源码 PYTHON_TARBALL="Python-${version}.tar.xz" if ${in_china}; then PYTHON_URL="https://mirrors.aliyun.com/python-release/source/${PYTHON_TARBALL}" echo "Downloading ${PYTHON_TARBALL} from Aliyun mirror..." else PYTHON_URL="https://www.python.org/ftp/python/${version}/${PYTHON_TARBALL}" echo "Downloading ${PYTHON_TARBALL} from python.org..." fi cd ${python_path} rm -rf src aria2c -x8 \ -U "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36" \ -o ${PYTHON_TARBALL} \ ${PYTHON_URL} if [ $? -ne 0 ]; then error "Failed to download Python ${version}" fi # 解压 tar -xJf ${PYTHON_TARBALL} if [ $? -ne 0 ]; then rm -f ${PYTHON_TARBALL} error "Failed to extract Python ${version}" fi mv Python-${version} src rm -f ${PYTHON_TARBALL} # 仅在高配置服务器上启用优化 [ ${MEM} -ge 15000 ] && [ ${CORES} -ge 8 ] && OPTIMIZE_FLAG="--enable-optimizations --with-lto" || OPTIMIZE_FLAG="" # 编译安装 cd src ./configure --prefix=${python_path} ${OPTIMIZE_FLAG} --enable-shared LDFLAGS="-Wl,-rpath,${python_path}/lib" if [ $? -ne 0 ]; then error "Configure failed" fi make "-j${j}" if [ $? -ne 0 ]; then error "Compilation failed" fi make install if [ ! -f "${python_path}/bin/python3" ]; then error "Python ${version} upgrade failed" fi # 清理源码 cd ${python_path} rm -rf src echo -e $HR echo "Upgrade successful" echo -e $HR