2018-03-13

Get Linux Distribution Name

使用 /etc/os-release 來取得 Linux Distribution 的相關資訊。應該可以適用於: CentOS, RedHat, Fedora, openSUSE, SUSE, Debian/Ubuntu, ArchLinux

proc getDistributionName {} {
    set OSName ""

    if {[file exists "/etc/os-release"]==1} {
        set release [open "/etc/os-release" r]
        while {1} {
            if {[chan gets $release line] > 0} {
                set info [split $line "="]
                if {[string compare [lindex $info 0] "NAME"]==0} {
                    set OSName [lindex $info 1]
                    break;
                }
            } else {
                if {[chan eof $release]} {
                    break;
                } else {
                    puts "Something is wrong."
                    break;
                }
            }
        }

        chan close $release
    } else {
        return -code error "/etc/os-release not exist!!!" 
    }
    
    return $OSName
}


參考資料:
os-release — Operating system identification

沒有留言: