1 From 1b0c5d63f6269afa46d121c28160a339da5dd5b7 Mon Sep 17 00:00:00 2001
2 From: Scott Talbert <swt@techie.net>
3 Date: Fri, 14 Jul 2023 11:45:19 -0400
4 Subject: [PATCH] Read Linux distribution info from os-release file
6 The Linux distribution community has somewhat deprecated the lsb_release
7 utility and has standardized on a new file, os-release, that can be
8 simply parsed to get the same information. Attempt to read this file in
9 /etc/os-release, then /usr/lib/os-release, and finally, fall back to
10 using the lsb_release utility if neither of those files are found.
12 See: https://www.freedesktop.org/software/systemd/man/os-release.html
13 Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2184391
17 (cherry picked from commit aef7df6c9f44f751d97f4f6519ae6e5c3b81019d)
19 docs/changes.txt | 1 +
20 src/unix/utilsunx.cpp | 30 ++++++++++++++++++++++++++++++
21 2 files changed, 31 insertions(+)
23 diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp
24 index ac5181e187f3..302aaa25b8f5 100644
25 --- a/src/unix/utilsunx.cpp
26 +++ b/src/unix/utilsunx.cpp
28 #include "wx/evtloop.h"
29 #include "wx/mstream.h"
30 #include "wx/private/fdioeventloopsourcehandler.h"
31 +#include "wx/config.h"
32 +#include "wx/filename.h"
35 #include <sys/wait.h> // waitpid()
36 @@ -1147,6 +1149,23 @@ wxString wxGetNativeCpuArchitectureName()
41 +wxGetValuesFromOSRelease(const wxString& filename, wxLinuxDistributionInfo& ret)
43 + if ( !wxFileName::Exists(filename) )
48 + wxFileConfig fc(wxEmptyString, wxEmptyString, wxEmptyString, filename);
49 + ret.Id = fc.Read(wxS("ID"), wxEmptyString).Capitalize();
50 + ret.Description = fc.Read(wxS("PRETTY_NAME"), wxEmptyString);
51 + ret.Release = fc.Read(wxS("VERSION_ID"), wxEmptyString);
52 + ret.CodeName = fc.Read(wxS("VERSION_CODENAME"), wxEmptyString);
58 wxGetValueFromLSBRelease(const wxString& arg, const wxString& lhs, wxString* rhs)
60 @@ -1161,6 +1180,17 @@ wxLinuxDistributionInfo wxGetLinuxDistributionInfo()
62 wxLinuxDistributionInfo ret;
64 + // Read /etc/os-release and fall back to /usr/lib/os-release per below
65 + // https://www.freedesktop.org/software/systemd/man/os-release.html
66 + if ( wxGetValuesFromOSRelease(wxS("/etc/os-release"), ret) )
70 + if ( wxGetValuesFromOSRelease(wxS("/usr/lib/os-release"), ret) )
75 if ( !wxGetValueFromLSBRelease(wxS("--id"), wxS("Distributor ID:\t"),