2022-04-06 06:25:34 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
2022-11-17 07:46:07 +00:00
|
|
|
File: AuSWInfo.Linux.cpp
|
2022-04-06 06:25:34 +00:00
|
|
|
Date: 2022-4-6
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include <Source/RuntimeInternal.hpp>
|
2022-11-17 07:46:07 +00:00
|
|
|
#include "AuSWInfo.hpp"
|
|
|
|
#include "AuSWInfo.Linux.hpp"
|
2022-04-06 06:25:34 +00:00
|
|
|
|
|
|
|
namespace Aurora::SWInfo
|
|
|
|
{
|
|
|
|
static AuString gKernelString;
|
|
|
|
static AuString gUserlandBrand;
|
|
|
|
static AuString gUserlandDesktopEnv;
|
|
|
|
static AuString gBuildString;
|
|
|
|
|
|
|
|
static void SetProcVersion()
|
|
|
|
{
|
|
|
|
AuIOFS::ReadString("/proc/version", gBuildString);
|
|
|
|
if (gBuildString.size() && gBuildString[gBuildString.size() - 1] == '\n')
|
|
|
|
{
|
|
|
|
gBuildString.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SetVersion(OSInformation &osInfo)
|
|
|
|
{
|
|
|
|
char *endPtr;
|
|
|
|
|
|
|
|
auto versionItr = gBuildString.find("ersion ");
|
|
|
|
if (versionItr == AuString::npos) return;
|
|
|
|
|
|
|
|
if (versionItr > 2)
|
|
|
|
{
|
|
|
|
gKernelString = gBuildString.substr(0, versionItr - 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ptr = gBuildString.c_str() + (7 + AuUInt(versionItr));
|
|
|
|
|
|
|
|
osInfo.uKernelMajor = strtoll(ptr, &endPtr, 10);
|
|
|
|
if (errno == ERANGE) return;
|
|
|
|
if (*endPtr != '.') return;
|
|
|
|
|
|
|
|
endPtr++;
|
|
|
|
|
|
|
|
osInfo.uKernelMinor = strtoll(endPtr, &endPtr, 10);
|
|
|
|
if (errno == ERANGE) return;
|
|
|
|
if (*endPtr != '.') return;
|
|
|
|
|
|
|
|
endPtr++;
|
|
|
|
|
|
|
|
osInfo.uKernelPatch = strtoll(endPtr, &endPtr, 10);
|
|
|
|
}
|
|
|
|
|
2024-05-07 13:41:16 +00:00
|
|
|
static bool ProcessVersionLine(OSInformation &osInfo, const AuROString &line);
|
2022-12-28 21:14:52 +00:00
|
|
|
|
2022-04-06 06:25:34 +00:00
|
|
|
static void ParseOSRel(OSInformation &osInfo)
|
|
|
|
{
|
|
|
|
AuString osRel;
|
|
|
|
|
2022-12-28 21:14:52 +00:00
|
|
|
if (!AuIOFS::ReadString("/etc/os-release", osRel))
|
|
|
|
{
|
|
|
|
if (!AuIOFS::ReadString("/usr/lib/os-release", osRel))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-06 06:25:34 +00:00
|
|
|
AuReplaceAll(osRel, "\"", "");
|
|
|
|
|
2024-05-07 13:41:16 +00:00
|
|
|
AuList<AuROString> versionNumbers;
|
2022-04-06 06:25:34 +00:00
|
|
|
|
2024-05-07 13:41:16 +00:00
|
|
|
Parse::SplitNewlines(osRel, [&](const AuROString &line)
|
2022-04-06 06:25:34 +00:00
|
|
|
{
|
|
|
|
if (AuStartsWith(line, "NAME="))
|
|
|
|
{
|
2024-05-07 13:41:16 +00:00
|
|
|
gUserlandBrand = AuString(line.substr(5));
|
2022-04-06 06:25:34 +00:00
|
|
|
}
|
|
|
|
else if (AuStartsWith(line, "VERSION="))
|
|
|
|
{
|
|
|
|
versionNumbers.push_back(line.substr(8));
|
|
|
|
}
|
|
|
|
else if (AuStartsWith(line, "VERSION_ID="))
|
|
|
|
{
|
|
|
|
versionNumbers.push_back(line.substr(11));
|
|
|
|
}
|
|
|
|
else if (AuStartsWith(line, "BUILD_ID="))
|
|
|
|
{
|
|
|
|
versionNumbers.push_back(line.substr(9));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-05-07 13:41:16 +00:00
|
|
|
std::sort(versionNumbers.begin(), versionNumbers.end(), [](const AuROString &str, const AuROString &strb)
|
2022-12-28 21:14:52 +00:00
|
|
|
{
|
2023-12-21 13:33:04 +00:00
|
|
|
return str.length() >= strb.length();
|
|
|
|
});
|
|
|
|
|
|
|
|
for (auto &line : versionNumbers)
|
|
|
|
{
|
|
|
|
if (line.size() > 2 && line[0] == '"' && line[line.size() - 1] == '"')
|
|
|
|
{
|
|
|
|
line = line.substr(1, line.size() - 2);
|
|
|
|
}
|
|
|
|
|
2022-12-28 21:14:52 +00:00
|
|
|
if (ProcessVersionLine(osInfo, line))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-12-21 13:33:04 +00:00
|
|
|
|
|
|
|
// generic server/*erver (Server/server) distros
|
|
|
|
osInfo.bIsServer |= osRel.find("erver") != AuString::npos;
|
2022-12-28 21:14:52 +00:00
|
|
|
}
|
|
|
|
|
2024-05-07 13:41:16 +00:00
|
|
|
static bool ProcessVersionLineParts(OSInformation &osInfo, const AuROString &line)
|
2022-12-28 21:14:52 +00:00
|
|
|
{
|
|
|
|
auto firstPeriod = line.find(".");
|
|
|
|
if (firstPeriod == AuString::npos)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ptr = line.data();
|
2024-05-07 13:41:16 +00:00
|
|
|
char *endPtr = (char *)line.data() + line.size();
|
2022-12-28 21:14:52 +00:00
|
|
|
|
|
|
|
osInfo.uUserlandMajor = strtoll(ptr, &endPtr, 10);
|
|
|
|
if (errno == ERANGE) return false;
|
|
|
|
if (*endPtr != '.') return true;
|
|
|
|
|
|
|
|
endPtr++;
|
|
|
|
|
|
|
|
osInfo.uUserlandMinor = strtoll(endPtr, &endPtr, 10);
|
|
|
|
if (errno == ERANGE) return false;
|
|
|
|
if (*endPtr != '.') return true;
|
|
|
|
|
|
|
|
endPtr++;
|
|
|
|
|
|
|
|
osInfo.uUserlandPatch = strtoll(endPtr, &endPtr, 10);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-05-07 13:41:16 +00:00
|
|
|
static bool ProcessVersionLine(OSInformation &osInfo, const AuROString &line)
|
2022-12-28 21:14:52 +00:00
|
|
|
{
|
|
|
|
auto parts = AuSplitString(line, " ");
|
|
|
|
|
|
|
|
for (const auto &line : parts)
|
|
|
|
{
|
|
|
|
if (ProcessVersionLineParts(osInfo, line))
|
|
|
|
{
|
2023-03-12 15:27:28 +00:00
|
|
|
return true;
|
2022-12-28 21:14:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2022-04-06 06:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void SetDesktopWindowManager()
|
|
|
|
{
|
2022-05-04 15:34:02 +00:00
|
|
|
const char *name;
|
|
|
|
|
|
|
|
name = ::getenv("XDG_CURRENT_DESKTOP");
|
|
|
|
|
|
|
|
if (!name)
|
|
|
|
{
|
|
|
|
name = ::getenv("XDG_SESSION_DESKTOP");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!name)
|
|
|
|
{
|
|
|
|
name = ::getenv("DESKTOP_SESSION");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
gUserlandDesktopEnv = name;
|
|
|
|
}
|
2022-04-06 06:25:34 +00:00
|
|
|
}
|
|
|
|
|
2022-12-28 23:44:45 +00:00
|
|
|
static void CheckForSupportLicenseHints(OSInformation &osInfo)
|
|
|
|
{
|
|
|
|
AuString a;
|
|
|
|
|
|
|
|
osInfo.bIsEnterprise = false;
|
|
|
|
|
|
|
|
if (AuFS::ReadString("/etc/system-release-cpe", a))
|
|
|
|
{
|
2023-12-21 13:20:07 +00:00
|
|
|
// redhat
|
2022-12-28 23:44:45 +00:00
|
|
|
osInfo.bIsEnterprise |= a.find("nterprise") != AuString::npos; // cpe:?????:enterprise_linux:??????
|
2023-12-21 13:20:07 +00:00
|
|
|
// aws
|
|
|
|
osInfo.bIsServer |= a.find("ami") != AuString::npos; // al202?-ami-202?.?.????.0-kernel-?.?-x86_64
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// centos and similar
|
|
|
|
osInfo.bIsServer |= AuFS::FileExists("/etc/redhat-release");
|
2022-12-28 23:44:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-06 06:25:34 +00:00
|
|
|
void InitLinuxInfo(OSInformation &osInfo)
|
|
|
|
{
|
2023-12-21 15:31:19 +00:00
|
|
|
osInfo = AuMove(OSInformation(&gKernelString, &gUserlandBrand, &gUserlandDesktopEnv, &gBuildString, AuBuild::kCurrentPlatform));
|
2022-04-06 06:25:34 +00:00
|
|
|
|
|
|
|
SetProcVersion();
|
|
|
|
SetVersion(osInfo);
|
|
|
|
ParseOSRel(osInfo);
|
2022-12-28 23:44:45 +00:00
|
|
|
CheckForSupportLicenseHints(osInfo);
|
2022-04-06 06:25:34 +00:00
|
|
|
|
|
|
|
SetDesktopWindowManager();
|
|
|
|
}
|
|
|
|
}
|