Initial code commit

This commit is contained in:
2025-09-28 01:45:11 -04:00
parent 8661409033
commit c9ecd3251b
11 changed files with 1169 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
package main
import (
"os"
"os/exec"
"os/user"
"strconv"
"github.com/rwinkhart/go-boilerplate/front"
"github.com/rwinkhart/go-boilerplate/other"
)
func manageService(action, service string) {
cmd := exec.Command("systemctl", "daemon-reload")
err := cmd.Run()
if err != nil {
other.PrintError("Failed to perform daemon-reload", 1)
}
cmd = exec.Command("systemctl", action, service)
err = cmd.Run()
if err != nil {
other.PrintError("Failed to "+action+" "+service, 1)
}
}
func writeFile(path, data, owner string, perms os.FileMode) {
err := os.WriteFile(path, []byte(data), perms)
if err != nil {
other.PrintError("Failed to write to "+path, 1)
}
if owner != "root" {
userInfo, err := user.Lookup(owner)
if err != nil {
other.PrintError("Failed to lookup UID for "+owner, 1)
}
uid, err := strconv.Atoi(userInfo.Uid)
if err != nil {
other.PrintError("Failed to convert UID to integer", 1)
}
err = os.Chown(path, uid, uid)
if err != nil {
other.PrintError("Failed to set ownership of "+path, 1)
}
}
}
func getUsername() string {
if username == "" {
username = front.Input("Non-root username:")
}
localUsername := username
return localUsername
}