Browse files

Make ensure(present, #user{}) actually depend on existence of the gro…

…up referenced (either gid or group name)

if group is specified at all
  • Loading branch information...
1 parent f38578e commit 64c564888c57b67b3490bc222ee65b7f4d248052 Yurii Rashkovskii committed Feb 23, 2012
Showing with 24 additions and 5 deletions.
  1. +24 −5 apps/htoad/src/htoad_users.erl
View
29 apps/htoad/src/htoad_users.erl
@@ -6,7 +6,8 @@
-include_lib("kernel/include/file.hrl").
-rules([init, etc_passwd, etc_group,
- ensure_user_present, ensure_user_absent,
+ ensure_user_present_with_group, ensure_user_present_with_gid, ensure_user_present_without_group,
+ ensure_user_absent,
ensure_group_present, ensure_group_absent]).
init(Engine, #init{}) ->
@@ -66,10 +67,28 @@ ensure_user_absent(Engine,
})
]).
-ensure_user_present(Engine,
- #file{ path = "/usr/sbin/useradd", content = dontread },
- {ensure, present, #user{ name = Name } = User},
- {operating_system_name, linux}) ->
+ensure_user_present_with_group(Engine,
+ {ensure, present, #user{ group = Group } = User},
+ {operating_system_name, linux},
+ #file{ path = "/usr/sbin/useradd", content = dontread },
+ #group{ name = Group }) ->
+ ensure_user_present(Engine, User).
+
+ensure_user_present_with_gid(Engine,
+ {ensure, present, #user{ group = Group } = User},
+ {operating_system_name, linux},
+ #file{ path = "/usr/sbin/useradd", content = dontread },
+ #group{ gid = Group }) ->
+ ensure_user_present(Engine, User).
+
+ensure_user_present_without_group(Engine,
+ {ensure, present, #user{ group = undefined } = User},
+ {operating_system_name, linux},
+ #file{ path = "/usr/sbin/useradd", content = dontread }) ->
+ ensure_user_present(Engine, User).
+
+
+ensure_user_present(Engine, #user{ name = Name } = User) ->
lager:debug("Creating user ~s",[Name]),
Options = useradd_options(User),
Command = #shell{ cmd = "/usr/sbin/useradd " ++ Options ++ " " ++ Name },

0 comments on commit 64c5648

Please sign in to comment.