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

This commit is contained in:
Peter Marquardt 2023-02-10 19:23:57 +01:00 committed by GitHub
commit 8b056faaa6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -94,7 +94,7 @@ begin
sl.LoadFromFile(FileName);
Result := True;
except
on EFilerError do; // Bypass
on EStreamError do sl.Free;
end;
end;
end;
@ -133,8 +133,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
@ -142,6 +142,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;
@ -450,11 +475,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