Module: GitPusshuTen::Helpers::Environment::User
- Included in:
- Environment
- Defined in:
- lib/gitpusshuten/helpers/environment/user.rb
Instance Method Summary collapse
-
#add_user! ⇒ Object
Adds a user to the remote server and sets the home directory to the path specified in the config.rb.
-
#add_user_to_sudoers! ⇒ Object
Adds the user to the sudoers file.
-
#remove_user! ⇒ Object
Removes a user from the remote server but does not remove the user’s home directory since it might contain applications.
-
#user_exists? ⇒ Boolean
Checks the remote server to see if the provided user exists.
-
#user_in_sudoers? ⇒ Boolean
Checks to see if the user is already in the sudoers file or not.
Instance Method Details
#add_user! ⇒ Object
Adds a user to the remote server and sets the home directory to the path specified in the config.rb. This is the location to where applications will be deployed
If a password is not specified in the configuration, it will prompt the user to fill one in here in the CLI.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gitpusshuten/helpers/environment/user.rb', line 42 def add_user! if c.password.nil? GitPusshuTen::Log. "What password would you like to give #{c.user.to_s.color(:yellow)}?" while @new_password.nil? new_password = ask('Fill in a password.') { |q| q.echo = false } new_password_verification = ask('Verify password.') { |q| q.echo = false } if not new_password.empty? and (new_password == new_password_verification) @new_password = new_password else if new_password.empty? GitPusshuTen::Log.error "Please provide a password." else GitPusshuTen::Log.error "Verification failed, please try again." end end end else @new_password = c.password end response = execute_as_root("useradd -m --home='#{home_dir}' -s '/bin/bash' --password='" + %x[openssl passwd #{@new_password}].chomp + "' '#{c.user}'") return true if response.nil? or response =~ /useradd\: warning\: the home directory already exists\./ false end |
#add_user_to_sudoers! ⇒ Object
Adds the user to the sudoers file
17 18 19 |
# File 'lib/gitpusshuten/helpers/environment/user.rb', line 17 def add_user_to_sudoers! execute_as_root("echo '#{c.user} ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers") end |
#remove_user! ⇒ Object
Removes a user from the remote server but does not remove the user’s home directory since it might contain applications
9 10 11 12 13 |
# File 'lib/gitpusshuten/helpers/environment/user.rb', line 9 def remove_user! response = execute_as_root("userdel -f '#{c.user}'") return true if response.nil? or response =~ /userdel: user .+ is currently logged in/ false end |
#user_exists? ⇒ Boolean
Checks the remote server to see if the provided user exists
23 24 25 26 |
# File 'lib/gitpusshuten/helpers/environment/user.rb', line 23 def user_exists? return false if execute_as_root("grep '#{c.user}' /etc/passwd").nil? true end |
#user_in_sudoers? ⇒ Boolean
Checks to see if the user is already in the sudoers file or not
30 31 32 33 |
# File 'lib/gitpusshuten/helpers/environment/user.rb', line 30 def user_in_sudoers? return true if execute_as_root("cat /etc/sudoers").include?("#{c.user} ALL=(ALL) NOPASSWD: ALL") false end |