Module: Pointer::RailsUser

Included in:
EasyDeploy
Defined in:
lib/pointer/rails_user.rb

Instance Method Summary collapse

Instance Method Details

#add_sudoObject



30
31
32
33
# File 'lib/pointer/rails_user.rb', line 30

def add_sudo
  sudo_string = "rails ALL = NOPASSWD:ALL"
  ensure_file_contains('/etc/sudoers', sudo_string)
end

#create_rails_userObject



7
8
9
10
11
12
13
14
15
# File 'lib/pointer/rails_user.rb', line 7

def create_rails_user
  if @ssh.exec!("id rails") =~ /No such user/
    expect_empty @ssh.exec!("useradd rails -d /home/#{rails_user} -m -s /bin/bash")
    expect_empty @ssh.exec!("usermod -a -G sudo rails")
    what "User created: rails"
  else
    what "User exists: rails"
  end
end

#delete_rails_userObject



3
4
5
# File 'lib/pointer/rails_user.rb', line 3

def delete_rails_user
  puts @ssh.exec!("userdel rails -f -r")
end


39
40
41
42
43
44
45
# File 'lib/pointer/rails_user.rb', line 39

def print_deploy_key
  id_rsa = '/home/rails/.ssh/id_rsa'
  if file_absent(id_rsa)
    what "Generating ssh key"
    puts @ssh.exec!("ssh-keygen -q -t rsa -f #{id_rsa} -N ''")
  end
end

#revoke_sudoObject



35
36
37
# File 'lib/pointer/rails_user.rb', line 35

def revoke_sudo
  puts "revoke_sudo is not implemented"
end

#upload_public_keyObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pointer/rails_user.rb', line 17

def upload_public_key
  ssh_dir = "/home/#{rails_user}/.ssh"
  authorized_keys_file = ssh_dir + '/authorized_keys'

  what "Uploading private key"
  @ssh.exec!("mkdir #{ssh_dir}")
  ensure_file_contains(authorized_keys_file, IO.read(File.expand_path(public_key)))
  expect_empty @ssh.exec!("chown rails:rails #{ssh_dir}")
  expect_empty @ssh.exec!("chown rails:rails #{authorized_keys_file}")
  expect_empty @ssh.exec!("chmod 0700 #{ssh_dir}")
  expect_empty @ssh.exec!("chmod 0600 #{authorized_keys_file}")
end