package templater import ( "log" "forge.cadoles.com/pcaseiro/templatefile/pkg/utils" ) type SystemUser struct { UserName string `json:"username"` Group string `json:"group"` Home string `json:"home"` Shell string `json:"shell"` } func (su *SystemUser) exists() (bool, error) { _, _, err := utils.RunSystemCommand("getent", "passwd", su.UserName) if err != nil { return false, err } return true, nil } func (su *SystemUser) Manage() error { exist, _ := su.exists() if exist { log.Printf("\tUser %s already exists", su.UserName) return nil } return su.Create() } func (su *SystemUser) Create() error { _, _, err := utils.RunSystemCommand("useradd", "-b", su.Home, "-m", "-G", su.Group, su.UserName) if err != nil { return err } return nil } func (su *SystemUser) Delete() error { _, _, err := utils.RunSystemCommand("userdel", su.UserName) if err != nil { return err } return nil } func (su *SystemUser) Update() error { return nil }