-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.rb
70 lines (59 loc) · 1.58 KB
/
user.rb
1
2
3
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
63
64
65
66
67
68
69
70
#
# Creates linux user for Rails application deployment
# Usage babushka priit:user
#
# Create own dedicated linux user and group for each app.
# Add manually missing ssh keys for all deployers.
#
dep 'user', :username, :password, :key_names do
username.ask("New app username'")
password.ask("New password")
requires 'sudo.lib'
requires 'linux_user'.with(username, password)
if key_names.nil?
requires 'ssh_all_authorized_keys'.with(username)
else
requires 'ssh_authorized_keys'.with(username, key_names)
end
requires 'zshrc'.with(username)
requires 'gemrc'.with(username)
requires 'sudoer'.with(username)
end
#
# Low level deps
#
# basic user with zsh
dep 'linux_user', :username, :password do
requires 'zsh'
requires 'group'.with(username)
met? { '/etc/passwd'.p.grep(/^#{username}:/) }
meet {
sudo "useradd --create-home --shell /bin/zsh --base-dir /home -g #{username} #{username}" and
sudo "chmod 701 /home/#{username}" and
sudo "chown #{username}:#{username} -R /home/#{username}" and
sudo %{echo "#{password}\n#{password}" | passwd #{username}}
}
end
dep 'group', :groupname do
met? { '/etc/group'.p.grep(/^#{groupname}:/) }
meet { sudo "groupadd #{groupname}" }
end
dep 'sudoer', :username do
met? do
path.p.exists?
end
meet do
filename.p.write("#{username} ALL=(ALL:ALL) ALL")
if shell "visudo -cf #{filename}"
shell "mv #{filename} #{path}"
else
puts 'Syntax error in new sudoers file'
end
end
def path
"/etc/sudoers.d/#{filename}"
end
def filename
"user-#{username}"
end
end