Class: Picobox::Os::Distro

Inherits:
Object
  • Object
show all
Defined in:
lib/picobox/os/distro.rb

Class Method Summary collapse

Class Method Details

.distroObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/picobox/os/distro.rb', line 5

def distro
  case `lsb_release -ids`.strip
  when /(Ubuntu)/
    :ubuntu
  when /(Debian)/
    :debian
  when /(Fedora)/
    :fedora
  else
    :unknown
  end
end

.su(os) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/picobox/os/distro.rb', line 18

def su(os)
  su ||= if TTY::Which.exist?('sudo') && os.user != 'root'
    'sudo -E sh -c'
  elsif os.user == 'root'
    message = <<-END.gsub(/^\s+\|/, '')
      |Not a great idea to install things as root user.
      |
      |  You need to:
      |    * Install sudo and add yourself to sudoers
      |
    END
    raise StandardError, message
  else
    message = <<-END.gsub(/^\s+\|/, '')
      |This installer needs the ability to run commands as root.
      |  We are unable to find 'sudo' available to make this happen.
      |
      |  You need to:
      |    * Install sudo and add yourself to sudoers
      |
    END
    raise StandardError, message
  end
end