class Specinfra::Command::Base::User
Public Class Methods
add(user, options)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 73 def add(user, options) command = ['useradd'] command << '-g' << escape(options[:gid]) if options[:gid] command << '-d' << escape(options[:home_directory]) if options[:home_directory] command << '-p' << escape(options[:password]) if options[:password] command << '-s' << escape(options[:shell]) if options[:shell] command << '-m' if options[:create_home] command << '-r' if options[:system_user] command << '-u' << escape(options[:uid]) if options[:uid] command << escape(user) command.join(' ') end
check_belongs_to_group(user, group)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 7 def check_belongs_to_group(user, group) "id #{escape(user)} | sed 's/ context=.*//g' | cut -f 4 -d '=' | grep -- #{escape(group)}" end
check_belongs_to_primary_group(user, group)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 11 def check_belongs_to_primary_group(user, group) "id -gn #{escape(user)}| grep ^#{escape(group)}$" end
check_exists(user)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 3 def check_exists(user) "id #{escape(user)}" end
check_has_home_directory(user, path_to_home)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 20 def check_has_home_directory(user, path_to_home) "getent passwd #{escape(user)} | cut -f 6 -d ':' | grep -w -- #{escape(path_to_home)}" end
check_has_login_shell(user, path_to_shell)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 24 def check_has_login_shell(user, path_to_shell) "getent passwd #{escape(user)} | cut -f 7 -d ':' | grep -w -- #{escape(path_to_shell)}" end
check_has_uid(user, uid)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 15 def check_has_uid(user, uid) regexp = "^uid=#{uid}(" "id #{escape(user)} | grep -- #{escape(regexp)}" end
get_encrypted_password(user)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 90 def get_encrypted_password(user) "getent shadow #{escape(user)} | cut -f 2 -d ':'" end
get_gid(user)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 45 def get_gid(user) "id -g #{escape(user)}" end
get_home_directory(user)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 49 def get_home_directory(user) "getent passwd #{escape(user)} | cut -f 6 -d ':'" end
get_login_shell(user)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 53 def get_login_shell(user) "getent passwd #{escape(user)} | cut -f 7 -d ':'" end
get_maximum_days_between_password_change(user)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 37 def get_maximum_days_between_password_change(user) "chage -l #{escape(user)} | sed -n 's/^Maximum.*: //p'" end
get_minimum_days_between_password_change(user)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 33 def get_minimum_days_between_password_change(user) "chage -l #{escape(user)} | sed -n 's/^Minimum.*: //p'" end
get_uid(user)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 41 def get_uid(user) "id -u #{escape(user)}" end
update_encrypted_password(user, encrypted_password)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 86 def update_encrypted_password(user, encrypted_password) %Q!echo #{escape("#{user}:#{encrypted_password}")} | chpasswd -e! end
update_gid(user, gid)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 69 def update_gid(user, gid) "usermod -g #{escape(gid)} #{escape(user)}" end
update_home_directory(user, directory)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 57 def update_home_directory(user, directory) "usermod -d #{escape(directory)} #{escape(user)}" end
update_login_shell(user, shell)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 61 def update_login_shell(user, shell) "usermod -s #{escape(shell)} #{escape(user)}" end
update_uid(user, uid)
click to toggle source
# File lib/specinfra/command/base/user.rb, line 65 def update_uid(user, uid) "usermod -u #{escape(uid)} #{escape(user)}" end