# Copyright (C) 2011-2012 RightScale, Inc, All Rights Reserved Worldwide. # # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use, # reproduction, modification, or disclosure of this program is # strictly prohibited. Any use of this program by an authorized # licensee is strictly subject to the terms and conditions, # including confidentiality obligations, set forth in the applicable # License Agreement between RightScale.com, Inc. and # the licensee module RightConf class PackageInstaller include Singleton include ProgressReporter # Install given packages # # === Parameters # packages(String|Array):: Package name or Packages list # opts[:abort_on_failure](String):: Optional, abort configuration # and display given error message if install fails when set # opts[:report](TrueClass|FalseClass):: Whether to report installation # # === Block # If a block is given it will get called with no argument prior to the # packages being installed. If the block returns true then installation # will proceed otherwise it won't. Use the block to check whether # installation is required or whether the packages are already installed. # If no block is given then installation will always occur. # # === Return # true:: Always return true def install(packages, opts=nil, &install_check) packages = [ packages ].flatten.compact return true if packages.empty? report = opts && opts.delete(:report) must_install = true if install_check report_check("Checking for #{packages.join(', ')}") if report must_install = install_check.call report_result(must_install) if report end if must_install report_check("Installing #{packages.join(', ')}") if report Platform.dispatch(packages, opts) { :install } report_success if report end true end protected # Install debian packages # # === Return # true:: Always return true def install_linux_ubuntu(packages, opts) return if packages.nil? args = packages.dup args << opts if opts Command.sudo('apt-get', 'install', '-y', *args) end alias :install_linux_debian :install_linux_ubuntu # Install yum packages # # === Return # true:: Always return true def install_linux_centos(packages, opts) return if packages.nil? args = packages.dup args << opts if opts Command.sudo('yum', 'install', '-y', *args) end alias :install_linux_redhat :install_linux_centos # Use brew on Mac OS X # # === Return # true:: Always return true def install_darwin(packages, opts) return if packages.nil? BrewInstaller.check_and_install packages.each do |p| args = [ p ] args << opts if opts res = Command.execute('brew', 'install', *args) installed = res.success? && res.output !~ /Formula already installed/ Command.sudo('brew', 'link', p) if installed end end # Install Windows software # # === Return # true:: Always return true def install_windows(packages, opts) # TBD end end end