mirror of
https://github.com/EnumeratedDev/stormfetch.git
synced 2026-09-15 23:46:12 +00:00
Update Makefile and add version flag
This commit is contained in:
@@ -1,32 +1,35 @@
|
|||||||
SHELL := /bin/bash
|
# Installation paths
|
||||||
|
PREFIX ?= /usr/local
|
||||||
ifeq ($(PREFIX),)
|
BINDIR ?= $(PREFIX)/bin
|
||||||
PREFIX := /usr/local
|
|
||||||
endif
|
|
||||||
ifeq ($(BINDIR),)
|
|
||||||
BINDIR := $(PREFIX)/bin
|
|
||||||
endif
|
|
||||||
ifeq ($(SYSCONFDIR),)
|
|
||||||
SYSCONFDIR := $(PREFIX)/etc
|
SYSCONFDIR := $(PREFIX)/etc
|
||||||
endif
|
|
||||||
ifeq ($(GO),)
|
# Compilers and tools
|
||||||
GO := $(shell type -a -P go | head -n 1)
|
GO ?= go
|
||||||
endif
|
|
||||||
|
# Build-time variables
|
||||||
|
VERSION ?= $(shell git describe --tags --dirty)
|
||||||
|
|
||||||
build:
|
build:
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
cd src; $(GO) build -ldflags "-w -X 'main.systemConfigDir=$(SYSCONFDIR)'" -o ../build/stormfetch stormfetch
|
cd src; $(GO) build -ldflags "-w -X 'main.StormfetchVersion=$(VERSION)' -X 'main.SystemConfigDir=$(SYSCONFDIR)'" -o ../build/stormfetch stormfetch
|
||||||
|
|
||||||
install: build/stormfetch config/
|
install: build/stormfetch config/
|
||||||
mkdir -p $(DESTDIR)$(BINDIR)
|
# Create directoriy
|
||||||
mkdir -p $(DESTDIR)$(SYSCONFDIR)/stormfetch/
|
install -dm755 $(DESTDIR)$(BINDIR)
|
||||||
cp build/stormfetch $(DESTDIR)$(BINDIR)/stormfetch
|
# Install binary
|
||||||
cp -r config/. $(DESTDIR)$(SYSCONFDIR)/stormfetch/
|
install -m755 build/stormfetch $(DESTDIR)$(BINDIR)/stormfetch
|
||||||
|
|
||||||
run: build/stormfetch
|
install-config:
|
||||||
build/stormfetch
|
# Create directory
|
||||||
|
install -dm755 $(DESTDIR)$(SYSCONFDIR)
|
||||||
|
# Install files
|
||||||
|
cp -r config $(DESTDIR)$(SYSCONFDIR)/stormfetch/
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
-rm -f $(DESTDIR)$(BINDIR)/stormfetch
|
||||||
|
-rm -rf $(DESTDIR)$(SYSCONFDIR)/stormfetch
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -r build/
|
rm -r build/
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build install install-config uninstall clean
|
||||||
|
|||||||
+2
-2
@@ -28,8 +28,8 @@ func readConfig() {
|
|||||||
// Find valid config directory
|
// Find valid config directory
|
||||||
if _, err := os.Stat(path.Join(userConfigDir, "stormfetch/config.yaml")); err == nil {
|
if _, err := os.Stat(path.Join(userConfigDir, "stormfetch/config.yaml")); err == nil {
|
||||||
configPath = path.Join(userConfigDir, "stormfetch/config.yaml")
|
configPath = path.Join(userConfigDir, "stormfetch/config.yaml")
|
||||||
} else if _, err := os.Stat(path.Join(systemConfigDir, "stormfetch/config.yaml")); err == nil {
|
} else if _, err := os.Stat(path.Join(SystemConfigDir, "stormfetch/config.yaml")); err == nil {
|
||||||
configPath = path.Join(systemConfigDir, "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())
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-2
@@ -9,9 +9,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Build-time variables
|
// Build-time variables
|
||||||
var systemConfigDir = "/etc/"
|
var StormfetchVersion = "dev"
|
||||||
|
var SystemConfigDir = "/etc/"
|
||||||
|
|
||||||
// Flag variables
|
// Flag variables
|
||||||
|
var ShowVersion = false
|
||||||
var ShowModuleTimeTaken = false
|
var ShowModuleTimeTaken = false
|
||||||
|
|
||||||
var configPath = ""
|
var configPath = ""
|
||||||
@@ -24,13 +26,19 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseFlags() {
|
func parseFlags() {
|
||||||
|
flag.BoolVar(&ShowVersion, "version", false, "Show Stormfetch version")
|
||||||
|
flag.BoolVar(&ShowModuleTimeTaken, "time-taken", false, "Show time taken to execute each module")
|
||||||
flag.StringVar(&config.Ascii, "ascii", config.Ascii, "Set distro ascii")
|
flag.StringVar(&config.Ascii, "ascii", config.Ascii, "Set distro ascii")
|
||||||
flag.StringVar(&config.DistroName, "distro-name", config.DistroName, "Set distro name")
|
flag.StringVar(&config.DistroName, "distro-name", config.DistroName, "Set distro name")
|
||||||
flag.BoolVar(&ShowModuleTimeTaken, "time-taken", false, "Show time taken to execute each module")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
func run() {
|
func run() {
|
||||||
|
if ShowVersion {
|
||||||
|
fmt.Printf("Stormfetch version %s\n", StormfetchVersion)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch ascii art and remove header
|
// Fetch ascii art and remove header
|
||||||
asciiArt := GetDistroAsciiArt()
|
asciiArt := GetDistroAsciiArt()
|
||||||
asciiArtHeader := ""
|
asciiArtHeader := ""
|
||||||
|
|||||||
+4
-4
@@ -73,8 +73,8 @@ func GetDistroAsciiArt() string {
|
|||||||
}
|
}
|
||||||
userConfDir, err := os.UserConfigDir()
|
userConfDir, err := os.UserConfigDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, err := os.Stat(path.Join(systemConfigDir, "stormfetch/ascii/", id)); err == nil {
|
if _, err := os.Stat(path.Join(SystemConfigDir, "stormfetch/ascii/", id)); err == nil {
|
||||||
bytes, err := os.ReadFile(path.Join(systemConfigDir, "stormfetch/ascii/", id))
|
bytes, err := os.ReadFile(path.Join(SystemConfigDir, "stormfetch/ascii/", id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return defaultAscii
|
return defaultAscii
|
||||||
}
|
}
|
||||||
@@ -89,8 +89,8 @@ func GetDistroAsciiArt() string {
|
|||||||
return defaultAscii
|
return defaultAscii
|
||||||
}
|
}
|
||||||
return string(bytes)
|
return string(bytes)
|
||||||
} else if _, err := os.Stat(path.Join(systemConfigDir, "stormfetch/ascii/", id)); err == nil {
|
} else if _, err := os.Stat(path.Join(SystemConfigDir, "stormfetch/ascii/", id)); err == nil {
|
||||||
bytes, err := os.ReadFile(path.Join(systemConfigDir, "stormfetch/ascii/", id))
|
bytes, err := os.ReadFile(path.Join(SystemConfigDir, "stormfetch/ascii/", id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return defaultAscii
|
return defaultAscii
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user