root_home.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # A facter fact to determine the root home directory.
  2. # This varies on PE supported platforms and may be
  3. # reconfigured by the end user.
  4. module Facter::Util::RootHome
  5. class << self
  6. def returnt_root_home
  7. root_ent = Facter::Util::Resolution.exec('getent passwd root')
  8. # The home directory is the sixth element in the passwd entry
  9. # If the platform doesn't have getent, root_ent will be nil and we should
  10. # return it straight away.
  11. root_ent && root_ent.split(':')[5]
  12. end
  13. end
  14. end
  15. Facter.add(:root_home) do
  16. setcode { Facter::Util::RootHome.returnt_root_home }
  17. end
  18. Facter.add(:root_home) do
  19. confine :kernel => :darwin
  20. setcode do
  21. str = Facter::Util::Resolution.exec('dscacheutil -q user -a name root')
  22. hash = {}
  23. str.split("\n").each do |pair|
  24. key, value = pair.split(%r{:})
  25. hash[key] = value
  26. end
  27. hash['dir'].strip
  28. end
  29. end
  30. Facter.add(:root_home) do
  31. confine :kernel => :aix
  32. root_home = nil
  33. setcode do
  34. str = Facter::Util::Resolution.exec('lsuser -c -a home root')
  35. str && str.split("\n").each do |line|
  36. next if line =~ %r{^#}
  37. root_home = line.split(%r{:})[1]
  38. end
  39. root_home
  40. end
  41. end