Method: Specinfra::Command::Darwin::Base::User.add

Defined in:
lib/specinfra/command/darwin/base/user.rb

.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