mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Fallback OS detection using lsb
This commit is contained in:
@@ -159,6 +159,7 @@ set(SRCS
|
||||
src/common/settings.c
|
||||
src/common/library.c
|
||||
src/common/networking.c
|
||||
src/detection/os.c
|
||||
src/detection/plasma.c
|
||||
src/detection/gtk.c
|
||||
src/detection/terminalShell.c
|
||||
|
||||
@@ -10,13 +10,9 @@ Here i just add things that are easy to forget.
|
||||
- [ ] Support for printing images as ascii art logos (using imlib2 and libcaca probably)
|
||||
- [ ] Support for printing images in terminals that support it
|
||||
- [ ] Better OS output for all possible combinations of /etc/os-release variables.
|
||||
- [ ] Fallback OS detection with lsb
|
||||
- [ ] Expose temperatures to CPU format string
|
||||
- [ ] Expose temperatures to GPU format string
|
||||
- [ ] Create a GPU driver module
|
||||
- [ ] Expose GPU driver to GPU format string
|
||||
- [ ] Fallback GPU detection using GL (multi GPU suport somehow possible?)
|
||||
- [ ] Add a public IP module
|
||||
- [ ] Find wayland compositor by looking at \${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY:-wayland-0}
|
||||
- [ ] Make LocalIP module more configurable
|
||||
- [ ] Automatic migrate old config files to newer versions
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
const FFOSResult* ffDetectOS(FFinstance* instance)
|
||||
{
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static FFOSResult result;
|
||||
static bool init = false;
|
||||
pthread_mutex_lock(&mutex);
|
||||
if(init)
|
||||
{
|
||||
pthread_mutex_unlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
init = true;
|
||||
|
||||
ffStrbufInit(&result.systemName);
|
||||
ffStrbufInit(&result.name);
|
||||
ffStrbufInit(&result.prettyName);
|
||||
ffStrbufInit(&result.id);
|
||||
ffStrbufInit(&result.idLike);
|
||||
ffStrbufInit(&result.variant);
|
||||
ffStrbufInit(&result.variantID);
|
||||
ffStrbufInit(&result.version);
|
||||
ffStrbufInit(&result.versionID);
|
||||
ffStrbufInit(&result.codename);
|
||||
ffStrbufInit(&result.buildID);
|
||||
ffStrbufInit(&result.architecture);
|
||||
ffStrbufInit(&result.error);
|
||||
|
||||
ffStrbufSetS(&result.systemName, instance->state.utsname.sysname);
|
||||
ffStrbufSetS(&result.architecture, instance->state.utsname.machine);
|
||||
|
||||
#if !__ANDROID__
|
||||
bool isOsRelease = true;
|
||||
FILE* file = fopen("/etc/os-release", "r");
|
||||
|
||||
if(file == NULL)
|
||||
file = fopen("/usr/lib/os-release", "r");
|
||||
|
||||
if(file == NULL)
|
||||
{
|
||||
file = fopen("/etc/lsb-release", "r");
|
||||
isOsRelease = false;
|
||||
}
|
||||
|
||||
ffStrbufInitA(&result.error, 64);
|
||||
if(file == NULL)
|
||||
{
|
||||
ffStrbufAppendS(&result.error, "couldn't read /etc/os-release nor /usr/lib/os-release nor /etc/lsb-release");
|
||||
return &result;
|
||||
}
|
||||
|
||||
char* line = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
// Documentation of the fields:
|
||||
// https://www.freedesktop.org/software/systemd/man/os-release.html
|
||||
while (getline(&line, &len, file) != -1)
|
||||
{
|
||||
if(isOsRelease)
|
||||
{
|
||||
ffGetPropValue(line, "NAME =", &result.name);
|
||||
ffGetPropValue(line, "PRETTY_NAME =", &result.prettyName);
|
||||
ffGetPropValue(line, "ID =", &result.id);
|
||||
ffGetPropValue(line, "ID_LIKE =", &result.idLike);
|
||||
ffGetPropValue(line, "VARIANT =", &result.variant);
|
||||
ffGetPropValue(line, "VARIANT_ID =", &result.variantID);
|
||||
ffGetPropValue(line, "VERSION =", &result.version);
|
||||
ffGetPropValue(line, "VERSION_ID =", &result.versionID);
|
||||
ffGetPropValue(line, "VERSION_CODENAME =", &result.codename);
|
||||
ffGetPropValue(line, "BUILD_ID =", &result.buildID);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffGetPropValue(line, "DISTRIB_ID =", &result.id);
|
||||
ffGetPropValue(line, "DISTRIB_RELEASE =", &result.version);
|
||||
ffGetPropValue(line, "DISTRIB_DESCRIPTION =", &result.prettyName);
|
||||
}
|
||||
}
|
||||
|
||||
if(line != NULL)
|
||||
free(line);
|
||||
|
||||
fclose(file);
|
||||
#else
|
||||
ffStrbufSetS(&result.name, "Android");
|
||||
ffStrbufSetS(&result.id, "android");
|
||||
ffSettingsGetAndroidProperty("ro.build.version.release", &result.versionID);
|
||||
ffSettingsGetAndroidProperty("ro.build.version.release", &result.version);
|
||||
ffSettingsGetAndroidProperty("ro.build.version.codename", &result.codename);
|
||||
ffSettingsGetAndroidProperty("ro.build.id", &result.buildID);
|
||||
#endif
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return &result;
|
||||
}
|
||||
+3
-1
@@ -410,6 +410,9 @@ FFvariant ffSettingsGetXFConf(FFinstance* instance, const char* channelName, con
|
||||
bool ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result);
|
||||
#endif
|
||||
|
||||
//detection/os.c
|
||||
const FFOSResult* ffDetectOS(FFinstance* instance);
|
||||
|
||||
//detection/plasma.c
|
||||
const FFPlasmaResult* ffDetectPlasma(FFinstance* instance);
|
||||
|
||||
@@ -429,7 +432,6 @@ const FFTerminalShellResult* ffDetectTerminalShell(FFinstance* instance);
|
||||
/********************/
|
||||
|
||||
//Common
|
||||
const FFOSResult* ffDetectOS(FFinstance* instance);
|
||||
const FFTitleResult* ffDetectTitle(FFinstance* instance);
|
||||
|
||||
//Printing
|
||||
|
||||
@@ -1,90 +1,8 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#define FF_OS_MODULE_NAME "OS"
|
||||
#define FF_OS_NUM_FORMAT_ARGS 12
|
||||
|
||||
const FFOSResult* ffDetectOS(FFinstance* instance)
|
||||
{
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static FFOSResult result;
|
||||
static bool init = false;
|
||||
pthread_mutex_lock(&mutex);
|
||||
if(init)
|
||||
{
|
||||
pthread_mutex_unlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
init = true;
|
||||
|
||||
ffStrbufInit(&result.systemName);
|
||||
ffStrbufInit(&result.name);
|
||||
ffStrbufInit(&result.prettyName);
|
||||
ffStrbufInit(&result.id);
|
||||
ffStrbufInit(&result.idLike);
|
||||
ffStrbufInit(&result.variant);
|
||||
ffStrbufInit(&result.variantID);
|
||||
ffStrbufInit(&result.version);
|
||||
ffStrbufInit(&result.versionID);
|
||||
ffStrbufInit(&result.codename);
|
||||
ffStrbufInit(&result.buildID);
|
||||
ffStrbufInit(&result.architecture);
|
||||
ffStrbufInit(&result.error);
|
||||
|
||||
ffStrbufSetS(&result.systemName, instance->state.utsname.sysname);
|
||||
ffStrbufSetS(&result.architecture, instance->state.utsname.machine);
|
||||
|
||||
#if !__ANDROID__
|
||||
FILE* osRelease = fopen("/etc/os-release", "r");
|
||||
|
||||
if(osRelease == NULL)
|
||||
osRelease = fopen("/usr/lib/os-release", "r");
|
||||
|
||||
ffStrbufInitA(&result.error, 64);
|
||||
if(osRelease == NULL)
|
||||
{
|
||||
ffStrbufAppendS(&result.error, "couldn't read /etc/os-release nor /usr/lib/os-release");
|
||||
return &result;
|
||||
}
|
||||
|
||||
char* line = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
// Documentation of the fields:
|
||||
// https://www.freedesktop.org/software/systemd/man/os-release.html
|
||||
while (getline(&line, &len, osRelease) != -1)
|
||||
{
|
||||
ffGetPropValue(line, "NAME =", &result.name);
|
||||
ffGetPropValue(line, "PRETTY_NAME =", &result.prettyName);
|
||||
ffGetPropValue(line, "ID =", &result.id);
|
||||
ffGetPropValue(line, "ID_LIKE =", &result.idLike);
|
||||
ffGetPropValue(line, "VARIANT =", &result.variant);
|
||||
ffGetPropValue(line, "VARIANT_ID =", &result.variantID);
|
||||
ffGetPropValue(line, "VERSION =", &result.version);
|
||||
ffGetPropValue(line, "VERSION_ID =", &result.versionID);
|
||||
ffGetPropValue(line, "VERSION_CODENAME =", &result.codename);
|
||||
ffGetPropValue(line, "BUILD_ID =", &result.buildID);
|
||||
}
|
||||
|
||||
if(line != NULL)
|
||||
free(line);
|
||||
|
||||
fclose(osRelease);
|
||||
#else
|
||||
ffStrbufSetS(&result.name, "Android");
|
||||
ffStrbufSetS(&result.id, "android");
|
||||
ffSettingsGetAndroidProperty("ro.build.version.release", &result.versionID);
|
||||
ffSettingsGetAndroidProperty("ro.build.version.release", &result.version);
|
||||
ffSettingsGetAndroidProperty("ro.build.version.codename", &result.codename);
|
||||
ffSettingsGetAndroidProperty("ro.build.id", &result.buildID);
|
||||
#endif
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return &result;
|
||||
}
|
||||
|
||||
void ffPrintOS(FFinstance* instance)
|
||||
{
|
||||
if(ffPrintFromCache(instance, FF_OS_MODULE_NAME, &instance->config.osKey, &instance->config.osFormat, FF_OS_NUM_FORMAT_ARGS))
|
||||
|
||||
Reference in New Issue
Block a user