check_os.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. if [ -e "/usr/bin/yum" ]; then
  11. PM=yum
  12. command -v lsb_release >/dev/null 2>&1 || { [ -e "/etc/euleros-release" ] && yum -y install euleros-lsb || yum -y install redhat-lsb-core; clear; }
  13. fi
  14. if [ -e "/usr/bin/apt-get" ]; then
  15. PM=apt-get
  16. command -v lsb_release >/dev/null 2>&1 || { apt-get -y update; apt-get -y install lsb-release; clear; }
  17. fi
  18. command -v lsb_release >/dev/null 2>&1 || { echo "${CFAILURE}${PM} source failed! ${CEND}"; kill -9 $$; }
  19. # Get OS Version
  20. if [ -e /etc/redhat-release ]; then
  21. OS=CentOS
  22. CentOS_ver=$(lsb_release -sr | awk -F. '{print $1}')
  23. [ -n "$(lsb_release -is | grep -Ei 'Alibaba|Aliyun')" ] && { CentOS_ver=7; Aliyun_ver=$(lsb_release -rs); }
  24. [[ "$(lsb_release -is)" =~ ^EulerOS$ ]] && { CentOS_ver=7; EulerOS_ver=$(lsb_release -rs); }
  25. [ "$(lsb_release -is)" == 'Fedora' ] && [ ${CentOS_ver} -ge 19 >/dev/null 2>&1 ] && { CentOS_ver=7; Fedora_ver=$(lsb_release -rs); }
  26. elif [ -n "$(grep 'Amazon Linux' /etc/issue)" -o -n "$(grep 'Amazon Linux' /etc/os-release)" ]; then
  27. OS=CentOS
  28. CentOS_ver=7
  29. elif [ -n "$(grep 'bian' /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == "Debian" ]; then
  30. OS=Debian
  31. Debian_ver=$(lsb_release -sr | awk -F. '{print $1}')
  32. elif [ -n "$(grep 'Deepin' /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == "Deepin" ]; then
  33. OS=Debian
  34. Debian_ver=8
  35. elif [ -n "$(grep -w 'Kali' /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == "Kali" ]; then
  36. OS=Debian
  37. if [ -n "$(grep 'VERSION="2016.*"' /etc/os-release)" ]; then
  38. Debian_ver=8
  39. elif [ -n "$(grep 'VERSION="2017.*"' /etc/os-release)" ]; then
  40. Debian_ver=9
  41. elif [ -n "$(grep 'VERSION="2018.*"' /etc/os-release)" ]; then
  42. Debian_ver=9
  43. fi
  44. elif [ -n "$(grep 'Ubuntu' /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == "Ubuntu" -o -n "$(grep 'Linux Mint' /etc/issue)" ]; then
  45. OS=Ubuntu
  46. Ubuntu_ver=$(lsb_release -sr | awk -F. '{print $1}')
  47. [ -n "$(grep 'Linux Mint 18' /etc/issue)" ] && Ubuntu_ver=16
  48. elif [ -n "$(grep 'elementary' /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == 'elementary' ]; then
  49. OS=Ubuntu
  50. Ubuntu_ver=16
  51. fi
  52. # Check OS Version
  53. if [ ${CentOS_ver} -lt 6 >/dev/null 2>&1 ] || [ ${Debian_ver} -lt 8 >/dev/null 2>&1 ] || [ ${Ubuntu_ver} -lt 14 >/dev/null 2>&1 ]; then
  54. echo "${CFAILURE}Does not support this OS, Please install CentOS 6+,Debian 8+,Ubuntu 14+ ${CEND}"
  55. kill -9 $$
  56. fi
  57. command -v gcc > /dev/null 2>&1 || $PM -y install gcc
  58. gcc_ver=$(gcc -dumpversion | awk -F. '{print $1}')
  59. [ ${gcc_ver} -lt 5 >/dev/null 2>&1 ] && redis_ver=${redis_oldver}
  60. if uname -m | grep -Eqi "arm|aarch64"; then
  61. armplatform="y"
  62. if uname -m | grep -Eqi "armv7"; then
  63. TARGET_ARCH="armv7"
  64. elif uname -m | grep -Eqi "armv8"; then
  65. TARGET_ARCH="arm64"
  66. elif uname -m | grep -Eqi "aarch64"; then
  67. TARGET_ARCH="aarch64"
  68. else
  69. TARGET_ARCH="unknown"
  70. fi
  71. fi
  72. if [ "$(uname -r | awk -F- '{print $3}' 2>/dev/null)" == "Microsoft" ]; then
  73. Wsl=true
  74. fi
  75. if [ "$(getconf WORD_BIT)" == "32" ] && [ "$(getconf LONG_BIT)" == "64" ]; then
  76. OS_BIT=64
  77. SYS_BIT_j=x64 #jdk
  78. SYS_BIT_a=x86_64 #mariadb
  79. SYS_BIT_b=x86_64 #mariadb
  80. SYS_BIT_c=x86_64 #ZendGuardLoader
  81. SYS_BIT_d=x86-64 #ioncube
  82. [ "${TARGET_ARCH}" == 'aarch64' ] && { SYS_BIT_c=aarch64; SYS_BIT_d=aarch64; }
  83. else
  84. OS_BIT=32
  85. SYS_BIT_j=i586
  86. SYS_BIT_a=x86
  87. SYS_BIT_b=i686
  88. SYS_BIT_c=i386
  89. SYS_BIT_d=x86
  90. [ "${TARGET_ARCH}" == 'armv7' ] && { SYS_BIT_c=armhf; SYS_BIT_d=armv7l; }
  91. fi
  92. THREAD=$(grep 'processor' /proc/cpuinfo | sort -u | wc -l)
  93. # Percona binary: https://www.percona.com/doc/percona-server/5.7/installation.html#installing-percona-server-from-a-binary-tarball
  94. if [ ${Debian_ver} -lt 9 >/dev/null 2>&1 ] || [ ${Ubuntu_ver} -lt 14 >/dev/null 2>&1 ]; then
  95. sslLibVer=ssl100
  96. elif [[ "${CentOS_ver}" =~ ^[6-7]$ ]] && [ "$(lsb_release -is)" != 'Fedora' ]; then
  97. sslLibVer=ssl101
  98. elif [ ${Debian_ver} -ge 9 >/dev/null 2>&1 ] || [ ${Ubuntu_ver} -ge 14 >/dev/null 2>&1 ]; then
  99. sslLibVer=ssl102
  100. elif [ ${Fedora_ver} -ge 27 >/dev/null 2>&1 ]; then
  101. sslLibVer=ssl102
  102. elif [ "${CentOS_ver}" == '8' ]; then
  103. sslLibVer=ssl1:111
  104. else
  105. sslLibVer=unknown
  106. fi