From e48d93e9f3b7055b4ae2d316503f06a86dee3034 Mon Sep 17 00:00:00 2001 From: murat Date: Sun, 24 May 2026 21:42:55 +0300 Subject: [PATCH] getting distroID from Os Release --- main.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/main.cpp b/main.cpp index 3a70164..3b65018 100644 --- a/main.cpp +++ b/main.cpp @@ -17,6 +17,7 @@ namespace fs = std::filesystem; string getUser(); string getHost(); string getDistro(); +string distroArt(); string getKernel(); string getUptime(); string getShell(); @@ -68,6 +69,8 @@ int main () { cout << colorRED << "\t\t RAM: \t" << colorRESET << getRAM() << "\n"; cout << colorBLUE << "\t\t OS Date:\t" << colorRESET << getOsDate() << "\n"; + cout << "distroID: " << distroArt() << "\n"; + return 0; } @@ -126,6 +129,36 @@ string getDistro() { 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() { struct utsname kernelInfo;