1
0

python.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 "${python_install_dir}/bin/pip" ]; then
  59. src_url=http://mirrors.linuxeye.com/oneinstack/src/setuptools-${setuptools_ver}.zip && Download_src
  60. src_url=http://mirrors.linuxeye.com/oneinstack/src/pip-${pip_ver}.tar.gz && Download_src
  61. unzip -q setuptools-${setuptools_ver}.zip
  62. tar xzf pip-${pip_ver}.tar.gz
  63. pushd setuptools-${setuptools_ver} > /dev/null
  64. ${python_install_dir}/bin/python setup.py install
  65. popd > /dev/null
  66. pushd pip-${pip_ver} > /dev/null
  67. ${python_install_dir}/bin/python setup.py install
  68. popd > /dev/null
  69. fi
  70. if [ ! -e "/root/.pip/pip.conf" ] ;then
  71. # get the IP information
  72. PUBLIC_IPADDR=$(../include/get_public_ipaddr.py)
  73. IPADDR_COUNTRY=$(../include/get_ipaddr_state.py ${PUBLIC_IPADDR})
  74. if [ "${IPADDR_COUNTRY}"x == "CN"x ]; then
  75. [ ! -d "/root/.pip" ] && mkdir /root/.pip
  76. echo -e "[global]\nindex-url = https://pypi.tuna.tsinghua.edu.cn/simple" > /root/.pip/pip.conf
  77. fi
  78. fi
  79. if [ -e "${python_install_dir}/bin/python3" ]; then
  80. echo "${CSUCCESS}Python ${python_ver} installed successfully! ${CEND}"
  81. rm -rf Python-${python_ver}
  82. fi
  83. popd > /dev/null
  84. fi
  85. }
  86. Uninstall_Python() {
  87. if [ -e "${python_install_dir}/bin/python" ]; then
  88. echo; echo "${CMSG}Python uninstall completed${CEND}"
  89. rm -rf ${python_install_dir}
  90. else
  91. echo; echo "${CWARNING}Python does not exist! ${CEND}"
  92. fi
  93. }