summaryrefslogtreecommitdiff
path: root/Magefile.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-13 22:59:39 +0200
committerPaul Buetow <paul@buetow.org>2026-02-13 22:59:39 +0200
commitea22afd3e7336492433412d1ac771f4a1145b05f (patch)
treeaba2cd0730c2a79ae1081d512b76ad023295aa3a /Magefile.go
parentcd5a3614baab756a41d764b79308afeea93f12dd (diff)
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 <cursoragent@cursor.com>
Diffstat (limited to 'Magefile.go')
-rw-r--r--Magefile.go96
1 files changed, 96 insertions, 0 deletions
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 ""
+}