mirror of
https://github.com/rwinkhart/cachyos-postinstall-helper.git
synced 2026-08-27 20:36:32 -04:00
Initial code commit
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user