From 674107915225dc1905f45ef3d5d42c9666aa92df Mon Sep 17 00:00:00 2001 From: vilmibm Date: Fri, 3 Mar 2023 21:39:36 +0000 Subject: [PATCH] call adduser, usermod --- cmd/welcome/main.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/welcome/main.go b/cmd/welcome/main.go index 4b61ffc..84f1ef9 100644 --- a/cmd/welcome/main.go +++ b/cmd/welcome/main.go @@ -5,6 +5,7 @@ import ( "fmt" "net/mail" "os" + "os/exec" "regexp" "strings" @@ -260,9 +261,19 @@ Your invite code has not been marked as used and you're welcome to try again, th return nil } -func createUser(data newUserData) error { - // TODO adduser - // TODO add to town group +// TODO add logging like the signup tool has + +func createUser(data newUserData) (err error) { + cmd := exec.Command("sudo", "/usr/sbin/adduser", "--quiet", "--disabled-password", data.Username) + if err = cmd.Run(); err != nil { + return fmt.Errorf("adduser failed: %w", err) + } + + cmd = exec.Command("sudo", "/usr/sbin/usermod", "-a", "-G", "town", data.Username) + if err = cmd.Run(); err != nil { + return fmt.Errorf("usermod failed: %w", err) + } + // TODO create keyfile by running helper (helper should also make ~/.ssh) // TODO generate welcome gift // TODO any alerts