Class: RightScale::Platform::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/right_agent/platform/linux.rb,
lib/right_agent/platform/darwin.rb,
lib/right_agent/platform/windows.rb

Defined Under Namespace

Classes: PackageManagerNotFound, PackageNotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#outputObject

The output generated by the Installer class



444
445
446
# File 'lib/right_agent/platform/linux.rb', line 444

def output
  @output
end

Instance Method Details

#aptitude?Boolean

Does this machine have aptitude

Return

true

If aptitude is available in the expected directory

false

Otherwise

Returns:

  • (Boolean)


456
457
458
# File 'lib/right_agent/platform/linux.rb', line 456

def aptitude?
  File.executable? '/usr/bin/apt-get'
end

#install(packages) ⇒ Object

Install packages based on installed package manager

Parameters

command_name(Array)

Array of packages names to be installed

Return

true

If installations of all packages was successfull

false

Otherwise

Raises:



486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/right_agent/platform/linux.rb', line 486

def install(packages)
  return true if packages.empty?
  
  packages = packages.uniq.join(' ')
  failed_packages = []
  
  if yum?
    command = "yum install -y #{packages} 2>&1"
    regex   = /No package (.*) available\./
  elsif aptitude?
    ENV['DEBIAN_FRONTEND'] = "noninteractive"
    command = "apt-get install -y #{packages} 2>&1"
    regex = /E: Couldn't find package (.*)/
  elsif zypper?
    command = "zypper --no-gpg-checks -n #{packages} 2>&1"
    regex = /Package '(.*)' not found\./
  else
    raise PackageManagerNotFound, "No package manager binary (apt, yum, zypper) found in /usr/bin"
  end
  
  @output = `#{command}`
  @output.scan(regex) { |package| failed_packages << package.first }
  raise PackageNotFound, "The following packages were not available: #{failed_packages.join(', ')}" unless failed_packages.empty?
  return true
end

#yum?Boolean

Does this machine have yum

Return

true

If yum is available in the expected directory

false

Otherwise

Returns:

  • (Boolean)


465
466
467
# File 'lib/right_agent/platform/linux.rb', line 465

def yum?
  File.executable? '/usr/bin/yum'
end

#zypper?Boolean

Does this machine have zypper

Return

true

If zypper is available in the expected directory

false

Otherwise

Returns:

  • (Boolean)


474
475
476
# File 'lib/right_agent/platform/linux.rb', line 474

def zypper?
  File.executable? '/usr/bin/zypper'
end