summaryrefslogtreecommitdiff
path: root/internal/app/script.go
blob: 2701cb2059f28f043b5ae461d1ef12635b129ebf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package app

import (
	"os"
	"path/filepath"
)

// ScriptPath returns the path to the loadbars-remote.sh script.
// It looks for scripts/loadbars-remote.sh relative to the executable, then current dir.
func ScriptPath() string {
	exe, err := os.Executable()
	if err == nil {
		dir := filepath.Dir(exe)
		// When installed: exe is /usr/bin/loadbars, script might be /usr/share/loadbars/scripts/
		for _, sub := range []string{"scripts/loadbars-remote.sh", "../scripts/loadbars-remote.sh", "../../scripts/loadbars-remote.sh"} {
			p := filepath.Join(dir, sub)
			if _, err := os.Stat(p); err == nil {
				return p
			}
		}
	}
	// Development: run from repo root
	if p, err := filepath.Abs("scripts/loadbars-remote.sh"); err == nil {
		if _, err := os.Stat(p); err == nil {
			return p
		}
	}
	return "scripts/loadbars-remote.sh"
}