Stormfetch can now read config files in the directory specified with the Makefile SYSCONFDIR variable
This commit is contained in:
parent
7c493dc9f9
commit
8c380dbec4
2
Makefile
2
Makefile
@ -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)
|
||||||
|
@ -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
20
main.go
@ -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 |
Loading…
x
Reference in New Issue
Block a user