fix pc install

This commit is contained in:
Puechberty Arthur
2026-06-26 22:20:46 +02:00
parent db3e904b89
commit 64eb0b165d
2 changed files with 25 additions and 41 deletions
-2
View File
@@ -13,8 +13,6 @@ install: $(TARGET)
cp $(TARGET) $(DESTDIR)/usr/bin/ cp $(TARGET) $(DESTDIR)/usr/bin/
mkdir -p $(DESTDIR)/usr/share/optifetch/logos mkdir -p $(DESTDIR)/usr/share/optifetch/logos
cp -r logos/*.txt $(DESTDIR)/usr/share/optifetch/logos/ 2>/dev/null || true cp -r logos/*.txt $(DESTDIR)/usr/share/optifetch/logos/ 2>/dev/null || true
mkdir -p $(DESTDIR)/etc
cp optifetch.conf $(DESTDIR)/etc/optifetch.conf 2>/dev/null || touch $(DESTDIR)/etc/optifetch.conf
uninstall: uninstall:
rm -f $(DESTDIR)/usr/bin/$(TARGET) rm -f $(DESTDIR)/usr/bin/$(TARGET)
+25 -39
View File
@@ -1,8 +1,7 @@
#include "optifetch.h" #include "optifetch.h"
#include <sys/stat.h> // Nécessaire pour mkdir() #include <sys/stat.h> // Pour mkdir()
void print_help() void print_help() {
{
printf("Optifetch - Lightweight system info tool\n\n"); printf("Optifetch - Lightweight system info tool\n\n");
printf("Usage: optifetch [options]\n\n"); printf("Usage: optifetch [options]\n\n");
printf("Options:\n"); printf("Options:\n");
@@ -11,9 +10,9 @@ void print_help()
printf("Configuration:\n"); printf("Configuration:\n");
printf(" Config file is searched in:\n"); printf(" Config file is searched in:\n");
printf(" 1. ./optifetch.conf\n"); printf(" 1. ./optifetch.conf\n");
printf(" 2. ~/.config/optifetch.conf\n"); printf(" 2. ~/.config/optifetch/optifetch.conf\n");
printf(" 3. /etc/optifetch.conf\n"); printf(" 3. /etc/optifetch.conf\n");
printf(" It is generated on first run if not found.\n\n"); printf(" It is generated on first run in ~/.config/optifetch/ if not found.\n\n");
printf("Available Variables:\n"); printf("Available Variables:\n");
printf(" {logo} {small_logo} {distro_color} {user} {host} {os} {kernel} {uptime} {arch}\n"); printf(" {logo} {small_logo} {distro_color} {user} {host} {os} {kernel} {uptime} {arch}\n");
printf(" {shell} {cpu} {cores} {cpu_max_freq} {gpu} {de} {wm} {term}\n"); printf(" {shell} {cpu} {cores} {cpu_max_freq} {gpu} {de} {wm} {term}\n");
@@ -38,10 +37,8 @@ void print_help()
printf(" {if:wifi} ... {endif} Show only if connected to wifi\n"); printf(" {if:wifi} ... {endif} Show only if connected to wifi\n");
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[]) {
{ if (argc > 1 && (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0)) {
if (argc > 1 && (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0))
{
print_help(); print_help();
return 0; return 0;
} }
@@ -53,52 +50,41 @@ int main(int argc, char *argv[])
int config_found = 0; int config_found = 0;
// 1. Cherche dans le dossier local // 1. Cherche dans le dossier local
if (access(config_path, F_OK) == 0) if (access(config_path, F_OK) == 0) {
{
config_found = 1; config_found = 1;
} }
// 2. Cherche dans ~/.config/optifetch.conf // 2. Cherche dans ~/.config/optifetch/optifetch.conf
if (!config_found) if (!config_found) {
{
const char *home = getenv("HOME"); const char *home = getenv("HOME");
if (home) if (home) {
{ snprintf(config_path, sizeof(config_path), "%s/.config/optifetch/optifetch.conf", home);
snprintf(config_path, sizeof(config_path), "%s/.config/optifetch.conf", home); if (access(config_path, F_OK) == 0) {
if (access(config_path, F_OK) == 0)
{
config_found = 1; config_found = 1;
} }
} }
} }
// 3. Cherche dans /etc/optifetch.conf // 3. Cherche dans /etc/optifetch.conf (si un admin l'a mis)
if (!config_found) if (!config_found) {
{
snprintf(config_path, sizeof(config_path), "/etc/optifetch.conf"); snprintf(config_path, sizeof(config_path), "/etc/optifetch.conf");
if (access(config_path, F_OK) == 0) if (access(config_path, F_OK) == 0) {
{
config_found = 1; config_found = 1;
} }
} }
// 4. Si toujours pas trouvé, on le génère // 4. Si toujours pas trouvé, on le génère dans ~/.config/optifetch/
if (!config_found) if (!config_found) {
{
const char *home = getenv("HOME"); const char *home = getenv("HOME");
if (home) if (home) {
{
// S'assurer que le dossier ~/.config existe bien avant de créer le fichier
char config_dir[512]; char config_dir[512];
snprintf(config_dir, sizeof(config_dir), "%s/.config", home); snprintf(config_dir, sizeof(config_dir), "%s/.config/optifetch", home);
mkdir(config_dir, 0755); // Crée le dossier (s'il existe déjà, ne fait rien) mkdir(config_dir, 0755); // Crée le dossier ~/.config/optifetch
snprintf(config_path, sizeof(config_path), "%s/.config/optifetch.conf", home); snprintf(config_path, sizeof(config_path), "%s/.config/optifetch/optifetch.conf", home);
generate_default_config(config_path); generate_default_config(config_path);
} } else {
else // Fallback si pas de HOME
{
// Si pas de HOME (ex: environnement très restreint), on crée dans le dossier courant
snprintf(config_path, sizeof(config_path), "optifetch.conf"); snprintf(config_path, sizeof(config_path), "optifetch.conf");
generate_default_config(config_path); generate_default_config(config_path);
} }
@@ -106,7 +92,7 @@ int main(int argc, char *argv[])
} }
render_config(config_path, &info); render_config(config_path, &info);
printf("\033[0m"); printf("\033[0m");
return 0; return 0;
} }