Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / facter / root_home.rb
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
16 Facter.add(:root_home) do
17   setcode { Facter::Util::RootHome.returnt_root_home }
18 end
19
20 Facter.add(:root_home) do
21   confine :kernel => :darwin
22   setcode do
23     str = Facter::Util::Resolution.exec('dscacheutil -q user -a name root')
24     hash = {}
25     str.split("\n").each do |pair|
26       key, value = pair.split(%r{:})
27       hash[key] = value
28     end
29     hash['dir'].strip
30   end
31 end
32
33 Facter.add(:root_home) do
34   confine :kernel => :aix
35   root_home = nil
36   setcode do
37     str = Facter::Util::Resolution.exec('lsuser -c -a home root')
38     str && str.split("\n").each do |line|
39       next if line =~ %r{^#}
40       root_home = line.split(%r{:})[1]
41     end
42     root_home
43   end
44 end