Stormfetch can now read config files in the directory specified with the Makefile SYSCONFDIR variable

This commit is contained in:
capcreepergr 2024-06-20 14:17:28 +03:00
parent 7c493dc9f9
commit 8c380dbec4
4 changed files with 13 additions and 11 deletions

View File

@ -13,7 +13,7 @@ endif
build: build:
mkdir -p build mkdir -p build
$(GO) build -ldflags "-w" -o build/stormfetch stormfetch $(GO) build -ldflags "-w -X 'main.systemConfigDir=$(SYSCONFDIR)'" -o build/stormfetch stormfetch
install: build/stormfetch config/ install: build/stormfetch config/
mkdir -p $(DESTDIR)$(BINDIR) mkdir -p $(DESTDIR)$(BINDIR)

View File

@ -20,7 +20,7 @@ Stormfetch is still in beta, so distro compatibility is limited. If you would li
- Download `make` from your package manager - Download `make` from your package manager
- Run the following command to compile the project - Run the following command to compile the project
``` ```
make make SYSCONFDIR=/etc
``` ```
- Run the following command to install stormfetch into your system. You may also append a DESTDIR variable at the end of this line if you wish to install in a different location - Run the following command to install stormfetch into your system. You may also append a DESTDIR variable at the end of this line if you wish to install in a different location
``` ```

20
main.go
View File

@ -13,6 +13,8 @@ import (
"strings" "strings"
) )
var systemConfigDir = "/etc/"
var configPath = "" var configPath = ""
var fetchScriptPath = "" var fetchScriptPath = ""
@ -46,12 +48,12 @@ func main() {
func readConfig() { func readConfig() {
// Get home directory // Get home directory
configDir, _ := os.UserConfigDir() userConfigDir, _ := os.UserConfigDir()
// Find valid config directory // Find valid config directory
if _, err := os.Stat(path.Join(configDir, "stormfetch/config.yaml")); err == nil { if _, err := os.Stat(path.Join(userConfigDir, "stormfetch/config.yaml")); err == nil {
configPath = path.Join(configDir, "stormfetch/config.yaml") configPath = path.Join(userConfigDir, "stormfetch/config.yaml")
} else if _, err := os.Stat("/etc/stormfetch/config.yaml"); err == nil { } else if _, err := os.Stat(path.Join(systemConfigDir, "stormfetch/config.yaml")); err == nil {
configPath = "/etc/stormfetch/config.yaml" configPath = path.Join(systemConfigDir, "stormfetch/config.yaml")
} else { } else {
log.Fatalf("Config file not found: %s", err.Error()) log.Fatalf("Config file not found: %s", err.Error())
} }
@ -74,10 +76,10 @@ func readConfig() {
log.Fatalf("Fetch script path points to a directory") log.Fatalf("Fetch script path points to a directory")
} }
} }
if _, err := os.Stat(path.Join(configDir, "stormfetch/fetch_script.sh")); err == nil { if _, err := os.Stat(path.Join(userConfigDir, "stormfetch/fetch_script.sh")); err == nil {
fetchScriptPath = path.Join(configDir, "stormfetch/fetch_script.sh") fetchScriptPath = path.Join(userConfigDir, "stormfetch/fetch_script.sh")
} else if _, err := os.Stat("/etc/stormfetch/fetch_script.sh"); err == nil { } else if _, err := os.Stat(path.Join(systemConfigDir, "stormfetch/fetch_script.sh")); err == nil {
fetchScriptPath = "/etc/stormfetch/fetch_script.sh" fetchScriptPath = path.Join(systemConfigDir, "stormfetch/fetch_script.sh")
} else { } else {
log.Fatalf("Fetch script file not found: %s", err.Error()) log.Fatalf("Fetch script file not found: %s", err.Error())
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 163 KiB

After

Width:  |  Height:  |  Size: 121 KiB