ADD: Support parsing of /etc/os-release (#804)

(cherry picked from commit 8b056faaa6)
This commit is contained in:
Peter Marquardt 2023-02-10 19:23:57 +01:00 committed by Alexander Koblov
commit 9e2e2ee3d4

View file

@ -91,7 +91,7 @@ begin
sl.LoadFromFile(FileName);
Result := True;
except
on EFilerError do; // Bypass
on EStreamError do sl.Free;
end;
end;
end;
@ -130,8 +130,8 @@ begin
if Result <> EmptyStr then
Result := TrimQuotes(Result)
else
Result := sl.Values['DISTRIB_ID'] +
sl.Values['DISTRIB_RELEASE'] +
Result := sl.Values['DISTRIB_ID'] + ' ' +
sl.Values['DISTRIB_RELEASE'] + ' ' +
sl.Values['DISTRIB_CODENAME'];
end;
finally
@ -139,6 +139,31 @@ begin
end;
end;
function GetOsFromOsRelease: String;
var
sl: TStringListEx;
begin
Result := EmptyStr;
if GetStringsFromFile('/etc/os-release', sl) then
try
if sl.Count > 0 then
begin
Result := sl.Values['PRETTY_NAME'];
if Result <> EmptyStr then
Result := TrimQuotes(Result)
else
Result := sl.Values['NAME'] + ' ' +
sl.Values['VERSION'] + ' ' +
sl.Values['ID'];
end;
finally
sl.Free;
end;
end;
function GetOsFromProcVersion: String;
var
i: Integer;
@ -446,11 +471,15 @@ begin
OSVersion := GetMacOSXVersion;
{$ENDIF}
// Try using linux systemd base.
if OSVersion = EmptyStr then
OSVersion := GetOsFromOsRelease;
// Other methods.
if OSVersion = EmptyStr then
OSVersion := GetOsFromIssue;
if OSVersion = EmptyStr then
OSVersion := GetOsFromProcVersion;
if OSVersion = EmptyStr then
OSVersion := GetOsFromIssue;
// Set default names.
if OSVersion = EmptyStr then