check_os.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. if [ -e "/etc/os-release" ]; then
  11. . /etc/os-release
  12. else
  13. echo "${CFAILURE}/etc/os-release does not exist! ${CEND}"
  14. kill -9 $$; exit 1;
  15. fi
  16. # Get OS Version
  17. Platform=${ID,,}
  18. VERSION_ID=${VERSION_ID%%.*}
  19. ARCH=$(arch)
  20. if [[ "${Platform}" =~ ^centos$|^rhel$|^almalinux$|^rocky$|^fedora$|^amzn$|^ol$|^alinux$|^anolis$|^tencentos$|^euleros$|^openeuler$|^kylin$ ]]; then
  21. PM=yum
  22. Family=rhel
  23. RHEL_ver=${VERSION_ID}
  24. if [[ "${Platform}" =~ ^centos$ ]]; then
  25. if [ "${VERSION_ID}" == '6' ]; then
  26. sed -i "s@centos/\$releasever@centos-vault/6.10@g" /etc/yum.repos.d/CentOS-Base.repo
  27. sed -i 's@centos/RPM-GPG@centos-vault/RPM-GPG@g' /etc/yum.repos.d/CentOS-Base.repo
  28. [ -e /etc/yum.repos.d/epel.repo ] && rm -f /etc/yum.repos.d/epel.repo
  29. fi
  30. elif [[ "${Platform}" =~ ^fedora$ ]]; then
  31. Fedora_ver=${VERSION_ID}
  32. [ ${VERSION_ID} -ge 19 ] && [ ${VERSION_ID} -lt 28 ] && RHEL_ver=7
  33. [ ${VERSION_ID} -ge 28 ] && [ ${VERSION_ID} -lt 34 ] && RHEL_ver=8
  34. [ ${VERSION_ID} -ge 34 ] && RHEL_ver=9
  35. elif [[ "${Platform}" =~ ^amzn$|^alinux$|^tencentos$|^euleros$ ]]; then
  36. [[ "${VERSION_ID}" =~ ^2$ ]] && RHEL_ver=7
  37. [[ "${VERSION_ID}" =~ ^3$ ]] && RHEL_ver=8
  38. elif [[ "${Platform}" =~ ^openeuler$ ]]; then
  39. [[ "${RHEL_ver}" =~ ^20$ ]] && RHEL_ver=7
  40. [[ "${RHEL_ver}" =~ ^2[1,2]$ ]] && RHEL_ver=8
  41. elif [[ "${Platform}" =~ ^kylin$ ]]; then
  42. [[ "${RHEL_ver}" =~ ^V10$ ]] && RHEL_ver=7
  43. fi
  44. elif [[ "${Platform}" =~ ^debian$|^deepin$|^uos$|^kali$ ]]; then
  45. PM=apt-get
  46. Family=debian
  47. Debian_ver=${VERSION_ID}
  48. if [[ "${Platform}" =~ ^deepin$|^uos$ ]]; then
  49. [[ "${Debian_ver}" =~ ^20$ ]] && Debian_ver=10
  50. [[ "${Debian_ver}" =~ ^23$ ]] && Debian_ver=11
  51. elif [[ "${Platform}" =~ ^kali$ ]]; then
  52. [[ "${Debian_ver}" =~ ^202 ]] && Debian_ver=10
  53. fi
  54. elif [[ "${Platform}" =~ ^ubuntu$|^linuxmint$|^elementary$ ]]; then
  55. PM=apt-get
  56. Family=ubuntu
  57. Ubuntu_ver=${VERSION_ID}
  58. if [[ "${Platform}" =~ ^linuxmint$ ]]; then
  59. [[ "${VERSION_ID}" =~ ^18$ ]] && Ubuntu_ver=16
  60. [[ "${VERSION_ID}" =~ ^19$ ]] && Ubuntu_ver=18
  61. [[ "${VERSION_ID}" =~ ^20$ ]] && Ubuntu_ver=20
  62. [[ "${VERSION_ID}" =~ ^21$ ]] && Ubuntu_ver=22
  63. elif [[ "${Platform}" =~ ^elementary$ ]]; then
  64. [[ "${VERSION_ID}" =~ ^5$ ]] && Ubuntu_ver=18
  65. [[ "${VERSION_ID}" =~ ^6$ ]] && Ubuntu_ver=20
  66. [[ "${VERSION_ID}" =~ ^7$ ]] && Ubuntu_ver=22
  67. fi
  68. else
  69. echo "${CFAILURE}Does not support this OS ${CEND}"
  70. kill -9 $$; exit 1;
  71. fi
  72. # Check OS Version
  73. if [ ${RHEL_ver} -lt 7 >/dev/null 2>&1 ] || [ ${Debian_ver} -lt 9 >/dev/null 2>&1 ] || [ ${Ubuntu_ver} -lt 16 >/dev/null 2>&1 ]; then
  74. echo "${CFAILURE}Does not support this OS, Please install CentOS 7+,Debian 9+,Ubuntu 16+ ${CEND}"
  75. kill -9 $$; exit 1;
  76. fi
  77. command -v gcc > /dev/null 2>&1 || $PM -y install gcc
  78. gcc_ver=$(gcc -dumpversion | awk -F. '{print $1}')
  79. [ ${gcc_ver} -lt 5 >/dev/null 2>&1 ] && redis_ver=${redis_oldver}
  80. if uname -m | grep -Eqi "arm|aarch64"; then
  81. armplatform="y"
  82. if uname -m | grep -Eqi "armv7"; then
  83. TARGET_ARCH="armv7"
  84. elif uname -m | grep -Eqi "armv8"; then
  85. TARGET_ARCH="arm64"
  86. elif uname -m | grep -Eqi "aarch64"; then
  87. TARGET_ARCH="aarch64"
  88. else
  89. TARGET_ARCH="unknown"
  90. fi
  91. fi
  92. if [ "$(uname -r | awk -F- '{print $3}' 2>/dev/null)" == "Microsoft" ]; then
  93. Wsl=true
  94. fi
  95. if [ "$(getconf WORD_BIT)" == "32" ] && [ "$(getconf LONG_BIT)" == "64" ]; then
  96. if [ "${TARGET_ARCH}" == 'aarch64' ]; then
  97. SYS_ARCH=arm64
  98. SYS_ARCH_i=aarch64
  99. SYS_ARCH_n=arm64
  100. else
  101. SYS_ARCH=amd64 #openjdk
  102. SYS_ARCH_i=x86-64 #ioncube
  103. SYS_ARCH_n=x64 #nodejs
  104. fi
  105. else
  106. echo "${CWARNING}32-bit OS are not supported! ${CEND}"
  107. kill -9 $$; exit 1;
  108. fi
  109. THREAD=$(grep 'processor' /proc/cpuinfo | sort -u | wc -l)
  110. # Percona binary: https://docs.percona.com/percona-server/5.7/installation/binary-tarball.html
  111. if [ ${Debian_ver} -lt 9 >/dev/null 2>&1 ]; then
  112. sslLibVer=ssl100
  113. elif [ "${RHEL_ver}" == '7' ] && [ "${Platform}" != 'fedora' ]; then
  114. sslLibVer=ssl101
  115. elif [ ${Debian_ver} -ge 9 >/dev/null 2>&1 ] || [ ${Ubuntu_ver} -ge 16 >/dev/null 2>&1 ]; then
  116. sslLibVer=ssl102
  117. elif [ ${Fedora_ver} -ge 27 >/dev/null 2>&1 ]; then
  118. sslLibVer=ssl102
  119. elif [ "${RHEL_ver}" == '8' ]; then
  120. sslLibVer=ssl1:111
  121. else
  122. sslLibVer=unknown
  123. fi