python3.6.4源码安装

如在执行中发现有异常时,请自行排查修改

[root@master ~]# cat python3_install.sh
#!/bin/bash
#Check system
check_sys(){
    local checkType=$1
    local value=$2

    local release=''
    local systemPackage=''

if [[ -f /etc/redhat-release ]]; then
    release="centos"
    systemPackage="yum"
elif cat /etc/issue | grep -Eqi "debian"; then
    release="debian"
    systemPackage="apt"
elif cat /etc/issue | grep -Eqi "ubuntu"; then
    release="ubuntu"
    systemPackage="apt"
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
    release="centos"
    systemPackage="yum"
elif cat /proc/version | grep -Eqi "debian"; then
    release="debian"
    systemPackage="apt"
elif cat /proc/version | grep -Eqi "ubuntu"; then
    release="ubuntu"
    systemPackage="apt"
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
    release="centos"
    systemPackage="yum"
fi

if [[ ${checkType} == "sysRelease" ]]; then
  if [ "$value" == "$release" ]; then
    return 0
  else
    return 1
  fi
elif [[ ${checkType} == "packageManager" ]]; then
  if [ "$value" == "$systemPackage" ]; then
    return 0
  else
    return 1
  fi
fi
}

 

# Get version
getversion(){
if [[ -s /etc/redhat-release ]]; then
  grep -oE "[0-9.]+" /etc/redhat-release
else
  grep -oE "[0-9.]+" /etc/issue
fi
}

pre_install(){
if check_sys packageManager yum || check_sys packageManager apt; then
# Not support CentOS 5
    if centosversion 5; then
        echo -e "$[{red}Error${plain}] Not supported CentOS 5, please change to CentOS 6+/Debian 7+/Ubuntu 12+ and try again."
	exit 1
    fi
else
    echo -e "[${red}Error${plain}] Your OS is not supported. please change OS to CentOS/Debian/Ubuntu and try again."
    exit 1
fi
}


local_IP=`curl -s ident.me`
if check_sys packageManager yum; then
  echo ""
  echo ""
  echo "=======安装前请把yum源配好,(ctrl + c停止)======="
  echo "您的系统是:`cat /etc/centos-release`"
  echo "您的内核是:`uname -r`"
  echo "您的外网publicIP是: $local_IP"

# centos的设置倒计时
kk=5
echo "时间同步中,请稍候....."

systemctl start chronyd > /dev/null
if [ $? -ne 0 ];then
  yum -y install chrony && systemctl start chronyd > /dev/null
  sed -i '/#server 3/a\server ntp.aliyun.com iburst' /etc/chrony.conf
fi
hwclock --systohc >/dev/null
hwclock -w >/dev/null

while [ $kk -gt 0 ];do
echo -n $kk
sleep 1
kk=$(($kk - 1))
echo -ne "\r   \r"
done
fi

# 系统判断
if check_sys packageManager apt; then
    echo ""
    echo ""
    echo "=======安装前请把apt源配好,(ctrl + c停止)======="
    echo "您的系统是:`cat /etc/issue`"
    echo "您的内核是:`uname -r`"
    echo "您的外网publicIP是:$local_IP"
fi
# ubuntu的设置倒计时
if check_sys packageManager apt; then
    echo ""
    echo ""
    echo "=======安装前请把yum源配好,(ctrl + c停止)======="
    echo "您的系统是:`cat /etc/issue`"
    echo "您的内核是:`uname -r`"
    echo "您的外网publicIP是:$local_IP"

kk=5
echo "时间同步中,请稍候....."
    service ntp start >/dev/null
    echo $? >/dev/null
if [ $? -ne 0 ];then
    sudo apt install ntp || service ntp restart >/dev/null
fi
sudo hwclock --systohc >/dev/null
sudo hwclock -w >/dev/null


while [ $kk -gt 0 ];do
echo -n $kk

sleep 1
kk=$(($kk - 1))
  echo -ne "\r       \r"
done
fi

# 按任意键开始设置
get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty raw
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}

sleep 3
echo "时间同步完毕,按任意键继续...."
char=`get_char`

# 系统确定后的执行命令
if check_sys packageManager yum;then
    yum install -y wget readline-devel gcc*
elif check_sys packageManager apt; then
    sudo apt-get -y update
    sudo apt-get -y install wget lrzsz gcc make \
    libbz2-dev libsqlite3-dev python3-dev libxml2-dev libffi-dev libssl-dev zlib1g-dev
fi


if [ ! -d /opop ];then
    mkdir /opop
fi
cd /opop/
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
tar -zxvf Python-3.6.4.tgz || tar -xf Python-3.6.4.tgz ./
cd Python-3.6.4
./configure --prefix=/usr/local/python3
make && make install
ln -sv /usr/local/python3/bin/python3.6  /usr/bin/
yum -y install python3-pip
echo -e  "\t\t#####################"
echo -e  "\t\t#  输入exit()可退出   #"
echo -e  "\t\t#####################"
python3.6


欢迎加入QQ群一起讨论Linux、开源等技术

posted @ 2018-01-13 18:53  Linux大魔王  阅读(1014)  评论(0编辑  收藏  举报