facter 1.6.9 → 1.6.10

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of facter might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -1,3 +1,27 @@
1
+ 1.6.10
2
+ ===
3
+ 35067dc Bump Facter epoch to 1
4
+ d6a3e91 Make package task depend on tar in Rakfile
5
+ f42896d (#14764) Stub architecture fact when Windows facts run on Linux
6
+ f44ca52 (maint) Fix hardware model fact for ruby 1.9
7
+ 964d1f0 (#12864) Close registry key
8
+ ab025bb Revert "Revert "(#12864) Windows: get primary DNS from registry""
9
+ 478386d (#10261) Detect x64 architecture on Windows
10
+ 6cc881d Use git describe in Rakefile to determine pkg ver
11
+ 2043244 (#13678) Remove deprecation msg triggerd by the ipaddress6 fact
12
+ d118d81 (#13678) Add filename extension on absolute paths on windows
13
+ b050eb1 (#14582) Fix noise in LSB facts
14
+ 85654b0 (#13678) Allow passing shell built-ins to exec method on windows
15
+ 8f4c016 (#13678) Single quote paths on unix with spaces
16
+ 2d164e8 (#13678) Join PATHs correctly on windows
17
+ e7e7e8f (#13678) Extend spec tests for expand_command
18
+ 0fea7b0 maint: Add shared context for specs to imitate windows or posix
19
+ 60d0cd2 (#13678) Fix spec failures on windows
20
+ 121a2ab (#13678) Fix quoting in expand_command
21
+ 55b1125 (#13678) Add more unit tests for new methods
22
+ 9086c0a (#13678) Add RDoc documentation for new methods
23
+ 165ace4 (#13678) Convert command to absolute paths before executing
24
+
1
25
  1.6.9
2
26
  ===
3
27
  b398bd8 (#14334) Fix dmidecode based facts on DragonFly BSD
data/Rakefile CHANGED
@@ -17,10 +17,6 @@ require 'rake'
17
17
  require 'rake/packagetask'
18
18
  require 'rake/gempackagetask'
19
19
 
20
- module Facter
21
- FACTERVERSION = File.read('lib/facter.rb')[/FACTERVERSION *= *'(.*)'/,1] or fail "Couldn't find FACTERVERSION"
22
- end
23
-
24
20
  FILES = FileList[
25
21
  '[A-Z]*',
26
22
  'install.rb',
@@ -31,12 +27,50 @@ FILES = FileList[
31
27
  'spec/**/*'
32
28
  ]
33
29
 
30
+ def get_version
31
+ `git describe`.strip
32
+ end
33
+
34
+ # :build_environment and :tar are mostly borrowed from puppet-dashboard Rakefile
35
+ task :build_environment do
36
+ unless ENV['FORCE'] == '1'
37
+ modified = `git status --porcelain | sed -e '/^\?/d'`
38
+ if modified.split(/\n/).length != 0
39
+ puts <<-HERE
40
+ !! ERROR: Your git working directory is not clean. You must
41
+ !! remove or commit your changes before you can create a package:
42
+
43
+ #{`git status | grep '^#'`.chomp}
44
+
45
+ !! To override this check, set FORCE=1 -- e.g. `rake package:deb FORCE=1`
46
+ HERE
47
+ raise
48
+ end
49
+ end
50
+ end
51
+
52
+ desc "Create a release .tar.gz"
53
+ task :tar => :build_environment do
54
+ name = "facter"
55
+ rm_rf 'pkg/tar'
56
+ temp=`mktemp -d -t tmpXXXXXX`.strip!
57
+ version = get_version
58
+ base = "#{temp}/#{name}-#{version}/"
59
+ mkdir_p base
60
+ sh "git checkout-index -af --prefix=#{base}"
61
+ mkdir_p "pkg/tar"
62
+ sh "tar -C #{temp} -pczf #{temp}/#{name}-#{version}.tar.gz #{name}-#{version}"
63
+ mv "#{temp}/#{name}-#{version}.tar.gz", "pkg/tar"
64
+ rm_rf temp
65
+ puts "Tarball is pkg/tar/#{name}-#{version}.tar.gz"
66
+ end
67
+
34
68
  spec = Gem::Specification.new do |spec|
35
69
  spec.platform = Gem::Platform::RUBY
36
70
  spec.name = 'facter'
37
71
  spec.files = FILES.to_a
38
72
  spec.executables = %w{facter}
39
- spec.version = Facter::FACTERVERSION
73
+ spec.version = get_version.split('-')[0]
40
74
  spec.summary = 'Facter, a system inventory tool'
41
75
  spec.description = 'You can prove anything with facts!'
42
76
  spec.author = 'Puppet Labs'
@@ -49,16 +83,11 @@ spec = Gem::Specification.new do |spec|
49
83
  '--main' << 'README' <<
50
84
  '--line-numbers'
51
85
  end
52
-
53
- Rake::PackageTask.new("facter", Facter::FACTERVERSION) do |pkg|
54
- pkg.package_dir = 'pkg'
55
- pkg.need_tar_gz = true
56
- pkg.package_files = FILES.to_a
57
- end
58
-
59
86
  Rake::GemPackageTask.new(spec) do |pkg|
60
87
  end
61
88
 
89
+ task :package => :tar
90
+
62
91
  task :default do
63
92
  sh %{rake -T}
64
93
  end
@@ -2,9 +2,10 @@
2
2
 
3
3
  Summary: Ruby module for collecting simple facts about a host operating system
4
4
  Name: facter
5
- Version: 1.6.9
5
+ Version: 1.6.10
6
6
  Release: 1%{?dist}
7
- #Release: 0.1rc1%{?dist}
7
+ #Release: 0.1rc1.2%{?dist}
8
+ Epoch: 1
8
9
  License: Apache 2.0
9
10
  Group: System Environment/Base
10
11
  URL: http://www.puppetlabs.com/puppet/related-projects/%{name}
@@ -53,6 +54,15 @@ rm -rf %{buildroot}
53
54
 
54
55
 
55
56
  %changelog
57
+ * Wed Jun 13 2012 Moses Mendoza <moses@puppetlabs.com> - 1.6.10-1
58
+ - Update for 1.6.10
59
+
60
+ * Fri Jun 8 2012 Moses Mendoza <moses@puppetlabs.com> - 1.6.10-0.1rc1.2
61
+ - Bump epoch to 1 to address errant Facter 2.0 rc release
62
+
63
+ * Wed Jun 6 2012 Moses Mendoza <moses@puppetlabs.com> - 1.6.10-0.1rc1
64
+ - Update for 1.6.10rc1
65
+
56
66
  * Thu May 17 2012 Moses Mendoza <moses@puppetlabs.com> - 1.6.9-1
57
67
  - Update for 1.6.9
58
68
 
data/lib/facter.rb CHANGED
@@ -25,7 +25,7 @@ module Facter
25
25
  include Comparable
26
26
  include Enumerable
27
27
 
28
- FACTERVERSION = '1.6.9'
28
+ FACTERVERSION = '1.6.10'
29
29
  # = Facter
30
30
  # Functions as a hash of 'facts' you might care about about your
31
31
  # system, such as mac address, IP address, Video card, etc.
@@ -25,7 +25,7 @@ Facter.add(:architecture) do
25
25
  end
26
26
  when /(i[3456]86|pentium)/
27
27
  case Facter.value(:operatingsystem)
28
- when "Gentoo"
28
+ when "Gentoo", "windows"
29
29
  "x86"
30
30
  else
31
31
  "i386"
data/lib/facter/domain.rb CHANGED
@@ -52,12 +52,17 @@ end
52
52
  Facter.add(:domain) do
53
53
  confine :kernel => :windows
54
54
  setcode do
55
- require 'facter/util/wmi'
55
+ require 'facter/util/registry'
56
56
  domain = ""
57
- Facter::Util::WMI.execquery("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").each { |nic|
58
- domain = nic.DNSDomain
59
- break
60
- }
57
+ regvalue = Facter::Util::Registry.hklm_read('SYSTEM\CurrentControlSet\Services\Tcpip\Parameters', 'Domain')
58
+ domain = regvalue if regvalue
59
+ if domain == ""
60
+ require 'facter/util/wmi'
61
+ Facter::Util::WMI.execquery("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").each { |nic|
62
+ domain = nic.DNSDomain
63
+ break
64
+ }
65
+ end
61
66
  domain
62
67
  end
63
68
  end
@@ -28,7 +28,34 @@ end
28
28
  Facter.add(:hardwaremodel) do
29
29
  confine :operatingsystem => :windows
30
30
  setcode do
31
- require 'rbconfig'
32
- RbConfig::CONFIG['host_cpu']
31
+ # The cryptic windows cpu architecture models are documented in these places:
32
+ # http://source.winehq.org/source/include/winnt.h#L568
33
+ # http://msdn.microsoft.com/en-us/library/windows/desktop/aa394373(v=vs.85).aspx
34
+ # http://msdn.microsoft.com/en-us/library/windows/desktop/windows.system.processorarchitecture.aspx
35
+ # Also, arm and neutral are included because they are valid for the upcoming
36
+ # windows 8 release. --jeffweiss 23 May 2012
37
+ require 'facter/util/wmi'
38
+ model = ""
39
+ Facter::Util::WMI.execquery("select Architecture, Level from Win32_Processor").each do |cpu|
40
+ model =
41
+ case cpu.Architecture
42
+ when 11 then 'neutral' # PROCESSOR_ARCHITECTURE_NEUTRAL
43
+ when 10 then 'i686' # PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
44
+ when 9 then 'x64' # PROCESSOR_ARCHITECTURE_AMD64
45
+ when 8 then 'msil' # PROCESSOR_ARCHITECTURE_MSIL
46
+ when 7 then 'alpha64' # PROCESSOR_ARCHITECTURE_ALPHA64
47
+ when 6 then 'ia64' # PROCESSOR_ARCHITECTURE_IA64
48
+ when 5 then 'arm' # PROCESSOR_ARCHITECTURE_ARM
49
+ when 4 then 'shx' # PROCESSOR_ARCHITECTURE_SHX
50
+ when 3 then 'powerpc' # PROCESSOR_ARCHITECTURE_PPC
51
+ when 2 then 'alpha' # PROCESSOR_ARCHITECTURE_ALPHA
52
+ when 1 then 'mips' # PROCESSOR_ARCHITECTURE_MIPS
53
+ when 0 then "i#{cpu.Level}86" # PROCESSOR_ARCHITECTURE_INTEL
54
+ else 'unknown' # PROCESSOR_ARCHITECTURE_UNKNOWN
55
+ end
56
+ break
57
+ end
58
+
59
+ model
33
60
  end
34
61
  end
@@ -65,7 +65,7 @@ end
65
65
  Facter.add(:ipaddress6) do
66
66
  confine :kernel => :windows
67
67
  setcode do
68
- output = Facter::Util::Resolution.exec("#{ENV['SYSTEMROOT']}/system32/netsh interface ipv6 show address level=verbose")
68
+ output = Facter::Util::Resolution.exec("#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ipv6 show address level=verbose")
69
69
 
70
70
  get_address_after_token(output, 'Address', true)
71
71
  end
@@ -13,6 +13,6 @@
13
13
  Facter.add(:lsbdistcodename) do
14
14
  confine :kernel => [ :linux, :"gnu/kfreebsd" ]
15
15
  setcode do
16
- Facter::Util::Resolution.exec('lsb_release -c -s')
16
+ Facter::Util::Resolution.exec('lsb_release -c -s 2>/dev/null')
17
17
  end
18
18
  end
@@ -13,7 +13,7 @@
13
13
  Facter.add(:lsbdistdescription) do
14
14
  confine :kernel => [ :linux, :"gnu/kfreebsd" ]
15
15
  setcode do
16
- if output = Facter::Util::Resolution.exec('lsb_release -d -s')
16
+ if output = Facter::Util::Resolution.exec('lsb_release -d -s 2>/dev/null')
17
17
  # the output may be quoted (at least it is on gentoo)
18
18
  output.sub(/^"(.*)"$/,'\1')
19
19
  end
@@ -13,6 +13,6 @@
13
13
  Facter.add(:lsbdistid) do
14
14
  confine :kernel => [ :linux, :"gnu/kfreebsd" ]
15
15
  setcode do
16
- Facter::Util::Resolution.exec('lsb_release -i -s')
16
+ Facter::Util::Resolution.exec('lsb_release -i -s 2>/dev/null')
17
17
  end
18
18
  end
@@ -13,6 +13,6 @@
13
13
  Facter.add(:lsbdistrelease) do
14
14
  confine :kernel => [ :linux, :"gnu/kfreebsd" ]
15
15
  setcode do
16
- Facter::Util::Resolution.exec('lsb_release -r -s')
16
+ Facter::Util::Resolution.exec('lsb_release -r -s 2>/dev/null')
17
17
  end
18
18
  end
@@ -13,6 +13,6 @@
13
13
  Facter.add(:lsbrelease) do
14
14
  confine :kernel => [ :linux, :"gnu/kfreebsd" ]
15
15
  setcode do
16
- Facter::Util::Resolution.exec('lsb_release -v -s')
16
+ Facter::Util::Resolution.exec('lsb_release -v -s 2>/dev/null')
17
17
  end
18
18
  end
@@ -80,8 +80,8 @@ module Facter::Util::IP
80
80
  when 'HP-UX'
81
81
  output = %x{/bin/netstat -in | sed -e 1d}
82
82
  when 'windows'
83
- output = %x|#{ENV['SYSTEMROOT']}/system32/netsh interface ip show interface|
84
- output += %x|#{ENV['SYSTEMROOT']}/system32/netsh interface ipv6 show interface|
83
+ output = %x|#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ip show interface|
84
+ output += %x|#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ipv6 show interface|
85
85
  end
86
86
  output
87
87
  end
@@ -107,9 +107,9 @@ module Facter::Util::IP
107
107
  return get_single_interface_output(interface) unless Facter.value(:kernel) == 'windows'
108
108
 
109
109
  if label == 'ipaddress6'
110
- output = %x|#{ENV['SYSTEMROOT']}/system32/netsh interface ipv6 show address \"#{interface}\"|
110
+ output = %x|#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ipv6 show address \"#{interface}\"|
111
111
  else
112
- output = %x|#{ENV['SYSTEMROOT']}/system32/netsh interface ip show address \"#{interface}\"|
112
+ output = %x|#{ENV['SYSTEMROOT']}/system32/netsh.exe interface ip show address \"#{interface}\"|
113
113
  end
114
114
  output
115
115
  end
@@ -0,0 +1,11 @@
1
+ module Facter::Util::Registry
2
+ class << self
3
+ def hklm_read(key, value)
4
+ require 'win32/registry'
5
+ reg = Win32::Registry::HKEY_LOCAL_MACHINE.open(key)
6
+ rval = reg[value]
7
+ reg.close
8
+ rval
9
+ end
10
+ end
11
+ end
@@ -13,18 +13,102 @@ class Facter::Util::Resolution
13
13
 
14
14
  INTERPRETER = Facter::Util::Config.is_windows? ? "cmd.exe" : "/bin/sh"
15
15
 
16
- def self.have_which
17
- if ! defined?(@have_which) or @have_which.nil?
18
- if Facter::Util::Config.is_windows?
19
- @have_which = false
20
- else
21
- %x{which which >/dev/null 2>&1}
22
- @have_which = $?.success?
16
+ # Returns the locations to be searched when looking for a binary. This
17
+ # is currently determined by the +PATH+ environment variable plus
18
+ # <tt>/sbin</tt> and <tt>/usr/sbin</tt> when run on unix
19
+ def self.search_paths
20
+ if Facter::Util::Config.is_windows?
21
+ ENV['PATH'].split(File::PATH_SEPARATOR)
22
+ else
23
+ # Make sure facter is usable even for non-root users. Most commands
24
+ # in /sbin (like ifconfig) can be run as non priviledged users as
25
+ # long as they do not modify anything - which we do not do with facter
26
+ ENV['PATH'].split(File::PATH_SEPARATOR) + [ '/sbin', '/usr/sbin' ]
27
+ end
28
+ end
29
+
30
+ # Determine the full path to a binary. If the supplied filename does not
31
+ # already describe an absolute path then different locations (determined
32
+ # by <tt>self.search_paths</tt>) will be searched for a match.
33
+ #
34
+ # Returns nil if no matching executable can be found otherwise returns
35
+ # the expanded pathname.
36
+ def self.which(bin)
37
+ if absolute_path?(bin)
38
+ return bin if File.executable?(bin)
39
+ if Facter::Util::Config.is_windows? and File.extname(bin).empty?
40
+ exts = ENV['PATHEXT']
41
+ exts = exts ? exts.split(File::PATH_SEPARATOR) : %w[.COM .EXE .BAT .CMD]
42
+ exts.each do |ext|
43
+ destext = bin + ext
44
+ if File.executable?(destext)
45
+ Facter.warnonce("Using Facter::Util::Resolution.which with an absolute path like #{bin} but no fileextension is deprecated. Please add the correct extension (#{ext})")
46
+ return destext
47
+ end
48
+ end
49
+ end
50
+ else
51
+ search_paths.each do |dir|
52
+ dest = File.join(dir, bin)
53
+ if Facter::Util::Config.is_windows?
54
+ dest.gsub!(File::SEPARATOR, File::ALT_SEPARATOR)
55
+ if File.extname(dest).empty?
56
+ exts = ENV['PATHEXT']
57
+ exts = exts ? exts.split(File::PATH_SEPARATOR) : %w[.COM .EXE .BAT .CMD]
58
+ exts.each do |ext|
59
+ destext = dest + ext
60
+ return destext if File.executable?(destext)
61
+ end
62
+ end
63
+ end
64
+ return dest if File.executable?(dest)
65
+ end
66
+ end
67
+ nil
68
+ end
69
+
70
+ # Determine in a platform-specific way whether a path is absolute. This
71
+ # defaults to the local platform if none is specified.
72
+ def self.absolute_path?(path, platform=nil)
73
+ # Escape once for the string literal, and once for the regex.
74
+ slash = '[\\\\/]'
75
+ name = '[^\\\\/]+'
76
+ regexes = {
77
+ :windows => %r!^(([A-Z]:#{slash})|(#{slash}#{slash}#{name}#{slash}#{name})|(#{slash}#{slash}\?#{slash}#{name}))!i,
78
+ :posix => %r!^/!,
79
+ }
80
+ platform ||= Facter::Util::Config.is_windows? ? :windows : :posix
81
+
82
+ !! (path =~ regexes[platform])
83
+ end
84
+
85
+ # Expand the executable of a commandline to an absolute path. The executable
86
+ # is the first word of the commandline. If the executable contains spaces,
87
+ # it has be but in double quotes to be properly recognized.
88
+ #
89
+ # Returns the commandline with the expanded binary or nil if the binary
90
+ # can't be found. If the path to the binary contains quotes, the whole binary
91
+ # is put in quotes.
92
+ def self.expand_command(command)
93
+ if match = /^"(.+?)"(?:\s+(.*))?/.match(command)
94
+ exe, arguments = match.captures
95
+ exe = which(exe) and [ "\"#{exe}\"", arguments ].compact.join(" ")
96
+ elsif match = /^'(.+?)'(?:\s+(.*))?/.match(command) and not Facter::Util::Config.is_windows?
97
+ exe, arguments = match.captures
98
+ exe = which(exe) and [ "'#{exe}'", arguments ].compact.join(" ")
99
+ else
100
+ exe, arguments = command.split(/ /,2)
101
+ if exe = which(exe)
102
+ # the binary was not quoted which means it contains no spaces. But the
103
+ # full path to the binary may do so.
104
+ exe = "\"#{exe}\"" if exe =~ /\s/ and Facter::Util::Config.is_windows?
105
+ exe = "'#{exe}'" if exe =~ /\s/ and not Facter::Util::Config.is_windows?
106
+ [ exe, arguments ].compact.join(" ")
23
107
  end
24
108
  end
25
- @have_which
26
109
  end
27
110
 
111
+
28
112
  # Execute a program and return the output of that program.
29
113
  #
30
114
  # Returns nil if the program can't be found, or if there is a problem
@@ -33,34 +117,21 @@ class Facter::Util::Resolution
33
117
  def self.exec(code, interpreter = nil)
34
118
  Facter.warnonce "The interpreter parameter to 'exec' is deprecated and will be removed in a future version." if interpreter
35
119
 
36
- # Try to guess whether the specified code can be executed by looking at the
37
- # first word. If it cannot be found on the PATH defer on resolving the fact
38
- # by returning nil.
39
- # This only fails on shell built-ins, most of which are masked by stuff in
40
- # /bin or of dubious value anyways. In the worst case, "sh -c 'builtin'" can
41
- # be used to work around this limitation
42
- #
43
- # Windows' %x{} throws Errno::ENOENT when the command is not found, so we
44
- # can skip the check there. This is good, since builtins cannot be found
45
- # elsewhere.
46
- if have_which and !Facter::Util::Config.is_windows?
47
- path = nil
48
- binary = code.split.first
49
- if code =~ /^\//
50
- path = binary
51
- else
52
- path = %x{which #{binary} 2>/dev/null}.chomp
53
- # we don't have the binary necessary
54
- return nil if path == "" or path.match(/Command not found\./)
55
- end
56
-
57
- return nil unless FileTest.exists?(path)
120
+ if expanded_code = expand_command(code)
121
+ # if we can find the binary, we'll run the command with the expanded path to the binary
122
+ code = expanded_code
123
+ else
124
+ # if we cannot find the binary return nil on posix. On windows we'll still try to run the
125
+ # command in case it is a shell-builtin. In case it is not, windows will raise Errno::ENOENT
126
+ return nil unless Facter::Util::Config.is_windows?
127
+ return nil if absolute_path?(code)
58
128
  end
59
129
 
60
130
  out = nil
61
131
 
62
132
  begin
63
133
  out = %x{#{code}}.chomp
134
+ Facter.warnonce 'Using Facter::Util::Resolution.exec with a shell built-in is deprecated. Most built-ins can be replaced with native ruby commands. If you really have to run a built-in, pass "cmd /c your_builtin" as a command' unless expanded_code
64
135
  rescue Errno::ENOENT => detail
65
136
  # command not found on Windows
66
137
  return nil