check_os.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/lj2007331/oneinstack
  10. if [ -e "/usr/bin/yum" ]; then
  11. PM=yum
  12. command -v lsb_release >/dev/null 2>&1 || { yum -y install redhat-lsb-core; clear; }
  13. elif [ -e "/usr/bin/apt-get" ]; then
  14. PM=apt
  15. command -v lsb_release >/dev/null 2>&1 || { apt-get -y update; apt-get -y install lsb-release; clear; }
  16. fi
  17. command -v lsb_release >/dev/null 2>&1 || { echo "${CFAILURE}${PM} source failed! ${CEND}"; kill -9 $$; }
  18. if [ -e /etc/redhat-release ]; then
  19. OS=CentOS
  20. CentOS_ver=$(lsb_release -sr | awk -F. '{print $1}')
  21. [ "${CentOS_ver}" == '17' ] && CentOS_ver=7
  22. [ "$(lsb_release -is)" == 'Fedora' ] && [ ${CentOS_ver} -ge 19 >/dev/null 2>&1 ] && { CentOS_ver=7; Fedora_ver=$(lsb_release -rs); }
  23. elif [ -n "$(grep 'Amazon Linux' /etc/issue)" -o -n "$(grep 'Amazon Linux' /etc/os-release)" ]; then
  24. OS=CentOS
  25. CentOS_ver=7
  26. elif [ -n "$(grep 'bian' /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == "Debian" ]; then
  27. OS=Debian
  28. Debian_ver=$(lsb_release -sr | awk -F. '{print $1}')
  29. elif [ -n "$(grep 'Deepin' /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == "Deepin" ]; then
  30. OS=Debian
  31. Debian_ver=8
  32. elif [ -n "$(grep -w 'Kali' /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == "Kali" ]; then
  33. OS=Debian
  34. if [ -n "$(grep 'VERSION="2016.*"' /etc/os-release)" ]; then
  35. Debian_ver=8
  36. elif [ -n "$(grep 'VERSION="2017.*"' /etc/os-release)" ]; then
  37. Debian_ver=9
  38. elif [ -n "$(grep 'VERSION="2018.*"' /etc/os-release)" ]; then
  39. Debian_ver=9
  40. fi
  41. elif [ -n "$(grep 'Ubuntu' /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == "Ubuntu" -o -n "$(grep 'Linux Mint' /etc/issue)" ]; then
  42. OS=Ubuntu
  43. Ubuntu_ver=$(lsb_release -sr | awk -F. '{print $1}')
  44. [ -n "$(grep 'Linux Mint 18' /etc/issue)" ] && Ubuntu_ver=16
  45. elif [ -n "$(grep 'elementary' /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == 'elementary' ]; then
  46. OS=Ubuntu
  47. Ubuntu_ver=16
  48. else
  49. echo "${CFAILURE}Does not support this OS, Please contact the author! ${CEND}"
  50. kill -9 $$
  51. fi
  52. if [ "$(uname -r | awk -F- '{print $3}' 2>/dev/null)" == "Microsoft" ]; then
  53. Wsl=true
  54. fi
  55. if [ "$(getconf WORD_BIT)" == "32" ] && [ "$(getconf LONG_BIT)" == "64" ]; then
  56. OS_BIT=64
  57. SYS_BIT_j=x64 #jdk
  58. SYS_BIT_a=x86_64 #mariadb
  59. SYS_BIT_b=x86_64 #mariadb
  60. SYS_BIT_c=x86_64 #ZendGuardLoader
  61. SYS_BIT_d=x86-64 #ioncube
  62. else
  63. OS_BIT=32
  64. SYS_BIT_j=i586
  65. SYS_BIT_a=x86
  66. SYS_BIT_b=i686
  67. SYS_BIT_c=i386
  68. SYS_BIT_d=x86
  69. fi
  70. LIBC_YN=$(awk -v A=$(getconf -a | grep GNU_LIBC_VERSION | awk '{print $NF}') -v B=2.14 'BEGIN{print(A>=B)?"0":"1"}')
  71. [ ${LIBC_YN} == '0' ] && GLIBC_FLAG=linux-glibc_214 || GLIBC_FLAG=linux
  72. if uname -m | grep -Eqi "arm"; then
  73. armplatform="y"
  74. if uname -m | grep -Eqi "armv7"; then
  75. TARGET_ARCH="armv7"
  76. elif uname -m | grep -Eqi "armv8"; then
  77. TARGET_ARCH="arm64"
  78. else
  79. TARGET_ARCH="unknown"
  80. fi
  81. fi
  82. THREAD=$(grep 'processor' /proc/cpuinfo | sort -u | wc -l)
  83. # Percona binary: https://www.percona.com/doc/percona-server/5.7/installation.html#installing-percona-server-from-a-binary-tarball
  84. if [ ${Debian_ver} -lt 9 >/dev/null 2>&1 ] || [ ${Ubuntu_ver} -lt 14 >/dev/null 2>&1 ]; then
  85. sslLibVer=ssl100
  86. elif [[ "${CentOS_ver}" =~ ^[6-7]$ ]] && [ "$(lsb_release -is)" != 'Fedora' ]; then
  87. sslLibVer=ssl101
  88. elif [ ${Debian_ver} -ge 9 >/dev/null 2>&1 ] || [ ${Ubuntu_ver} -ge 14 >/dev/null 2>&1 ]; then
  89. sslLibVer=ssl102
  90. elif [ ${Fedora_ver} -ge 27 >/dev/null 2>&1 ]; then
  91. sslLibVer=ssl102
  92. else
  93. sslLibVer=unknown
  94. fi