1
0

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