Improve how we identify Linux version in `hostInfo` command
What should be done?
In hostInfo we identify Linux' release by checking /etc/os-release file and parsing the version from it: https://github.com/FerretDB/FerretDB/blob/b1cc4e8b1138805a9d16fafb4ff880dc73d4e6eb/internal/handlers/common/msg_hostinfo.go#L47
However, not each Linux distro contains the version information in this file. As the result, this check https://github.com/FerretDB/FerretDB/blob/b1cc4e8b1138805a9d16fafb4ff880dc73d4e6eb/integration/commands_diagnostic_test.go#L227 will fail for such distros.
Let's investigate what's possible for such distros - is there a way to get the info about the version, should we set some "default value", or should we allow an empty version to be set (and then we need to fix the test).
Many thanks to @raeidish for reporting this problem with Arch Linux (see also https://gist.github.com/natefoo/814c5bf936922dad97ff).
doing something like the following in parse_osrelease.go does fix the issue for me. however you might want to get the kernel version with uname utility instead
v, fv := configParams["VERSION"]
n, fn := configParams["NAME"]
if !fv {
v = "undefined"
}
if !fn {
n = "undefined"
}
It is very strange that /etc/os-release does not exist on Arch Linux. It is the very common and standard file:
- https://www.freedesktop.org/software/systemd/man/os-release.html
- https://man.archlinux.org/man/os-release.5.en
Maybe the location is different and we should try a few more like /usr/lib/os-release?
We could also try to parse lsb-release file, but we definitely don't want to run lsb_release tool.
I have checked several distros:
| Distro | /etc/os-release |
/usr/lib/os-release |
|---|---|---|
| Arch | :x: | :heavy_check_mark: |
| Red Hat | :heavy_check_mark: | :heavy_check_mark: |
| Ubuntu | :heavy_check_mark: | :heavy_check_mark: |
| Amazon Linux | :heavy_check_mark: | :heavy_check_mark: |
| CentOS | :heavy_check_mark: | :heavy_check_mark: |
| openSUSE | :heavy_check_mark: | :heavy_check_mark: |
| Debian | :heavy_check_mark: | :heavy_check_mark: |
| Scientific Linux(SL) | :heavy_check_mark: | :x: |
However, Arch contains /etc/arch-release instead of /etc/os-release.
So we can:
- use the pattern
/etc/*-release - make a condition for Arch
- switch to file:
/usr/lib/os-releaseEDIT: Scientific Linux misses it
What does seem to be a better option?
Can I work on this issue?
@kropidlowsky, your proposal sounds good to me! Please feel free to take this issue.
(As agreed, the option 2 should be enough)
After reading http://0pointer.de/blog/projects/os-release, I think that instead of reading distribution-specific files, we should read two possible paths for distribution-independent files: /etc/os-release and /usr/lib/os-release.
@kropidlowsky could you contribute a new PR?