Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-10

Detecting what is the linux distro

18 messages · 9 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

ik

Hello List,

I'm looking for a proper way to detect the type of Linux distro.

At first I thought about /etc/issue, but it seems that some are abusing this file.
Many distro's uses /etc/XXXX__release, where XXXX is their name, but it's not a proper way either to detect, because not everyone uses it.

Any additional ideas ?

Thanks,

Ido

Reply by email

Torsten Bonde Christiansen
to ik
ik wrote 10 lines
Hello List, I'm looking for a proper way to detect the type of Linux distro. At first I thought about /etc/issue, but it seems that some are abusing this file. Many distro's uses /etc/XXXX__release, where XXXX is their name, but it's not a proper way either to detect, because not everyone uses it. Any additional ideas ?

Most distros also include their name in the kernel, so using "uname -a" could also give a hint. But AFAIK there is no common place where all distros store the name.

Kind regards,
Torsten Bonde Christiansen.

Reply by email

Graeme Geldenhuys
to ik: I'm looking for a proper way to detect the type of Linux distro. At first I thought about…
ik wrote 7 lines
At first I thought about /etc/issue, but it seems that some are abusing this file. Many distro's uses /etc/XXXX__release, where XXXX is their name, but it's not a proper way either to detect, because not everyone uses it. Any additional ideas ?

If your distro complies with the LSB standards (most popular distros do), then you should have a /etc/lsb-release text file that you can parse.

------------------------------------
~ $ cd /etc
etc $ ls -l lsb-release
-rw-r--r-- 1 root root 104 2010-07-08 16:55 lsb-release

etc $ cat lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.04
DISTRIB_CODENAME=lucid
DISTRIB_DESCRIPTION="Ubuntu 10.04.1 LTS"

------------------------------------

Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net:8080/fpgui/

Reply by email

silvioprog
to ik: I'm looking for a proper way to detect the type of Linux distro. At first I thought about…

2010/10/11 ik

