1. os-releas

1.1. Debian9.9

~# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

2. CentOS7.4

 cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

3. Ubuntu16.04

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.1 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.1 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
UBUNTU_CODENAME=xenial

4. OS判断

OS=`uname -s`
if [ ${OS} == "Darwin" ];then
    sudo brew install git
elif [ ${OS} == "Linux" ];then
    source /etc/os-release
    case $ID in
        debian|ubuntu|devuan)
            sudo apt-get install git
            ;;
        centos|fedora|rhel)
            yumdnf="yum"
            if test "$(echo "$VERSION_ID >= 22" | bc)" -ne 0;
            then
                yumdnf="dnf"
            fi
            sudo $yumdnf install -y git
            ;;
        *)
            exit 1
            ;;
    esac
else
    echo "Other OS: ${OS}"
fi
# 判断操作系统类型
source /etc/os-release​
case $ID in
    debian)
        if [ "$VERSION_ID" = "9" ];
            OSTYPE="debian9"
        else
            echo "not debian9, unsupport debian version"
            exit 2
        fi 
        ;;
    ubuntu)
        if [ "$VERSION_ID" = "18.04" ];
            OSTYPE="ubuntu1804"
        else
            echo "not ubuntu18.04, unsupport ubuntu version"
            exit 3
        fi 
        ;;
    centos|rhel)
        if [ "$VERSION_ID" = "7" ];
            OSTYPE="centos7"
        else
            echo "not centos7, unsupport centos version"
            exit 4
        fi 
        ;;
    *)
        echo "unsupport os: $ID-$VERSION_ID"
        exit 5
        ;;
esac
Copyright © 温玉 2021 | 浙ICP备2020032454号 all right reserved,powered by Gitbook该文件修订时间: 2023-06-19 08:59:50

results matching ""

    No results matching ""