getting distroID from Os Release

This commit is contained in:
2026-05-24 21:42:55 +03:00
parent 1e368b778c
commit e48d93e9f3
+33
View File
@@ -17,6 +17,7 @@ namespace fs = std::filesystem;
string getUser(); string getUser();
string getHost(); string getHost();
string getDistro(); string getDistro();
string distroArt();
string getKernel(); string getKernel();
string getUptime(); string getUptime();
string getShell(); string getShell();
@@ -68,6 +69,8 @@ int main () {
cout << colorRED << "\t\t RAM: \t" << colorRESET << getRAM() << "\n"; cout << colorRED << "\t\t RAM: \t" << colorRESET << getRAM() << "\n";
cout << colorBLUE << "\t\t OS Date:\t" << colorRESET << getOsDate() << "\n"; cout << colorBLUE << "\t\t OS Date:\t" << colorRESET << getOsDate() << "\n";
cout << "distroID: " << distroArt() << "\n";
return 0; return 0;
} }
@@ -126,6 +129,36 @@ string getDistro() {
else return ""; else return "";
} }
string distroArt() {
std::ifstream readOsRelease("/etc/os-release");
if(!readOsRelease.is_open()) {
std::cerr << "Error: Couldn't read /etc/os-release\n";
return "";
}
string distroID;
string line;
while (std::getline(readOsRelease, line)) {
if(line.empty() || line[0] == '#') continue;
std::size_t delimiter = line.find("=");
if(delimiter != string::npos) {
string key = line.substr(0, delimiter);
if (key == "ID"){
distroID = line.substr(delimiter + 1);
if (distroID[0] == '"' && distroID[distroID.length() - 1] == '"') distroID = distroID.substr(1, distroID.length() - 2);
}
}
}
readOsRelease.close();
if (!distroID.empty()) return distroID;
else return "";
}
string getKernel() { string getKernel() {
struct utsname kernelInfo; struct utsname kernelInfo;