Show quoted text 16 lines
Hello List, I'm looking for a proper way to detect the type of Linux distro. At first I thought about /etc/issue, but it seems that some are abusing this file. Many distro's uses /etc/XXXX__release, where XXXX is their name, but it's not a proper way either to detect, because not everyone uses it. Any additional ideas ? Thanks, Ido
Please, see the function LSGetLinuxDistro (
code.google.com/p/lazsolutions/source/browse/trunk/Core/LSUtils.pas#55);
Silvio Clécio, *programmer* *ObjectPascal*

Reply by email

Marco van de Voort
to Graeme Geldenhuys: If your distro complies with the LSB standards (most popular distros do), then you should…

In our previous episode, Graeme Geldenhuys said:

Show quoted text 10 lines
> file. > Many distro's uses /etc/XXXX__release, where XXXX is their name, but it's > not a proper way either to detect, because not everyone uses it. > > Any additional ideas ? If your distro complies with the LSB standards (most popular distros do), then you should have a /etc/lsb-release text file that you can parse.

FC11, no such file, but there is a dir lsb-release.d with the contents

0 -rw-r--r--. 1 root root 0 2010-06-25 11:25 core-4.0-ia32 0 -rw-r--r--. 1 root root 0 2010-06-25 11:25 core-4.0-noarch 0 -rw-r--r--. 1 root root 0 2010-06-25 11:25 graphics-4.0-ia32 0 -rw-r--r--. 1 root root 0 2010-06-25 11:25 graphics-4.0-noarch 0 -rw-r--r--. 1 root root 0 2010-06-25 11:25 printing-4.0-ia32 0 -rw-r--r--. 1 root root 0 2010-06-25 11:25 printing-4.0-noarch

Reply by email

Michalis Kamburelis
to Marco van de Voort
Marco van de Voort wrote 6 lines
> If your distro complies with the LSB standards (most popular distros > do), then you should have a /etc/lsb-release text file that you can > parse. FC11, no such file, but there is a dir lsb-release.d with the contents

You're not really supposed to be looking at /etc/lsb* files directly. Rather you should run "lsb_release". Try "lsb_release --all". For the short name of the distribution, something like "lsb_release --id --short" is appropriate, see the manpage.

Michalis

Reply by email

Graeme Geldenhuys
to ik
ik wrote
It's sad to see that there is no specific way to get this information on all distro's but at least I can get it on the most used distros out there.

A general problem under Linux (and it's hundreds of distros). That is why I think it is so important to support freedesktop.org and LSB Foundation (Linux Standards Base). They are trying really hard to resolve these problems, *plus* make it easier for software developers to integrate there applications. Luckily the most popular distros (covering probably 90% of linux usage) do try and follow those standards.

Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net:8080/fpgui/

Reply by email

Graeme Geldenhuys
to Henry Vermaak
Henry Vermaak wrote
Just curious, why would you like to detect this?

I don't know about the original poster, but I for one use such information for our custom security components - generating trial unlock keys for our commercial software.

Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net:8080/fpgui/

Reply by email

ik
to Henry Vermaak: Just curious, why would you like to detect this? Henry
Henry Vermaak wrote 9 lines
On 11 October 2010 19:51, ik wrote: > Thanks all for the answers. > > It's sad to see that there is no specific way to get this information on all > distro's but at least I can get it on the most used distros out there. Just curious, why would you like to detect this?

You want to know how to install files for daemons, append information in other existed packages etc... But instead of creating 1000% packages types for each distro, you can for example know that Gentoo and ArchLinux uses /etc/rc.d/ for init deamons.
You know that Debian, CentOS, RedHat and few others uses /etc/init.d/ etc...

BTW I had a program that created in my ArchLinux /etc/init.d/ and placed it there, while i was the wrong location.

Show quoted text 6 lines
Henry _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Ido

LINESIP websites:
http://www.linesip.com
http://www.linesip.co.il

Reply by email

David W Noon
to ik

On Tue, 12 Oct 2010 09:54:35 +0200, ik wrote about Re: [fpc-pascal] Detecting what is the linux distro:

On Tue, Oct 12, 2010 at 09:30, Henry Vermaak wrote:

[snip]

Show quoted text 9 lines
> Just curious, why would you like to detect this? > You want to know how to install files for daemons, append information in other existed packages etc... But instead of creating 1000% packages types for each distro, you can for example know that Gentoo and ArchLinux uses /etc/rc.d/ for init deamons. You know that Debian, CentOS, RedHat and few others uses /etc/init.d/ etc...

Both of those directories are used by virtually all UNIX implementations. /etc/init.d/ contains the init scripts for system daemons, whereas /etc/rc.d/ contains the configuration files that are interpolated into the init scripts to establish environment variables for the daemons. These directories do not have an either/or relationship.

This is a consequence of using an init process based on the System V model.

Why don't you just use a package manager, such as apt/dpkg, Portage, RPM, etc., instead? Most distros can handle more than one of these. For example, I run Gentoo, and it will handle .deb and .rpm packages, as well as its native Portage ebuilds.

Regards, Dave [RLU #314465] *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon) *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

Reply by email

Sven Barth
to David W Noon
David W Noon wrote 26 lines
On Tue, 12 Oct 2010 09:54:35 +0200, ik wrote about Re: [fpc-pascal] Detecting what is the linux distro: > On Tue, Oct 12, 2010 at 09:30, Henry Vermaak > wrote: [snip] >> Just curious, why would you like to detect this? >> > > You want to know how to install files for daemons, append information > in other existed packages etc... But instead of creating 1000% > packages types for each distro, you can for example know that Gentoo > and ArchLinux uses /etc/rc.d/ for init deamons. > You know that Debian, CentOS, RedHat and few others uses /etc/init.d/ > etc... Both of those directories are used by virtually all UNIX implementations. /etc/init.d/ contains the init scripts for system daemons, whereas /etc/rc.d/ contains the configuration files that are interpolated into the init scripts to establish environment variables for the daemons. These directories do not have an either/or relationship. This is a consequence of using an init process based on the System V model.

ArchLinux does not use a System V init system, but a simpler BSD one. And thus it does not use /etc/init.d, but only /etc/rc.d.

Why don't you just use a package manager, such as apt/dpkg, Portage, RPM, etc., instead? Most distros can handle more than one of these. For example, I run Gentoo, and it will handle .deb and .rpm packages, as well as its native Portage ebuilds.

ArchLinux handles only its own ArchLinux Package Manager format (basically a .tar.gz with some script files) - as far as I'm aware of.

Regards,
Sven

Reply by email

David W Noon
to Sven Barth

On Tue, 12 Oct 2010 16:29:42 +0200, Sven Barth wrote about Re: [fpc-pascal] Detecting what is the linux distro:

Am 12.10.2010 14:01, schrieb David W Noon:

[snip]

Show quoted text 5 lines
> This is a consequence of using an init process based on the System V > model. ArchLinux does not use a System V init system, but a simpler BSD one. And thus it does not use /etc/init.d, but only /etc/rc.d.

So does the BSD init use run levels? One of the major distinctions between /etc/init.d/ and /etc/rc.d is that the latter is segregated by run levels, so that each daemon can have a different environment for different run levels. All of the actual init scripts in my /etc/rc.d/ ultimately resolve to symlinks into /etc/init.d/, which is typical for any System V style system.

Indeed, this makes installing a script directly into /etc/rc.d/ a strict no-no under Gentoo, as all insertions into a run level have to be performed by the sysadmin by hand; other Linuxes are more permissive, though. Consequently, I would never want any program to install anything into that directory, except by the rc-update program run by hand.

Regards, Dave [RLU #314465] *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon) *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

Reply by email

ik
to David W Noon: On Tue, 12 Oct 2010 09:54:35 +0200, ik wrote about Re: [fpc-pascal] Detecting what is the…

It's not just that. Lets say you have a UI for IPTables. In Redhat based, it will be located under /etc/sysconfig/iptables . On debian based, it should be under /etc/networking/post-config or something like that (don't have a debian based machine here), and so on...

Please note that I do not talk about exited scripts such as Arno's scripts or shorewall, just plain IPTables client, and it's different on each distro.

If you require to read settings of the system (that located at /etc/), no one guarantee you that all distro's will store then at the same place.

That's the reason why so many software/driver vendors are so reluctant to release Linux support.
For example Foomatic drivers for CUPS, the drivers of the printers in Mac OS-X are the same as with Linux, but many vendors ignore Linux just because this mess.

So it's not just "lets create a package and get over with it", It's not that simple.

Ido

LINESIP websites:
http://www.linesip.com
http://www.linesip.co.il

David W Noon wrote 42 lines
On Tue, 12 Oct 2010 09:54:35 +0200, ik wrote about Re: [fpc-pascal] Detecting what is the linux distro: > On Tue, Oct 12, 2010 at 09:30, Henry Vermaak > wrote: [snip] > > Just curious, why would you like to detect this? > > > > You want to know how to install files for daemons, append information > in other existed packages etc... But instead of creating 1000% > packages types for each distro, you can for example know that Gentoo > and ArchLinux uses /etc/rc.d/ for init deamons. > You know that Debian, CentOS, RedHat and few others uses /etc/init.d/ > etc... Both of those directories are used by virtually all UNIX implementations. /etc/init.d/ contains the init scripts for system daemons, whereas /etc/rc.d/ contains the configuration files that are interpolated into the init scripts to establish environment variables for the daemons. These directories do not have an either/or relationship. This is a consequence of using an init process based on the System V model. Why don't you just use a package manager, such as apt/dpkg, Portage, RPM, etc., instead? Most distros can handle more than one of these. For example, I run Gentoo, and it will handle .deb and .rpm packages, as well as its native Portage ebuilds. -- Regards, Dave [RLU #314465] *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon) *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Henry Vermaak
to ik
ik wrote 10 lines
It's not just that. Lets say you have a UI for IPTables. In Redhat based, it will be located under /etc/sysconfig/iptables . On debian based, it should be under /etc/networking/post-config or something like that (don't have a debian based machine here), and so on... Please note that I do not talk about exited scripts such as Arno's scripts or shorewall, just plain IPTables client, and it's different on each distro. If you require to read settings of the system (that located at /etc/), no one guarantee you that all distro's will store then at the same place.

You can't rely on these things. Distros will even change things from version to version. That is why you put things in configuration files and let the maintainers/packagers supply the correct settings in the config files for their distro. This is how hundreds of apps do things.

That's the reason why so many software/driver vendors are so reluctant to release Linux support.

Nonsense. Most vendors are lazy, some are scared of licensing, etc. Most importantly they think they can get away with not supporting linux because of the small market share. For now.

Henry

Reply by email

Marco van de Voort
to David W Noon: On Tue, 12 Oct 2010 16:29:42 +0200, Sven Barth wrote about Re: [fpc-pascal] Detecting…

In our previous episode, David W Noon said:

> ArchLinux does not use a System V init system, but a simpler BSD one. > And thus it does not use /etc/init.d, but only /etc/rc.d. So does the BSD init use run levels?

Yes.

One of the major distinctions between /etc/init.d/ and /etc/rc.d is that the latter is segregated by run levels, so that each daemon can have a different environment for different run levels.

.. but the mark of the sysV layout is the script per daemon per runtime level. Sometimes it is simplified by making symlinks though.

While classic (pre SysV) Unix (including BSD) has just one or two scripts that handle everything.

Modern BSD (like current FreeBSD) currently afaik do have a script per daemon btw, just not the added dimension of runlevels.

Reply by email

Sven Barth
to Marco van de Voort
Marco van de Voort wrote 21 lines
In our previous episode, David W Noon said: >> ArchLinux does not use a System V init system, but a simpler BSD one. >> And thus it does not use /etc/init.d, but only /etc/rc.d. > > So does the BSD init use run levels? Yes. > One of the major distinctions > between /etc/init.d/ and /etc/rc.d is that the latter is segregated by > run levels, so that each daemon can have a different environment for > different run levels. .. but the mark of the sysV layout is the script per daemon per runtime level. Sometimes it is simplified by making symlinks though. While classic (pre SysV) Unix (including BSD) has just one or two scripts that handle everything. Modern BSD (like current FreeBSD) currently afaik do have a script per daemon btw, just not the added dimension of runlevels.

ArchLinux also uses only one script per daemon which is located in /etc/rc.d/.

The only difference that a runlevel has in ArchLinux is whether the multiuser or the singleuser rc file (which is in /etc/) is called. But this doesn't influence the daemons in /etc/rc.d/.

Regards,
Sven

Reply by email