python.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  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 [ "${PM}" == 'yum' ]; then
  16. [ -z "`grep -w epel /etc/yum.repos.d/*.repo`" ] && yum -y install epel-release
  17. pkgList="gcc dialog augeas-libs openssl openssl-devel libffi-devel redhat-rpm-config ca-certificates"
  18. for Package in ${pkgList}; do
  19. yum -y install ${Package}
  20. done
  21. elif [ "${PM}" == 'apt-get' ]; then
  22. pkgList="gcc dialog libaugeas0 augeas-lenses libssl-dev libffi-dev ca-certificates"
  23. for Package in ${pkgList}; do
  24. apt-get -y install $Package
  25. done
  26. fi
  27. # Install Python3
  28. if [ ! -e "${python_install_dir}/bin/python" -a ! -e "${python_install_dir}/bin/python3" ] ;then
  29. src_url=http://mirrors.linuxeye.com/oneinstack/src/Python-${python_ver}.tgz && Download_src
  30. tar xzf Python-${python_ver}.tgz
  31. pushd Python-${python_ver} > /dev/null
  32. ./configure --prefix=${python_install_dir}
  33. make && make install
  34. [ ! -e "${python_install_dir}/bin/python" -a -e "${python_install_dir}/bin/python3" ] && ln -s ${python_install_dir}/bin/python{3,}
  35. [ ! -e "${python_install_dir}/bin/pip" -a -e "${python_install_dir}/bin/pip3" ] && ln -s ${python_install_dir}/bin/pip{3,}
  36. popd > /dev/null
  37. fi
  38. if [ ! -e "${python_install_dir}/bin/pip" ]; then
  39. src_url=http://mirrors.linuxeye.com/oneinstack/src/setuptools-${setuptools_ver}.zip && Download_src
  40. src_url=http://mirrors.linuxeye.com/oneinstack/src/pip-${pip_ver}.tar.gz && Download_src
  41. unzip -q setuptools-${setuptools_ver}.zip
  42. tar xzf pip-${pip_ver}.tar.gz
  43. pushd setuptools-${setuptools_ver} > /dev/null
  44. ${python_install_dir}/bin/python setup.py install
  45. popd > /dev/null
  46. pushd pip-${pip_ver} > /dev/null
  47. ${python_install_dir}/bin/python setup.py install
  48. popd > /dev/null
  49. fi
  50. if [ ! -e "/root/.pip/pip.conf" ] ;then
  51. # get the IP information
  52. PUBLIC_IPADDR=$(../include/get_public_ipaddr.py)
  53. IPADDR_COUNTRY=$(../include/get_ipaddr_state.py ${PUBLIC_IPADDR})
  54. if [ "${IPADDR_COUNTRY}"x == "CN"x ]; then
  55. [ ! -d "/root/.pip" ] && mkdir /root/.pip
  56. echo -e "[global]\nindex-url = https://pypi.tuna.tsinghua.edu.cn/simple" > /root/.pip/pip.conf
  57. fi
  58. fi
  59. if [ -e "${python_install_dir}/bin/python3" ]; then
  60. echo "${CSUCCESS}Python ${python_ver} installed successfully! ${CEND}"
  61. rm -rf Python-${python_ver}
  62. fi
  63. popd > /dev/null
  64. fi
  65. }
  66. Uninstall_Python() {
  67. if [ -e "${python_install_dir}/bin/python" ]; then
  68. echo "${CMSG}Python uninstall completed${CEND}"
  69. rm -rf ${python_install_dir}
  70. fi
  71. }