lib/rconf/support/package_installer.rb in rconf-0.6.25 vs lib/rconf/support/package_installer.rb in rconf-0.6.30

- old
+ new

@@ -22,17 +22,33 @@ # 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) + def install(packages, opts=nil, &install_check) packages = [ packages ].flatten report = opts && opts.delete(:report) - report_check("Installing the following packages:\n#{packages.join(' ')}\nThis could take a while") if report - Platform.dispatch(packages, opts) { :install } - report_success if 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