check_os.sh 4.8 KB

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