4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/danarchy_deploy/users.rb', line 4
def self.new(deployment, options)
return deployment if ! deployment[:users]
puts "\n" + self.name
(useradd_result, userdel_result, archives_result) = nil
deployment[:users].each do |username, user|
user[:username] = username.to_s
user[:home] ||= '/home/' + username.to_s
puts "\n > Checking if user '#{user[:username]}' already exists."
usercheck_result = usercheck(user, options)
if usercheck_result[:stdout]
puts " - User: #{user[:username]} already exists!"
else
group = { groupname: user[:username] }
group[:gid] = user[:gid] || nil
group[:system] = user[:system] || nil
groupcheck_result = DanarchyDeploy::Groups.groupcheck(group, options)
if !groupcheck_result[:stdout] && group[:gid]
puts " |+ Adding group: #{group[:groupname]}"
DanarchyDeploy::Groups.groupadd(group, options)
end
puts " |+ Adding user: #{user[:username]}"
useradd_result = useradd(user, options)
File.chmod(0750, user[:home]) if Dir.exist?(user[:home])
end
if !options[:pretend]
puts "\n > Checking groups for user: #{user[:username]}"
if user[:groups] && checkgroups(usercheck_result, user, options) == false
updategroups(user, options)
puts " |+ Updated groups: #{user[:groups].join(',')}"
else
puts " - No change to groups needed."
end
if user[:authorized_keys]
puts "\n > Checking on #{user[:authorized_keys].count} authorized_keys for user: #{user[:username]}"
authorized_keys(user, options)
end
if user[:sudoer]
puts "\n > Checking sudo rules for user: #{user[:username]}"
sudoer(user, options)
end
end
if user[:applications]
puts "\n > Checking #{user[:username]}'s applications."
user = DanarchyDeploy::Applicator.new(deployment[:os], user, options)
end
user.delete(:username)
end
deployment
end
|