-
Notifications
You must be signed in to change notification settings - Fork 3
/
python3
39 lines (38 loc) · 1.89 KB
/
python3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
P=Python;
p=python;
r=/usr/local/python3;
y=https://www.yanyu.ltd/;
tools=https://raw.githubusercontent.com/mslxi/mslx/main/tools;
green(){
echo -e "\033[32m\033[01m$1\033[0m"
}
if [[ -x "$(command -v ${p}3)" ]];then if [[ $(${p}3 --version |grep -i "${p} 3") ]];
then green "检测到${p}3环境,是否继续,继续会删除所有python3环境然后编译安装${P}";fi;
green 继续操作输入yes
read -p ": " yn;fi;
if [[ $(echo ${yn}|grep -v "yes") != "" ]];then echo "退出操作";exit 1;fi;
if [[ $(echo ${yn}|grep -i "yes") != "" ]];
then rm -rf $(whereis ${p}3);fi;
if [[ $(cat /etc/issue |grep -i "centos") != "" ]];
then a=yum;$a update -y;$a install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel -y;fi ;
if [[ $(cat /etc/issue |grep -i -E "debian|ubuntu") != "" ]];
then a=apt;$a update -y;$a -y install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev;fi ;
if [ ! -d $r ];then mkdir $r ;fi ;cd $r;
green "当前网络环境是否国内网络环境?yes则使用国内代理"
read -p "yes或者回车" gh;
if [[ $(echo ${gh} | grep -i "yes") != "" ]];then $url=${y}${url};fi;
green 输入要安装的python版本,到https://www.python.org/ftp/python/查看版本号,例如3.10.2
read -p ":" v;
url=https://www.${p}.org/ftp/${p}/${v}/${P}-${v}.tgz;
tar -zxvf <(wget -qO- ${url});
cd ${P}-${v};
./configure --prefix=${r}/${P}-${v};
make;make install;
mv ${r}/${P}-${v}/${p} /usr/bin/${p}3;
mv ${r}/${P}-${v}/bin/pip3 /usr/local/bin/pip3;
if ! [ -x "$(command -v ${p}3)" ];then echo "当前没有${p}3环境,安装失败!请排查";fi;
if [[ $(${p}3 --version|grep -i "${P} ${v}") != "" ]];then echo 安装成功;fi ;
if [[ $(${p}3 --version|grep -v "${P} ${v}") != "" ]];then echo 安装失败;fi ;
echo "当前${p}版本为"$(${p}3 --version);echo '脚本自动安装版本为'${P}${v};
bash <(curl ${tools})