@@ -82,23 +82,26 @@ func LoadUserData(ctx context.Context) ([]string, error) {
8282
8383 // Process users
8484 for _ , userEntry := range userData .Users {
85- // Create user
86- slog .InfoContext (ctx , "creating user" , "user" , userEntry .Name )
87- err = runCommand (ctx , "/usr/sbin/useradd" ,
88- "--home-dir" , userEntry .HomeDir ,
89- "--create-home" ,
90- "--comment" , userEntry .GECOS ,
91- "--uid" , userEntry .UID ,
92- "--shell" , userEntry .Shell ,
93- userEntry .Name )
94- if err != nil {
95- return nil , fmt .Errorf ("failed to create user %q: %w" , userEntry .Name , err )
96- }
97-
98- // Look up the newly created user
9985 userInfo , err := user .LookupId (userEntry .UID )
10086 if err != nil {
101- return nil , fmt .Errorf ("failed to look up newly created user %q: %w" , userEntry .Name , err )
87+ // User does not exist yet; create it.
88+ slog .InfoContext (ctx , "creating user" , "user" , userEntry .Name )
89+ err = runCommand (ctx , "/usr/sbin/useradd" ,
90+ "--home-dir" , userEntry .HomeDir ,
91+ "--create-home" ,
92+ "--comment" , userEntry .GECOS ,
93+ "--uid" , userEntry .UID ,
94+ "--shell" , userEntry .Shell ,
95+ userEntry .Name )
96+ if err != nil {
97+ return nil , fmt .Errorf ("failed to create user %q: %w" , userEntry .Name , err )
98+ }
99+ userInfo , err = user .LookupId (userEntry .UID )
100+ if err != nil {
101+ return nil , fmt .Errorf ("failed to look up newly created user %q: %w" , userEntry .Name , err )
102+ }
103+ } else {
104+ slog .InfoContext (ctx , "user already exists" , "user" , userEntry .Name )
102105 }
103106 uid , err := strconv .ParseInt (userInfo .Uid , 10 , 32 )
104107 if err != nil {
0 commit comments