From f5ecc05d62aeb253ac609c48c5baa7aac20682fd Mon Sep 17 00:00:00 2001 From: Richard Marshall Date: Fri, 6 Mar 2015 14:16:19 -0800 Subject: [PATCH] config/system: add shell user attribute This adds support for specifying the login shell of created users. --- config/config_test.go | 5 +++++ config/user.go | 1 + system/user.go | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/config/config_test.go b/config/config_test.go index 71033b7..efcdd18 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -374,6 +374,7 @@ users: no_user_group: true system: y no_log_init: True + shell: /bin/sh ` cfg, err := NewCloudConfig(contents) if err != nil { @@ -441,6 +442,10 @@ users: if !user.NoLogInit { t.Errorf("Failed to parse no_log_init field") } + + if user.Shell != "/bin/sh" { + t.Errorf("Failed to parse shell field, got %q", user.Shell) + } } func TestCloudConfigUsersGithubUser(t *testing.T) { diff --git a/config/user.go b/config/user.go index 024b6fa..e89a258 100644 --- a/config/user.go +++ b/config/user.go @@ -29,4 +29,5 @@ type User struct { NoUserGroup bool `yaml:"no_user_group"` System bool `yaml:"system"` NoLogInit bool `yaml:"no_log_init"` + Shell string `yaml:"shell"` } diff --git a/system/user.go b/system/user.go index 2f5d85d..3f973c3 100644 --- a/system/user.go +++ b/system/user.go @@ -72,6 +72,10 @@ func CreateUser(u *config.User) error { args = append(args, "--no-log-init") } + if u.Shell != "" { + args = append(args, "--shell", u.Shell) + } + args = append(args, u.Name) output, err := exec.Command("useradd", args...).CombinedOutput()