Class: SysAdminToolbox::System::Setup

Inherits:
Object
  • Object
show all
Includes:
IO::System, IO::User
Defined in:
lib/SysAdminToolbox/system/setup.rb

Instance Method Summary collapse

Methods included from IO::User

#password

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/SysAdminToolbox/system/setup.rb', line 10

def run
  SysAdminToolbox::App.clear_console

  puts "Welcome to initial system setup!"
  puts "This should only be performed on new (virgin) systems"
  puts
  SysAdminToolbox::App.quit if ask("Are you ready to start? (anything but 'yes' will cancel) ").downcase.strip != 'yes'


  # Root user
  puts "\nSecuring root account"
  begin
    root_password = password "Root Password: "
    raise RetryableError, 'Root password must be 8-20 charecters long!' if !root_password.length.between?(8,20)

    root_password2 = password "(again) "
    raise RetryableError, 'Passwords do not match!' if root_password != root_password2


    p = Open4::popen4("passwd --stdin root") do |pid, stdin, stdout, stderr|
      stdin.puts root_password
      stdin.close
    end
    raise SystemCallError, 'Failed to change root password!' if p.exitstatus

  rescue RetryableError => e
    puts "\n"+e.message
    retry
  rescue => e
    puts "\n"+e.message
    SysAdminToolbox::App.quit
  end
end