commit 0cb5859e319f832008881ab2a678f5fbb4658ebf Author: iliketwertles Date: Mon Jan 8 19:31:10 2024 -0500 add files diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..4039bef --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,16 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c3ae15c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,73 @@ +{ + "files.associations": { + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "array": "cpp", + "atomic": "cpp", + "hash_map": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdint": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "format": "cpp", + "fstream": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp", + "variant": "cpp", + "codecvt": "cpp" + }, + "C_Cpp.errorSquiggles": "disabled" +} \ No newline at end of file diff --git a/extra.cpp b/extra.cpp new file mode 100644 index 0000000..0d47d1c --- /dev/null +++ b/extra.cpp @@ -0,0 +1,131 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +struct utsname unameData; + +std::string trim(const std::string& line) { + const char* WhiteSpace = " \t\v\r\n"; + std::size_t start = line.find_first_not_of(WhiteSpace); + std::size_t end = line.find_last_not_of(WhiteSpace); + return start == end ? std::string() : line.substr(start, end - start + 1); +} + +std::string exec(const char* cmd) { + std::array buffer; + std::string result; + std::unique_ptr pipe(popen(cmd, "r"), pclose); + if (!pipe) { + throw std::runtime_error("popen() failed!"); + } + while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { + result += buffer.data(); + } + return result; +} + + +void fumo(std::string distro, std::string kernel, std::string packages, std::string desktop, double diff) { + // getting arch + uname(&unameData); + std::string arch = unameData.machine; + + //getting cpu info + std::string cpuinfo_s, cpu, line, init_name; + std::ifstream cpuinfo ("/proc/cpuinfo"); + if ( cpuinfo.is_open() ) { + std::string model = "model name"; + while ( std::getline(cpuinfo, line) ) { + size_t found = line.find(model); + if (found != std::string::npos) { + cpu = line.substr(found + 13); + + // .erase(cpu.find_last_not_of(" \t") + 1); + cpu.erase(0, cpu.find_first_not_of(" \t")); + cpu.erase(cpu.find_last_not_of((" \t")) +1); + line = ""; + + break; + } + } + } else { + std::cout << "/proc/cpuinfo isnt open!" << std::endl; + } + + //getting gpu (please help me) + //std::string gpu = exec("lspci | grep -m 1 ' VGA ' | cut -d" " -f 9-") + + //getting init + if ( std::filesystem::exists("/etc/systemd/system.conf") ) { + init_name = "Systemd"; + } else if ( std::filesystem::exists("/etc/init.d") ) { + init_name = "OpenRC"; + } else if ( std::filesystem::exists("/etc/runit/1") ) { + init_name = "Runit"; + } else { + init_name = "i dunno"; + } + + //getting meminfo + std::ifstream meminfo ("/proc/meminfo"); + std::string total; + std::string available; + if ( meminfo.is_open() ) { + total = "MemTotal:"; + available = "MemAvailable:"; + while ( std::getline(meminfo, line) ) { + size_t foundt = line.find(total); + size_t founda = line.find(available); + if ( foundt != std::string::npos ) { + total = line.substr(foundt + total.length()); + total.erase(0, total.find_first_not_of(" \t")); + total.erase(total.find_last_not_of(" \t") + 1); + total = total.substr(0, total.size()-3); + } else if ( founda != std::string::npos ) { + available = line.substr(founda + available.length()); + available.erase(0, available.find_first_not_of(" \t")); + available.erase(available.find_last_not_of(" \t") + 1); + available = available.substr(0, available.size()-3); + } + if ( total != "MemTotal:" && available != "MemAvailable:" ) { break; } + } + } + meminfo.close(); + int used = std::stoi(total) - std::stoi(available); + + + printf("⠀⢀⣒⠒⠆⠤⣀⡀⠀\n"); + printf("⢠⡛⠛⠻⣷⣶⣦⣬⣕⡒⠤⢀⣀⠀\n"); + printf("⡿⢿⣿⣿⣿⣿⣿⡿⠿⠿⣿⣳⠖⢋⣩⣭⣿⣶⡤⠶⠶⢶⣒⣲⢶⣉⣐⣒⣒⣒⢤⡀⠀\n"); + printf("⣿⠀⠉⣩⣭⣽⣶⣾⣿⢿⡏⢁⣴⠿⠛⠉⠁⠀⠀⠀⠀⠀⠀⠉⠙⠲⢭⣯⣟⡿⣷⣘⠢⡀\n"); + printf("⠹⣷⣿⣿⣿⣿⣿⢟⣵⠋⢠⡾⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣿⣿⣾⣦⣾⣢\n"); + printf("⠀⠹⣿⣿⣿⡿⣳⣿⠃⠀⣼⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢻⣿⣿⣿⠟\n"); + printf("⠀⠀⠹⣿⣿⣵⣿⠃⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣷⡄\n"); + printf("⠀⠀⠀⠈⠛⣯⡇⠛⣽⣦⣿⠀⠀⠀⠀⢀⠔⠙⣄⠀⠀⠀⠀⠀⠀⣠⠳⡀⠀⠀⠀⠀⢿⡵⡀⠀⠀ Distro:\033[36m %s \033[0m\n", distro.c_str()); + printf("⠀⠀⠀⠀⣸⣿⣿⣿⠿⢿⠟⠀⠀⠀⢀⡏⠀⠀⠘⡄⠀⠀⠀⠀⢠⠃⠀⠹⡄⠀⠀⠀⠸⣿⣷⡀⠀⠀ Kernel:\033[33m %s \033[0m\n", kernel.c_str()); + printf("⠀⠀⠀⠸⣿⣿⠟⢹⣥⠀⠀⠀⠀⠀⣸⣀⣀⣤⣀⣀⠈⠳⢤⡀⡇⣀⣠⣄⣸⡆⠀⠀⠀⡏⠀⠀ Packages:\033[34m %s \033[0m\n", packages.c_str()); + printf("⠀⠀⠀⠀⠁⠁⠀⢸⢟⡄⠀⠀⠀⠀⣿⣾⣿⣿⣿⣿⠁⠀⠈⠙⠙⣯⣿⣿⣿⡇⠀⠀⢠⠃ Desktop:\033[31m %s \033[0m\n", desktop.c_str()); + printf("⠀⠀⠀⠀⠀⠀⠀⠇⢨⢞⢆⠀⠀⠀⡿⣿⣿⣿⣿⡏⠀⠀⠀⠀⠀⣿⣿⣿⡿⡇⠀⣠⢟⡄ Arch:\033[35m %s \033[0m\n", arch.c_str()); + printf("⠀⠀⠀⠀⠀⠀⡼⠀⢈⡏⢎⠳⣄⠀⡇⠙⠛⠟⠛⠀⠀⠀⠀⠀⠀⠘⠻⠛⢱⢃⡜⡝⠈⠚⡄ CPU:\033[32m %s \033[0m\n", cpu.c_str()); + printf("⠀⠀⠀⠀⠀⠘⣅⠁⢸⣋⠈⢣⡈⢷⠇⠀⠀⠀⠀⠀⣄⠀⠀⢀⡄⠀⠀⣠⣼⢯⣴⠇⣀⡀⢸ GPU:\033[33m %s \033[0m\n", trim(exec("lspci | grep -m 1 ' VGA ' | cut -d\" \" -f 9-")).c_str()); + printf("⠀⠀⠀⠀⠀⠀⠈⠳⡌⠛⣶⣆⣷⣿⣦⣄⣀⠀⠀⠀⠈⠉⠉⢉⣀⣤⡞⢛⣄⡀⢀⡨⢗⡦⠎ Init:\033[31m %s \033[0m\n", init_name.c_str()); + printf("⠀⠀⠀⠀⠀⠀⠀⠀⠈⠑⠪⣿⠁⠀⠐⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣏⠉⠁⢸⠀⠀⠀⠄⠙⡆ Shell:\033[35m %s \033[0m\n", getenv("SHELL")); + printf("⠀⠀⠀⠀⠀⠀⠀⠀⣀⠤⠚⡉⢳⡄⠡⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣏⠁⣠⣧⣤⣄⣀⡀⡰⠁ Mem:\033[36m %i/%imb \033[0m\n", used / 1024, std::stoi(total) / 1024); + printf("⠀⠀⠀⠀⠀⢀⠔⠉⠀⠀⠀⠀⢀⣧⣠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣅⡀\n"); + printf("⠀⠀⠀⠀⠀⢸⠆⠀⠀⠀⣀⣼⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠟⠋⠁⣠⠖⠒⠒⠛⢿⣆\n"); + printf("⠀⠀⠀⠀⠀⠀⠑⠤⠴⠞⢋⣵⣿⢿⣿⣿⣿⣿⣿⣿⠗⣀⠀⠀⠀⠀⠀⢰⠇⠀⠀⠀⠀⢀⡼⣶⣤\n"); + printf("⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠟⢛⣿⠀⠙⠲⠽⠛⠛⠵⠞⠉⠙⠳⢦⣀⣀⡞⠀⠀⠀⠀⡠⠋⠐⠣⠮⡁\n"); + printf("⠀⠀⠀⠀⠀⠀⠀⢠⣎⡀⢀⣾⠇⢀⣠⡶⢶⠞⠋⠉⠉⠒⢄⡀⠉⠈⠉⠀⠀⠀⣠⣾⠀⠀⠀⠀⠀⢸⡀\n"); + printf("⠀⠀⠀⠀⠀⠀⠀⠘⣦⡀⠘⢁⡴⢟⣯⣞⢉⠀⠀⠀⠀⠀⠀⢹⠶⠤⠤⡤⢖⣿⡋⢇⠀⠀⠀⠀⠀⢸⠀\n"); + printf("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠵⠗⠺⠟⠖⢈⡣⡄⠀⠀⠀⠀⢀⣼⡤⣬⣽⠾⠋⠉⠑⠺⠧⣀⣤⣤⡠⠟⠃\n"); // ignore this V + std::cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠷⠶⠦⠶⠞⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ You installed " << (int) diff << " days ago" << '\n'; +} diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..ae27561 --- /dev/null +++ b/main.cpp @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include +#include +#include "extra.cpp" +#include +#include + +struct stat fileInfo; + +int main(int argc, char* argv[]) { + namespace fs = std::filesystem; + // defining + const time_t today = std::time(0); + std::string distro, kernel, packages, desktop, osrelease_s, line; + time_t birth_date; + std::ifstream osrelease ("/etc/os-release"); + + // reading /etc/os-release to get distro name, under NAME= + if ( osrelease.is_open() ) { + std::string name = "NAME="; + while ( std::getline(osrelease, line) ) { + size_t found = line.find(name); + if ( found != std::string::npos ) { + distro = line.substr(found + name.length()); + + distro.erase(0, distro.find_first_not_of(" \t")); + distro.erase(distro.find_last_not_of(" \t") + 1); + + break; + } + } + } else { + std::cout << "/etc/os-release isnt open!" << std::endl; + return 1; + } + osrelease.close(); + + // getting kernel version + uname(&unameData); + kernel = unameData.release; + + // getting packages, only works for emerge from gentoo + if (fs::is_directory("/var/db/pkg")) { + int count = 0; + for (const auto& entry : fs::directory_iterator("/var/db/pkg")) { + if (fs::is_directory(entry.path())) { + for (const auto& sub_entry : fs::directory_iterator(entry.path())) { + if (fs::is_directory(sub_entry.path())) { + count++; + } + } + } + } + packages = std::to_string(count); + } else { + packages = "unsupported :("; + } + + // getting desktop env, if it cant read current desktop + // it reads desktop session, if both are null then you + // dont have a desktop + if ( getenv("XDG_CURRENT_DESKTOP") != NULL ) { + desktop = getenv("XDG_CURRENT_DESKTOP"); + } else if ( getenv("DESKTOP_SESSION") != NULL ) { + desktop = getenv("DESKTOP_SESSION"); + } else { + desktop = "i dunno :("; + } + + // getting date of linux install (theoretical) + // uses metadata of the path / to simulate the + // oldest thing, obv doesnt work if you + // reformatted root + if ( stat("/", &fileInfo) == 0 ) { + birth_date = fileInfo.st_ctime; + } else { + birth_date = 0; + } + double diff = std::difftime(today, birth_date) / (60 * 60 * 24); + + // printing everything out, idk a better way to do it + if (argc >= 2 && strcmp(argv[1], "-f") == 0) { + fumo(distro, kernel, packages, desktop, diff); + return 0; + } else { + std::cout << " .--." << '\n'; + std::cout << " |o_o | Distro: " << "\033[36m" << distro << "\033[0m" << '\n'; + std::cout << " |:_/ | Kernel: " << "\033[33m" << kernel << "\033[0m" << '\n'; + std::cout << R"( // \ \ Packages: )" << "\033[34m" << packages << "\033[0m" << '\n'; + std::cout << " (| | ) Desktop: " << "\033[31m" << desktop << "\033[0m" << '\n'; + std::cout << R"( /'\_ _/`\ )" << '\n'; + std::cout << R"( \___)=(___/ You installed )" << (int) diff << " days ago" << '\n'; + } + return 0; +} \ No newline at end of file