alternatives.pp 900 B

12345678910111213141516171819202122232425262728293031323334
  1. #
  2. # fmw_jdk::utils::alternatives
  3. #
  4. # Copyright 2015 Oracle. All Rights Reserved
  5. #
  6. define fmw_jdk::utils::alternatives(
  7. $java_home_dir = undef,
  8. $priority = undef,
  9. $user = undef,
  10. $group = undef,
  11. )
  12. {
  13. $path = '/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin'
  14. case $::osfamily {
  15. 'RedHat': {
  16. $alt_command = 'alternatives'
  17. }
  18. 'Debian', 'Suse':{
  19. $alt_command = 'update-alternatives'
  20. }
  21. default: {
  22. fail("Unrecognized osfamily ${::osfamily}, please use it on a Linux host")
  23. }
  24. }
  25. exec { "java alternatives ${title}":
  26. command => "${alt_command} --install /usr/bin/${title} ${title} ${java_home_dir}/bin/${title} ${priority}",
  27. unless => "${alt_command} --display ${title} | /bin/grep ${java_home_dir} | /bin/grep 'priority ${priority}$'",
  28. path => $path,
  29. user => $user,
  30. group => $group,
  31. }
  32. }