Module: LoomExt::CoreMods::User::Actions

Defined in:
lib/loomext/coremods/user.rb

Instance Method Summary collapse

Instance Method Details

#add(user, home_dir: nil, login_shell: "/bin/bash", uid: nil, gid: nil, groups: [], is_system_user: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/loomext/coremods/user.rb', line 27

def add(user,
        home_dir: nil,
        login_shell: "/bin/bash",
        uid: nil,
        gid: nil,
        groups: [],
        is_system_user: nil)
  if user_exists? user
    Loom.log.warn "add_user skipping existing user => #{user}"
    return
  end

  flags = []
  flags << ["--home-dir", home_dir] if home_dir
  flags << ["--create-home"] if home_dir
  flags << ["--shell", ] if 
  flags << ["--uid", uid] if uid
  flags << ["--gid", gid] if gid
  flags << ["--groups", groups] unless groups.empty?
  flags << "--system" if is_system_user

  loom.exec :useradd, flags, user
end

#add_system_user(user, **user_fields) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/loomext/coremods/user.rb', line 51

def add_system_user(user, **user_fields)
  if user_exists? user
    Loom.log.warn "add_system_user skipping existing user => #{user}"
    return
  end

  add user, is_system_user: true, login_shell: "/bin/false", **user_fields
end

#make_sudoer(user) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/loomext/coremods/user.rb', line 69

def make_sudoer(user)
  raise SudoersDNotIncluded unless includes_sudoers?
  raise SudoersDNoExistError unless sudoersd_exists?

  sudoer_conf = :"#{user} ALL=(ALL) NOPASSWD:ALL"

  loom.files(LOOM_SUDOERS_FILE).append sudoer_conf
  loom.exec :chmod, "0440", LOOM_SUDOERS_FILE
end

#remove(user) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/loomext/coremods/user.rb', line 60

def remove(user)
  unless user_exists? user
    Loom.log.warn "remove_user skipping non-existant user => #{user}"
    return
  end

  loom.exec :userdel, "-r", user
end