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