Class: Specinfra::Command::Darwin::Base::User
Class Method Summary
collapse
Methods inherited from Base::User
check_belongs_to_group, check_belongs_to_primary_group, check_exists, check_has_authorized_key, check_has_uid, check_is_system_user, get_encrypted_password, get_gid, get_login_shell, get_maximum_days_between_password_change, get_minimum_days_between_password_change, get_uid, update_uid
Methods inherited from Base
create, escape
Class Method Details
.add(user, options) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/specinfra/command/darwin/base/user.rb', line 31
def add(user, options)
user_name = escape(user)
record_path = "/Users/#{user_name}"
dscl_create = "dscl . -create #{record_path}"
command = [dscl_create]
command << "#{dscl_create} UserShell #{escape(options[:shell])}" if options[:shell]
command << "#{dscl_create} UniqueID #{escape(options[:uid])}" if options[:uid]
command << "#{dscl_create} PrimaryGroupID #{escape(options[:gid])}" if options[:gid]
home_dir = if options[:home_directory]
escape(options[:home_directory])
else
record_path
end
command << "#{dscl_create} NFSHomeDirectory #{home_dir}"
command << "dscl . passwd #{record_path} #{escape(options[:password])}" if options[:password]
command << "createhomedir -b -u #{user_name}" if options[:create_home]
command.join(' && ')
end
|
.check_has_home_directory(user, path_to_home) ⇒ Object
3
4
5
|
# File 'lib/specinfra/command/darwin/base/user.rb', line 3
def check_has_home_directory(user, path_to_home)
"#{get_home_directory(user)} | grep -E '^#{escape(path_to_home)}$'"
end
|
.check_has_login_shell(user, path_to_shell) ⇒ Object
7
8
9
|
# File 'lib/specinfra/command/darwin/base/user.rb', line 7
def check_has_login_shell(user, path_to_shell)
"finger #{escape(user)} | grep -E '^Directory' | awk '{ print $4 }' | grep -E '^#{escape(path_to_shell)}$'"
end
|
.get_home_directory(user) ⇒ Object
11
12
13
|
# File 'lib/specinfra/command/darwin/base/user.rb', line 11
def get_home_directory(user)
"finger #{escape(user)} | grep -E '^Directory' | awk '{ print $2 }'"
end
|
.update_encrypted_password(user, password) ⇒ Object
23
24
25
|
# File 'lib/specinfra/command/darwin/base/user.rb', line 23
def update_encrypted_password(user, password)
"dscl . passwd /Users/#{escape(user)} #{escape(password)}"
end
|
.update_gid(user, gid) ⇒ Object
27
28
29
|
# File 'lib/specinfra/command/darwin/base/user.rb', line 27
def update_gid(user, gid)
"dscl . -create /Users/#{escape(user)} PrimaryGroupID #{escape(gid)}"
end
|
.update_home_directory(user, directory) ⇒ Object
15
16
17
|
# File 'lib/specinfra/command/darwin/base/user.rb', line 15
def update_home_directory(user, directory)
"dscl . -create /Users/#{escape(user)} NFSHomeDirectory #{escape(directory)}"
end
|
.update_login_shell(user, shell) ⇒ Object
19
20
21
|
# File 'lib/specinfra/command/darwin/base/user.rb', line 19
def update_login_shell(user, shell)
"dscl . -create /Users/#{escape(user)} UserShell #{escape(shell)}"
end
|