展開名を効率的に決定するスクリプトを作成するにはどうすればよいですか?

展開名を効率的に決定するスクリプトを作成するにはどうすればよいですか?

私は見たこの投稿どのディストリビューションがインストールされているかを調べる方法はさまざまであるため、すべて試してみるためにスクリプトを書いてみました。可能なコマンドは次のとおりです。

$ cat /etc/lsb-release 
$ cat /etc/issue 
$ dmesg | head -1
$ cat /proc/version 
$ cat /etc/slackware-version 
$ cat/etc/debian-verion 

私は次のような文章を書いてみました。 (私は主にスペイン語を使うのでスペイン語になっています。)

function Nombre_SO()
{

    DistroName="Linux"
    if [ $DistroName = Linux ] ;
    then

# Debian
    debian=`cat /etc/debian_version | cut -d " " -f01 | tr '[:upper:]' '[:lower:]'`
    if [ "$debian" = "debian" || "squeeze/sid" || "lenny" ]; 
        then
        DistroName="debian"
        else
        echo "Esto no es debian"
    fi

# Slackware
    slackware=`cat /etc/slackware-version | cut -d " " -f01` | tr '[:upper:]' '[:lower:]'`
    if [ "$slackware" = "slackware" || "slackware-x86_64" ];
    then
        DistroName="slackware" 
    else
    echo "Esto no es Slackware"
}

誰かがあなたのディストリビューションの名前を得るために他のすべての方法を一緒に集めるのを助けることができますか?

ベストアンサー1

各ディストリビューションは、(lsbの努力にもかかわらず)名前とバージョンを宣言するために/ etc /の他のファイルを使用または使用することができます(または存在しない場合があります)。

スクリプトの各条件に条件を追加する必要があります。また、一部のディストリビューションは他の主要なディストリビューションから分岐しているため、バージョンファイルが調整される場合と調整されない場合があります。

車輪を再発明したくない場合は、他の人の仕事を活用して目的を達成できます。たとえば、Pythonのモジュールではプラットフォーム分布を推測する方法があります。

Help on function linux_distribution in module platform:

linux_distribution(distname='', version='', id='', supported_dists=('SuSE', 'debian', 'fedora', 'redhat', 'centos', 'mandrake', 'mandriva', 'rocks', 'slackware', 'yellowdog', 'gentoo', 'UnitedLinux', 'turbolinux'), full_distribution_name=1)
    Tries to determine the name of the Linux OS distribution name.

    The function first looks for a distribution release file in
    /etc and then reverts to _dist_try_harder() in case no
    suitable files are found.

    supported_dists may be given to define the set of Linux
    distributions to look for. It defaults to a list of currently
    supported Linux distributions identified by their release file
    name.

    If full_distribution_name is true (default), the full
    distribution read from the OS is returned. Otherwise the short
    name taken from supported_dists is used.

    Returns a tuple (distname,version,id) which default to the
    args given as parameters.

たとえば、

In [1]: import platform

In [2]: platform.linux_distribution()
Out[2]: ('Ubuntu', '11.10', 'oneiric')

おすすめ記事