tliron / install-gnome-themes

Script to install the latest versions of some fine GNOME 3 themes
MIT License
435 stars 44 forks source link

Reliable determination of the Distribution Name #9

Closed Corin-EU closed 7 years ago

Corin-EU commented 7 years ago

I ccanot think of a more unreliable method of determining the distribution name than this

  head -1 /etc/issue | cut --delimiter=' ' --fields=1

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

   lsb_release -i | sed -ne 's|Distributor ID:[[:space:]]||p'

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.

tliron commented 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.

Corin-EU commented 7 years ago

"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.

tliron commented 7 years ago

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!

Corin-EU commented 7 years ago

That sounds like a good strategy.

Thanks for the fix, it is much appreciated.