RedPlug's Tory

리눅스 버젼 체크용 스크립트

Ubuntu, CentOS 및 특정 버젼에 대한 체크 목적으로 사용

Major 및 Minor까지 체크 가능

OSVersionCheck()
{
    OSDistribution=$(cat /etc/*release*)
    if [[ "$OSDistribution" == *Ubuntu* ]];then
        ubuntuVer=$(lsb_release -| awk '{print $2}')
        if [ -"$ubuntuVer" ];then
            echo '### cannot see ubuntu version, manual check ver, and script exit'
            exit
        fi
 
        case $ubuntuVer in
            # ubuntu 12.04 ~ 16.04
            12.04* | 14.04* | 16.04*)
                echo "Ubuntu 12.04, 14.04, 16.04"
            ;;
            
            # ubuntu 18.04 ~ 20.04
            18.04* | 20.04*)
                echo "Ubuntu 18.04, 20.04"
            ;;
            *)
                echo "Ubuntu but Untested OS"
        esac
 
    elif [[ "$OSDistribution" == *CentOS* ]];then
        RHELVer=`cat /etc/redhat-release |awk '{print $3}'`
        if [ "$RHELVer" = "release" ];then
            RHELVer=`cat /etc/redhat-release |awk '{print $4}'`
        fi        
 
        case $RHELVer in
            # CentOS 6.0 ~ 6.3
            6.0 | 6.1 | 6.2 | 6.3)
                echo "CentOS 6.0 ~ 6.3"
            # CentOS 6.4 ~ 6.10
            ;;
            6.4 | 6.5 | 6.6 | 6.7 | 6.8 | 6.9 | 6.10)
                echo "CentOS 6.4 ~ 6.10"
            ;;
            # CentOS 7.X
            7.*)
                echo "CentOS 7.XX"
            ;;
            *)
                echo "CentOS but Untested OS"
        esac
    else
        echo "Untested OS, not centOS Ubuntu"
    fi
}
OSVersionCheck