Closed Corin-EU closed 7 years ago
This is proving to be weirdly difficult. Is there no de facto standard for finding the name of a Linux-based OS?
Duplicate of #3.
"This is proving to be weirdly difficult."
You are correct -- it is not easy and there is in fact no de facto standard other than if the lsb package is installed and the lsb_release is available. That is in fact why LSB was devised to bring some standardization to the different GNU/Linux distributions so that at least a minimal standard and capabilities are present.
Note that the presence of /etc/debian_version does not by its-self show that the a system is actual Debian, because derived distributions including Ubuntu and Linux Mint include this file.
As for /etc/issue, if a system has the linuxlogo package installed and operational, which re-writes /etc/issue and /etc/issue.net with an ASCII art image of the distribution logo, then the first line will probably be a blank line or apparently meaningless characters.
Another possible test for distribution name is to check the "version" of the kernel with uname -v, because most distributions create a custom specific kernel version which usually includes the distribution name. But because Linux Mint is basically Ubuntu with its own desktops, administration tools, and some extras, then uname -v on Linux Mint will show an Ubuntu string because Linux Mint uses an Ubuntu kernel. (And Linux Mint Debian edition uses a Debian kernel).
So best to try first with lsb_release.
I agree. I just committed a fix that tries to detect this in three ways, starting with lsb_release
, then looking for cat /etc/*-release
, and finally /etc/issue
. I think this would be good enough for the purposes of this particular script, since we support a few specific OSes anyway. If in the future we support yet another OS that doesn't for some reason work with any of these methods, we will add a method just for that OS.
Thank you everyone for the comments!
That sounds like a good strategy.
Thanks for the fix, it is much appreciated.
I ccanot think of a more unreliable method of determining the distribution name than this
The contents of /etc/issue are never guaranteed to have the distribution name on line 1 nor even contain the distribution name.
If the lsb_release executable is available, then the distribution name can be easily found with
otherwise checking the contents of the file /etc/os-release (if present) can yield results, otherwise looks for files such as /etc/linuxmint/info, /etc/debian_version, etc.