diff --git a/x-ui.sh b/x-ui.sh index 03432c31..0ae5e2dd 100644 --- a/x-ui.sh +++ b/x-ui.sh @@ -20,46 +20,41 @@ function LOGI() { # check root [[ $EUID -ne 0 ]] && LOGE "ERROR: You must be root to run this script! \n" && exit 1 -# check os -if [[ -f /etc/redhat-release ]]; then - release="centos" -elif cat /etc/issue | grep -Eqi "debian"; then - release="debian" -elif cat /etc/issue | grep -Eqi "ubuntu"; then - release="ubuntu" -elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then - release="centos" -elif cat /proc/version | grep -Eqi "debian"; then - release="debian" -elif cat /proc/version | grep -Eqi "ubuntu"; then - release="ubuntu" -elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then - release="centos" +# Check OS and set release variable +if [[ -f /etc/os-release ]]; then + source /etc/os-release + release=$ID +elif [[ -f /usr/lib/os-release ]]; then + source /usr/lib/os-release + release=$ID else - LOGE "check system OS failed,please contact with author! \n" && exit 1 + echo "Failed to check the system OS, please contact the author!" >&2 + exit 1 fi +echo "The OS release is: $release" + + os_version="" +os_version=$(grep -i version_id /etc/os-release | cut -d \" -f2 | cut -d . -f1) -# os version -if [[ -f /etc/os-release ]]; then - os_version=$(awk -F'[= ."]' '/VERSION_ID/{print $3}' /etc/os-release) -fi -if [[ -z "$os_version" && -f /etc/lsb-release ]]; then - os_version=$(awk -F'[= ."]+' '/DISTRIB_RELEASE/{print $2}' /etc/lsb-release) -fi - -if [[ x"${release}" == x"centos" ]]; then - if [[ ${os_version} -le 6 ]]; then - LOGE "please use CentOS 7 or higher version! \n" && exit 1 - fi -elif [[ x"${release}" == x"ubuntu" ]]; then - if [[ ${os_version} -lt 16 ]]; then - LOGE "please use Ubuntu 16 or higher version!\n" && exit 1 - fi -elif [[ x"${release}" == x"debian" ]]; then +if [[ "${release}" == "centos" ]]; then if [[ ${os_version} -lt 8 ]]; then - LOGE "please use Debian 8 or higher version!\n" && exit 1 + echo -e "${red} Please use CentOS 8 or higher ${plain}\n" && exit 1 + fi +elif [[ "${release}" == "ubuntu" ]]; then + if [[ ${os_version} -lt 20 ]]; then + echo -e "${red}please use Ubuntu 20 or higher version!${plain}\n" && exit 1 + fi + +elif [[ "${release}" == "fedora" ]]; then + if [[ ${os_version} -lt 36 ]]; then + echo -e "${red}please use Fedora 36 or higher version!${plain}\n" && exit 1 + fi + +elif [[ "${release}" == "debian" ]]; then + if [[ ${os_version} -lt 10 ]]; then + echo -e "${red} Please use Debian 10 or higher ${plain}\n" && exit 1 fi fi