python3.6.4源码安装

时间:2023-03-10 07:00:07
python3.6.4源码安装

该脚本适合centos6和ubuntu用,关于debian可以根据脚本中的范例自己添加

微笑哥与你每天进步一点点

#!/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 "时间同步中,请稍候....."

service ntpd start >/dev/null
   echo $? >/dev/null
 if [ $? -ne 0 ];then
     yum -y install ntpd && service ntpd start >/dev/null
 fi
    ntpdate time.nist.gov >/dev/null
     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 "=======安装前请把yum源配好,(ctrl + c停止)======="
    echo "您的系统是:`cat /etc/issue`"
    echo "您的内核是:`uname -r`"
    echo "您的外网publicIP是:$local_IP"

#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/
echo -e  "\t\t#####################"
echo -e  "\t\t#         输入exit()可退出    #"
echo -e  "\t\t#####################"
python3.6