diff options
author | Julien Dessaux | 2024-03-26 08:31:53 +0100 |
---|---|---|
committer | Julien Dessaux | 2024-03-26 08:31:53 +0100 |
commit | f51843f634ed37d02558ba49cda7c24764f928ac (patch) | |
tree | e8c4775268141671e5815a30f2e8976ef1a6dfc8 /stdlib/os | |
parent | chore(packages): removed useless packages list hook function and debian stdli... (diff) | |
download | gonf-f51843f634ed37d02558ba49cda7c24764f928ac.tar.gz gonf-f51843f634ed37d02558ba49cda7c24764f928ac.tar.bz2 gonf-f51843f634ed37d02558ba49cda7c24764f928ac.zip |
feat(users): implemented basic user creation promise
Diffstat (limited to '')
-rw-r--r-- | stdlib/os/linux/useradd.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/stdlib/os/linux/useradd.go b/stdlib/os/linux/useradd.go new file mode 100644 index 0000000..8dfee8b --- /dev/null +++ b/stdlib/os/linux/useradd.go @@ -0,0 +1,26 @@ +package linux + +import ( + "git.adyxax.org/adyxax/gonf/v2/pkg" + "os/exec" +) + +func Useradd(data gonf.UserData) (gonf.Status, error) { + getent := exec.Command("getent", "passwd", data.Name) + if err := getent.Run(); err == nil { + return gonf.KEPT, nil + } + args := make([]string, 0) + if data.HomeDir != "" { + args = append(args, "--home-dir="+data.HomeDir) + } + if data.System { + args = append(args, "--system") + } + args = append(args, data.Name) + cmd := exec.Command("useradd", args...) + if err := cmd.Run(); err != nil { + return gonf.BROKEN, err + } + return gonf.REPAIRED, nil +} |