From ea22afd3e7336492433412d1ac771f4a1145b05f Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 13 Feb 2026 22:59:39 +0200 Subject: Go rewrite: loadbars with mage, default localhost, NOTICE - Module codeberg.org/snonux/loadbars, Go 1.25 - cmd/loadbars, internal/{app,config,collector,display,stats,constants,version} - SDL display, shell script for remote (no Perl), config/cluster support - Magefile: build, test, install, uninstall/deinstall - NOTICE for go-sdl2 attribution (BSD-3-Clause) - Default to localhost when no hosts given (no SSH) - Remove loadbars-go binary name; build as loadbars Co-authored-by: Cursor --- Magefile.go | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 Magefile.go (limited to 'Magefile.go') diff --git a/Magefile.go b/Magefile.go new file mode 100644 index 0000000..119f0b8 --- /dev/null +++ b/Magefile.go @@ -0,0 +1,96 @@ +//go:build mage + +package main + +import ( + "fmt" + "os" + "path/filepath" + + "github.com/magefile/mage/mg" + "github.com/magefile/mage/sh" +) + +const ( + binaryName = "loadbars" + shareName = "loadbars" +) + +// Default sets the default target (build). +func Default() { mg.Deps(Build) } + +// Build compiles the loadbars binary. +func Build() error { + return sh.RunV("go", "build", "-o", binaryName, "./cmd/loadbars") +} + +// Test runs the test suite. +func Test() error { + return sh.RunV("go", "test", "./...") +} + +// Install builds and installs the binary, script, and NOTICE under DESTDIR. +// Usage: DESTDIR=/tmp/install mage install (or mage install for DESTDIR empty) +func Install() error { + mg.Deps(Build) + dest := getDestDir() + binDir := filepath.Join(dest, "usr", "bin") + shareDir := filepath.Join(dest, "usr", "share", shareName) + scriptsDir := filepath.Join(shareDir, "scripts") + if err := os.MkdirAll(binDir, 0755); err != nil { + return fmt.Errorf("mkdir %s: %w", binDir, err) + } + if err := os.MkdirAll(scriptsDir, 0755); err != nil { + return fmt.Errorf("mkdir %s: %w", scriptsDir, err) + } + if err := sh.Copy(filepath.Join(binDir, binaryName), binaryName); err != nil { + return fmt.Errorf("copy binary: %w", err) + } + if err := sh.Copy(filepath.Join(scriptsDir, "loadbars-remote.sh"), "scripts/loadbars-remote.sh"); err != nil { + return fmt.Errorf("copy script: %w", err) + } + if err := sh.Copy(filepath.Join(shareDir, "NOTICE"), "NOTICE"); err != nil { + return fmt.Errorf("copy NOTICE: %w", err) + } + fmt.Printf("Installed to %s (binary: %s/usr/bin/%s)\n", dest, dest, binaryName) + return nil +} + +// Uninstall removes files installed by Install from DESTDIR. +func Uninstall() error { + return deinstall() +} + +// Deinstall is an alias for Uninstall. +func Deinstall() error { + return deinstall() +} + +func deinstall() error { + dest := getDestDir() + if dest == "" { + return fmt.Errorf("DESTDIR must be set to uninstall (e.g. DESTDIR=/tmp/install mage uninstall)") + } + paths := []string{ + filepath.Join(dest, "usr", "bin", binaryName), + filepath.Join(dest, "usr", "share", shareName, "scripts", "loadbars-remote.sh"), + filepath.Join(dest, "usr", "share", shareName, "NOTICE"), + } + for _, p := range paths { + if err := os.Remove(p); err != nil && !os.IsNotExist(err) { + return fmt.Errorf("remove %s: %w", p, err) + } + } + // Remove empty dirs + _ = os.Remove(filepath.Join(dest, "usr", "share", shareName, "scripts")) + _ = os.Remove(filepath.Join(dest, "usr", "share", shareName)) + fmt.Printf("Uninstalled from %s\n", dest) + return nil +} + +func getDestDir() string { + if d := os.Getenv("DESTDIR"); d != "" { + return filepath.Clean(d) + } + return "" +} -- cgit v1.2.3