From 15b85bd9e99de299b9826e4919d51a6cac3ea62b Mon Sep 17 00:00:00 2001 From: Fletcher Nichol Date: Mon, 18 Feb 2013 13:57:31 -0700 Subject: [PATCH] Install Omnibus if require_chef_omnibus version differs from current. This will allow a user to upgrade or downgrade their Omnibus package version to match the version string in require_chef_omnibus. If the version string matches what is currently installed, the installation is skipped. **Note** This commit also supports a value of `"latest"` for require_chef_omnibus which drops the version flag when calling the omnibus installation script. Since calculating the lastest Chef release is nontrivial, the Omnibus installer will be called on every converge when `"latest"` is set--whether Chef is installed or not. Closes #32 --- lib/kitchen/driver/ssh_base.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/kitchen/driver/ssh_base.rb b/lib/kitchen/driver/ssh_base.rb index d0517f696..90dd7c52d 100644 --- a/lib/kitchen/driver/ssh_base.rb +++ b/lib/kitchen/driver/ssh_base.rb @@ -91,11 +91,23 @@ def chef_home end def install_omnibus(ssh_args) - flag = config[:require_chef_omnibus] - version = flag.is_a?(String) ? "-s -- -v #{flag}" : "" + flag = config[:require_chef_omnibus].downcase + version = if flag.is_a?(String) && flag != "latest" + "-s -- -v #{flag}" + else + "" + end ssh(ssh_args, <<-INSTALL.gsub(/^ {10}/, '')) - if [ ! -d "/opt/chef" ] ; then + should_update_chef() { + case "#{flag}" in + $(chef-solo --v | awk '{print $2}')) return 1 ;; + latest|*) return 0 ;; + esac + } + + if [ ! -d "/opt/chef" ] || should_update_chef ; then + echo '-----> Installing Chef Omnibus (#{flag})' curl -sSL https://www.opscode.com/chef/install.sh \ | sudo bash #{version} fi