class Uberinstaller::Platform

stackoverflow.com/questions/170956/how-can-i-find-which-operating-system-my-ruby-program-is-running-on

Attributes

architecture[R]

@!attribute [r] architecture

OS architecture information

@!attribute [r] lsb

LSB module information

@!attribute [r] uname

`uname` calls results
lsb[R]

@!attribute [r] architecture

OS architecture information

@!attribute [r] lsb

LSB module information

@!attribute [r] uname

`uname` calls results
uname[R]

@!attribute [r] architecture

OS architecture information

@!attribute [r] lsb

LSB module information

@!attribute [r] uname

`uname` calls results

Public Class Methods

new(opts = {}) click to toggle source

Get platform, detect ubuntu, detect ubuntu version, save lsb params

@param opts [Hash]

:lsb => the file containing LSB information
# File lib/uberinstaller/platform.rb, line 23
def initialize(opts = {})
  @opts = opts.keyword_args(:lsb => '/etc/lsb-release')
  
  @lsb = nil
  @uname = nil
  
  get_lsb_informations
  get_arch_informations

  @architecture = @uname[:machine]
end

Public Instance Methods

is_32bit?() click to toggle source

Reverse of is_64bit?

# File lib/uberinstaller/platform.rb, line 48
def is_32bit?
  !is_64bit?
end
is_64bit?() click to toggle source

Check if system is running 64 bit OS

# File lib/uberinstaller/platform.rb, line 53
def is_64bit?
  return @uname[:machine] == 'x86_64' if @uname[:machine]
  logger.fatal 'uname is not set, impossible to get machine information'
  false
end
is_not_ubuntu?() click to toggle source

Reverse of is_ubuntu?

# File lib/uberinstaller/platform.rb, line 43
def is_not_ubuntu?
  !is_ubuntu?
end
is_ubuntu?() click to toggle source

Check if platform is Ubuntu

# File lib/uberinstaller/platform.rb, line 36
def is_ubuntu?
  return @lsb[:id] == 'Ubuntu' if @lsb[:id]
  logger.fatal 'lsb is not set, impossible to get OS information'
  false
end

Private Instance Methods

get_arch_informations() click to toggle source

Detect OS architecture information

Using a call to `uname` try to detect architecture informations. `uname` must be available on the system

# File lib/uberinstaller/platform.rb, line 64
def get_arch_informations
  @uname ||= Hash.new
  IO.popen 'uname -m' do |io| @uname[:machine] = io.read.strip end
  IO.popen 'uname -n' do |io| @uname[:host] = io.read.strip end
  IO.popen 'uname -srv' do |io| @uname[:kernel] = io.read.strip end
end
get_lsb_informations() click to toggle source

Get OS information from LSB

LSB must be aavailable on the system

# File lib/uberinstaller/platform.rb, line 74
def get_lsb_informations
  # http://stackoverflow.com/a/1236075/715002
  IO.popen "cat #{@opts.lsb}" do |io|
    io.each do |line|
      unless line.include? 'cat:' # check for error
        @lsb ||= Hash.new

        if line.include? 'DISTRIB_ID'
          @lsb[:id] = get_lsb_value line
        elsif line.include? 'DISTRIB_RELEASE'
          @lsb[:release] = get_lsb_value line
        elsif line.include? 'DISTRIB_CODENAME'
          @lsb[:codename] = get_lsb_value line
        elsif line.include? 'DISTRIB_DESCRIPTION'
          @lsb[:description] = get_lsb_value line
        end
      else
        logger.fatal "Platform has no #{@opts.lsb}, so it is not supported"
      end
    end
  end
end
get_lsb_value(string) click to toggle source

Handy method to retrieve values from LSB pairs

# File lib/uberinstaller/platform.rb, line 98
def get_lsb_value(string)
  string.split('=')[1].strip
end