Skip to content

Commit

Permalink
Merge pull request #111 from socrata-cookbooks/fix_alternatives_for_c…
Browse files Browse the repository at this point in the history
…entos

Fix alternatives for centos
  • Loading branch information
carmstrong committed Jan 5, 2014
2 parents 5790f08 + 7c244fc commit e6f82c3
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions providers/alternatives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

action :set do
if new_resource.bin_cmds
# I couldn't find a way to cleanly avoid repeating this variable declaration in both :set and :unset
alternatives_cmd = node['platform_family'] == 'rhel' ? 'alternatives' : 'update-alternatives'
new_resource.bin_cmds.each do |cmd|

bin_path = "/usr/bin/#{cmd}"
Expand All @@ -31,12 +33,12 @@
end

# install the alternative if needed
alternative_exists = shell_out("update-alternatives --display #{cmd} | grep #{alt_path}").exitstatus == 0
alternative_exists = shell_out("#{alternatives_cmd} --display #{cmd} | grep #{alt_path}").exitstatus == 0
unless alternative_exists
description = "Add alternative for #{cmd}"
converge_by(description) do
Chef::Log.debug "Adding alternative for #{cmd}"
install_cmd = shell_out("update-alternatives --install #{bin_path} #{cmd} #{alt_path} #{priority}")
install_cmd = shell_out("#{alternatives_cmd} --install #{bin_path} #{cmd} #{alt_path} #{priority}")
unless install_cmd.exitstatus == 0
Chef::Application.fatal!(%Q[ set alternative failed ])
end
Expand All @@ -46,12 +48,12 @@

# set the alternative if default
if new_resource.default
alternative_is_set = shell_out("update-alternatives --display #{cmd} | grep \"link currently points to #{alt_path}\"").exitstatus == 0
alternative_is_set = shell_out("#{alternatives_cmd} --display #{cmd} | grep \"link currently points to #{alt_path}\"").exitstatus == 0
unless alternative_is_set
description = "Set alternative for #{cmd}"
converge_by(description) do
Chef::Log.debug "Setting alternative for #{cmd}"
set_cmd = shell_out("update-alternatives --set #{cmd} #{alt_path}")
set_cmd = shell_out("#{alternatives_cmd} --set #{cmd} #{alt_path}")
unless set_cmd.exitstatus == 0
Chef::Application.fatal!(%Q[ set alternative failed ])
end
Expand All @@ -64,9 +66,11 @@
end

action :unset do
# I couldn't find a way to cleanly avoid repeating this variable declaration in both :set and :unset
alternatives_cmd = node['platform_family'] == 'rhel' ? 'alternatives' : 'update-alternatives'
new_resource.bin_cmds.each do |cmd|
alt_path = "#{new_resource.java_location}/bin/#{cmd}"
cmd = shell_out("update-alternatives --remove #{cmd} #{alt_path}")
cmd = shell_out("#{alternatives_cmd} --remove #{cmd} #{alt_path}")
if cmd.exitstatus == 0
new_resource.updated_by_last_action(true)
end
Expand Down

0 comments on commit e6f82c3

Please sign in to comment.