Skip to content

Commit e6f82c3

Browse files
committed
Merge pull request #111 from socrata-cookbooks/fix_alternatives_for_centos
Fix alternatives for centos
2 parents 5790f08 + 7c244fc commit e6f82c3

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

providers/alternatives.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

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

2426
bin_path = "/usr/bin/#{cmd}"
@@ -31,12 +33,12 @@
3133
end
3234

3335
# install the alternative if needed
34-
alternative_exists = shell_out("update-alternatives --display #{cmd} | grep #{alt_path}").exitstatus == 0
36+
alternative_exists = shell_out("#{alternatives_cmd} --display #{cmd} | grep #{alt_path}").exitstatus == 0
3537
unless alternative_exists
3638
description = "Add alternative for #{cmd}"
3739
converge_by(description) do
3840
Chef::Log.debug "Adding alternative for #{cmd}"
39-
install_cmd = shell_out("update-alternatives --install #{bin_path} #{cmd} #{alt_path} #{priority}")
41+
install_cmd = shell_out("#{alternatives_cmd} --install #{bin_path} #{cmd} #{alt_path} #{priority}")
4042
unless install_cmd.exitstatus == 0
4143
Chef::Application.fatal!(%Q[ set alternative failed ])
4244
end
@@ -46,12 +48,12 @@
4648

4749
# set the alternative if default
4850
if new_resource.default
49-
alternative_is_set = shell_out("update-alternatives --display #{cmd} | grep \"link currently points to #{alt_path}\"").exitstatus == 0
51+
alternative_is_set = shell_out("#{alternatives_cmd} --display #{cmd} | grep \"link currently points to #{alt_path}\"").exitstatus == 0
5052
unless alternative_is_set
5153
description = "Set alternative for #{cmd}"
5254
converge_by(description) do
5355
Chef::Log.debug "Setting alternative for #{cmd}"
54-
set_cmd = shell_out("update-alternatives --set #{cmd} #{alt_path}")
56+
set_cmd = shell_out("#{alternatives_cmd} --set #{cmd} #{alt_path}")
5557
unless set_cmd.exitstatus == 0
5658
Chef::Application.fatal!(%Q[ set alternative failed ])
5759
end
@@ -64,9 +66,11 @@
6466
end
6567

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

0 commit comments

Comments
 (0)