views:

137

answers:

7

I would like to show the user some help on specific operations in my program of the form:

Please type "apt-get install foobar" to install the foobar feature.

Is there anything to do this or do i have to leave it to the user and offer a dozend choices from Red Hat, Suse, Debian/Ubuntu, Mandriva, Slackware, Gentoo ....

A: 

You can do it for most well know distros(Redhat, Fedaora, Gentoo, Suse, Debian, Ubuntu), those have special files to identify the distribution and version. i.e. /etc/debian_version.

But it would be a tedious task for you to list out all the package and things but if you really want to be user friendly

RageZ
A: 

try with cat:

cat /proc/version

but with uname is maybe better:

uname -a
cupakob
Can i really expect that /proc/version have the name of the distribution in it? At least for the major ones?uname is not giving me any hint that i'm on SUSE. I get:Linux linux-kiste 2.6.27.7-9-default #1 SMP 2008-12-04 18:10:04 +0100 x86_64 x86_64 x86_64 GNU/Linux
Lothar
On ubuntu works: Linux version 2.6.31-14-generic (buildd@rothera) (gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu8) ) #48-Ubuntu SMP Fri Oct 16 14:04:26 UTC 2009. And what is about uname -a?
cupakob
+2  A: 

You could give

cat /etc/issue

a try too

asrijaal
+4  A: 

lsb_release -a might help on debian and apparented.

RC
This seems to be the answer - i wait a few days until i flag it.
Lothar
On Debian, it does not exist unless the `lsb-release` package is installed. That package is not marked `essential` and is not guaranteed to be present.
ephemient
The old Linux problem again - i hate it, they deserve there 1% desktop market share.
Lothar
@ephemient, that's good to know, thanks.
RC
+3  A: 

cat /etc/lsb-release

root@pierr-desktop:~# cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.10
DISTRIB_CODENAME=intrepid
DISTRIB_DESCRIPTION="Ubuntu 8.10"
pierr
that is the right way :)
cupakob
No it isn't. Suse gives me:"Linux linux-kiste 2.6.27.7-9-default #1 SMP 2008-12-04 18:10:04 +0100 x86_64 x86_64 x86_64 GNU/Linux"Again no indication here about the Distribution and i don't think that the /etc/lsb-release is even in the LSB spec. At least i haven't seen it in 3.2
Lothar
okay :) its not the right one for you...
cupakob
Instead of reading that file directly, use `lsb_release -a` (or specifically request the attributes you want, e.g. `lsb_release -i -r -c -d`).
ephemient
+2  A: 

No, there is no generic way to find out which Linux distribution you are running on.

There is the lsb_release command, which is specified in the Linux Standard Base specification. But obviously this command is only present on LSB-compliant distributions, and many smaller or specialized distributions are not LSB-compliant. (For example, the distribution I am running on my FritzBox router is not.)

And if you are assuming an LSB-compliant distribution anyway, then why not simply package your application as an LSB package? That way it works the same on all LSB-compliant distributions.

Jörg W Mittag
+1  A: 

Given that Linux can be built starting with one system and morphed into another, you may not be able to tell precisely which it currently is. Some distribution provide the lsb tools if they are LSB compliant, so that might help.

Some distributions provide a file /etc/dist-release. For example, I have a file /etc/arch-release that is empty.

You might also execute:

uname -a

That might indicate the the distribution the kernel was built for, but that might be a long shot. My Arch linux kernel has no mention of Arch, but I believe my Gentoo install indicates "Gentoo Linux".

Some tools can be indicative of the distribution, such as apt-get, rpm, emerge, but you can usually install those tools on other distributions as well.

s1n