Ported hivectl

This commit is contained in:
Sasha Koshka
2023-05-31 15:52:33 -04:00
parent 1a5502211e
commit 8c9b85d7ca
3 changed files with 294 additions and 0 deletions

View File

@@ -24,3 +24,14 @@ func Printf (format string, values ...any) {
func ServiceUser (service string) string {
return "hn-" + strings.ToLower(service)
}
// NeedRoot halts the program and displays an error if it is not being run as
// root. This should be called whenever an operation takes place that requires
// root privelages.
func NeedRoot() {
uid := os.Getuid()
if uid != 0 {
Sayf("this utility must be run as root")
os.Exit(1)
}
}