class Specinfra::Command::Darwin::Base::User
Public Class Methods
add(user, options)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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