python.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.cn
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 6+ Debian 7+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Install_Python() {
  11. if [ -e "${python_install_dir}/bin/python" ]; then
  12. echo "${CWARNING}Python already installed! ${CEND}"
  13. else
  14. pushd ${oneinstack_dir}/src > /dev/null
  15. if [ "${CentOS_ver}" == '7' ]; then
  16. [ ! -e /etc/yum.repos.d/epel.repo ] && cat > /etc/yum.repos.d/epel.repo << EOF
  17. [epel]
  18. name=Extra Packages for Enterprise Linux 7 - \$basearch
  19. #baseurl=http://download.fedoraproject.org/pub/epel/7/\$basearch
  20. mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=\$basearch
  21. failovermethod=priority
  22. enabled=1
  23. gpgcheck=0
  24. EOF
  25. elif [ "${CentOS_ver}" == '6' ]; then
  26. [ ! -e /etc/yum.repos.d/epel.repo ] && cat > /etc/yum.repos.d/epel.repo << EOF
  27. [epel]
  28. name=Extra Packages for Enterprise Linux 6 - \$basearch
  29. #baseurl=http://download.fedoraproject.org/pub/epel/6/\$basearch
  30. mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=\$basearch
  31. failovermethod=priority
  32. enabled=1
  33. gpgcheck=0
  34. EOF
  35. fi
  36. if [ "${PM}" == 'yum' ]; then
  37. pkgList="gcc dialog augeas-libs openssl openssl-devel libffi-devel redhat-rpm-config ca-certificates"
  38. for Package in ${pkgList}; do
  39. yum -y install ${Package}
  40. done
  41. elif [ "${PM}" == 'apt-get' ]; then
  42. pkgList="gcc dialog libaugeas0 augeas-lenses libssl-dev libffi-dev ca-certificates"
  43. for Package in ${pkgList}; do
  44. apt-get -y install $Package
  45. done
  46. fi
  47. # Install Python3
  48. if [ ! -e "${python_install_dir}/bin/python" -a ! -e "${python_install_dir}/bin/python3" ] ;then
  49. src_url=http://mirrors.linuxeye.com/oneinstack/src/Python-${python_ver}.tgz && Download_src
  50. tar xzf Python-${python_ver}.tgz
  51. pushd Python-${python_ver} > /dev/null
  52. ./configure --prefix=${python_install_dir}
  53. make && make install
  54. [ ! -e "${python_install_dir}/bin/python" -a -e "${python_install_dir}/bin/python3" ] && ln -s ${python_install_dir}/bin/python{3,}
  55. [ ! -e "${python_install_dir}/bin/pip" -a -e "${python_install_dir}/bin/pip3" ] && ln -s ${python_install_dir}/bin/pip{3,}
  56. popd > /dev/null
  57. fi
  58. if [ ! -e "/root/.pip/pip.conf" ] ;then
  59. # get the IP information
  60. PUBLIC_IPADDR=$(../include/get_public_ipaddr.py)
  61. IPADDR_COUNTRY=$(../include/get_ipaddr_state.py ${PUBLIC_IPADDR})
  62. if [ "${IPADDR_COUNTRY}"x == "CN"x ]; then
  63. [ ! -d "/root/.pip" ] && mkdir /root/.pip
  64. echo -e "[global]\nindex-url = https://pypi.tuna.tsinghua.edu.cn/simple" > /root/.pip/pip.conf
  65. fi
  66. fi
  67. if [ -e "${python_install_dir}/bin/python3" ]; then
  68. echo "${CSUCCESS}Python ${python_ver} installed successfully! ${CEND}"
  69. rm -rf Python-${python_ver}
  70. fi
  71. popd > /dev/null
  72. fi
  73. }
  74. Uninstall_Python() {
  75. if [ -e "${python_install_dir}/bin/python" ]; then
  76. echo; echo "${CMSG}Python uninstall completed${CEND}"
  77. rm -rf ${python_install_dir}
  78. else
  79. echo; echo "${CWARNING}Python does not exist! ${CEND}"
  80. fi
  81. }