facter 1.5 → 1.5.2
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 +51 -1
- data/Rakefile +10 -1
- data/conf/osx/PackageInfo.plist +36 -0
- data/conf/osx/createpackage.sh +167 -0
- data/conf/osx/preflight +11 -0
- data/conf/redhat/facter.spec +120 -0
- data/conf/solaris/pkginfo +7 -0
- data/documentation/custom.page +22 -0
- data/documentation/index.page +19 -0
- data/install.rb +227 -92
- data/lib/facter.rb +1 -1
- data/lib/facter/domain.rb +14 -0
- data/lib/facter/hardwaremodel.rb +8 -0
- data/lib/facter/ipaddress.rb +21 -2
- data/lib/facter/ipmess.rb +8 -37
- data/lib/facter/kernel.rb +7 -1
- data/lib/facter/kernelrelease.rb +16 -1
- data/lib/facter/kernelversion.rb +5 -0
- data/lib/facter/lsb.rb +1 -0
- data/lib/facter/macaddress.rb +15 -1
- data/lib/facter/operatingsystem.rb +6 -1
- data/lib/facter/operatingsystemrelease.rb +34 -7
- data/lib/facter/puppetversion.rb +1 -1
- data/lib/facter/util/ip.rb +37 -47
- data/lib/facter/util/manufacturer.rb +2 -2
- data/lib/facter/util/resolution.rb +13 -3
- data/lib/facter/virtual.rb +62 -0
- data/spec/Rakefile +18 -0
- data/spec/integration/facter.rb +27 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/unit/data/linux_ifconfig_all_with_single_interface +18 -0
- data/spec/unit/data/solaris_ifconfig_single_interface +3 -0
- data/spec/unit/facter.rb +134 -0
- data/spec/unit/util/collection.rb +255 -0
- data/spec/unit/util/confine.rb +75 -0
- data/spec/unit/util/fact.rb +129 -0
- data/spec/unit/util/ip.rb +40 -0
- data/spec/unit/util/loader.rb +219 -0
- data/spec/unit/util/resolution.rb +209 -0
- metadata +31 -2
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
inMenu: false
|
3
|
+
directoryName: Facter
|
4
|
+
---
|
5
|
+
|
6
|
+
A cross-platform Ruby library for retrieving facts from operating systems.
|
7
|
+
Supports multiple resolution mechanisms, any of which can be restricted to
|
8
|
+
working only on certain operating systems or environments. Facter is especially
|
9
|
+
useful for retrieving things like operating system names, IP addresses, MAC
|
10
|
+
addresses, and SSH keys.
|
11
|
+
|
12
|
+
It is easy to extend Facter to include your own [custom facts](custom.html) or
|
13
|
+
to include additional mechanisms for retrieving facts.
|
14
|
+
|
15
|
+
* [Downloads](/downloads/facter/)
|
16
|
+
* [Bug Tracking](/cgi-bin/facter.cgi)
|
17
|
+
* [API Documentation](/downloads/facter/apidocs/)
|
18
|
+
|
19
|
+
*$Id$*
|
data/install.rb
CHANGED
@@ -30,45 +30,57 @@
|
|
30
30
|
# 5) Install all library files ending in .rb from lib/ into Ruby's
|
31
31
|
# site_lib/version directory.
|
32
32
|
#
|
33
|
-
# $Id: install.rb,v 1.6 2004/08/08 20:33:09 austin Exp $
|
34
33
|
#++
|
35
34
|
|
36
35
|
require 'rbconfig'
|
37
36
|
require 'find'
|
38
37
|
require 'fileutils'
|
38
|
+
require 'ftools' # apparently on some system ftools doesn't get loaded
|
39
39
|
require 'optparse'
|
40
40
|
require 'ostruct'
|
41
41
|
|
42
|
-
InstallOptions = OpenStruct.new
|
43
|
-
|
44
|
-
$loadedrdoc = false
|
45
|
-
|
46
42
|
begin
|
47
43
|
require 'rdoc/rdoc'
|
48
|
-
$
|
49
|
-
rescue LoadError
|
50
|
-
|
51
|
-
|
44
|
+
$haverdoc = true
|
45
|
+
rescue LoadError
|
46
|
+
puts "Missing rdoc; skipping documentation"
|
47
|
+
$haverdoc = false
|
48
|
+
end
|
49
|
+
|
50
|
+
begin
|
51
|
+
if $haverdoc
|
52
|
+
rst2man = %x{which rst2man.py}
|
53
|
+
$haveman = true
|
54
|
+
else
|
55
|
+
$haveman = false
|
56
|
+
end
|
57
|
+
rescue
|
58
|
+
puts "Missing rst2man; skipping man page creation"
|
59
|
+
$haveman = false
|
52
60
|
end
|
53
61
|
|
62
|
+
PREREQS = %w{openssl xmlrpc/client xmlrpc/server cgi}
|
63
|
+
|
64
|
+
InstallOptions = OpenStruct.new
|
54
65
|
|
55
66
|
def glob(list)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
67
|
+
g = list.map { |i| Dir.glob(i) }
|
68
|
+
g.flatten!
|
69
|
+
g.compact!
|
70
|
+
g.reject! { |e| e =~ /\.svn/ }
|
71
|
+
g
|
61
72
|
end
|
62
73
|
|
63
|
-
|
64
|
-
|
65
|
-
bins =
|
66
|
-
rdoc = glob(%w{bin
|
67
|
-
ri = glob(%w(bin
|
68
|
-
|
74
|
+
# Set these values to what you want installed.
|
75
|
+
sbins = glob(%w{sbin/*})
|
76
|
+
bins = glob(%w{bin/*})
|
77
|
+
rdoc = glob(%w{bin/* sbin/* lib/**/*.rb README README-library CHANGELOG TODO Install}).reject { |e| e=~ /\.(bat|cmd)$/ }
|
78
|
+
ri = glob(%w(bin/*.rb sbin/* lib/**/*.rb)).reject { |e| e=~ /\.(bat|cmd)$/ }
|
79
|
+
man = glob(%w{man/man8/*})
|
80
|
+
libs = glob(%w{lib/**/*.rb lib/**/*.py})
|
69
81
|
tests = glob(%w{tests/**/*.rb})
|
70
82
|
|
71
|
-
def do_bins(bins, target, strip = 'bin/')
|
83
|
+
def do_bins(bins, target, strip = 's?bin/')
|
72
84
|
bins.each do |bf|
|
73
85
|
obf = bf.gsub(/#{strip}/, '')
|
74
86
|
install_binfile(bf, obf, target)
|
@@ -79,26 +91,64 @@ def do_libs(libs, strip = 'lib/')
|
|
79
91
|
libs.each do |lf|
|
80
92
|
olf = File.join(InstallOptions.site_dir, lf.gsub(/#{strip}/, ''))
|
81
93
|
op = File.dirname(olf)
|
82
|
-
|
83
|
-
FileUtils.makedirs(op)
|
84
|
-
#else
|
85
|
-
# recmkdir(op)
|
86
|
-
#end
|
94
|
+
File.makedirs(op, true)
|
87
95
|
File.chmod(0755, op)
|
88
|
-
|
96
|
+
File.install(lf, olf, 0755, true)
|
89
97
|
end
|
90
98
|
end
|
91
99
|
|
100
|
+
def do_man(man, strip = 'man/')
|
101
|
+
man.each do |mf|
|
102
|
+
omf = File.join(InstallOptions.man_dir, mf.gsub(/#{strip}/, ''))
|
103
|
+
om = File.dirname(omf)
|
104
|
+
File.makedirs(om, true)
|
105
|
+
File.chmod(0644, om)
|
106
|
+
File.install(mf, omf, 0644, true)
|
107
|
+
gzip = %x{which gzip}
|
108
|
+
gzip.chomp!
|
109
|
+
%x{#{gzip} -f #{omf}}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Verify that all of the prereqs are installed
|
114
|
+
def check_prereqs
|
115
|
+
PREREQS.each { |pre|
|
116
|
+
begin
|
117
|
+
require pre
|
118
|
+
rescue LoadError
|
119
|
+
puts "Could not load %s; cannot install" % pre
|
120
|
+
exit -1
|
121
|
+
end
|
122
|
+
}
|
123
|
+
end
|
124
|
+
|
92
125
|
##
|
93
126
|
# Prepare the file installation.
|
94
127
|
#
|
95
128
|
def prepare_installation
|
96
|
-
|
97
|
-
if
|
98
|
-
|
129
|
+
# Only try to do docs if we're sure they have rdoc
|
130
|
+
if $haverdoc
|
131
|
+
InstallOptions.rdoc = true
|
132
|
+
if RUBY_PLATFORM == "i386-mswin32"
|
133
|
+
InstallOptions.ri = false
|
134
|
+
else
|
135
|
+
InstallOptions.ri = true
|
136
|
+
end
|
137
|
+
else
|
138
|
+
InstallOptions.rdoc = false
|
139
|
+
InstallOptions.ri = false
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
if $haveman
|
144
|
+
InstallOptions.man = true
|
145
|
+
if RUBY_PLATFORM == "i386-mswin32"
|
146
|
+
InstallOptions.man = false
|
147
|
+
end
|
99
148
|
else
|
100
|
-
|
149
|
+
InstallOptions.man = false
|
101
150
|
end
|
151
|
+
|
102
152
|
InstallOptions.tests = true
|
103
153
|
|
104
154
|
ARGV.options do |opts|
|
@@ -110,9 +160,27 @@ def prepare_installation
|
|
110
160
|
opts.on('--[no-]ri', 'Prevents the creation of RI output.', 'Default off on mswin32.') do |onri|
|
111
161
|
InstallOptions.ri = onri
|
112
162
|
end
|
163
|
+
opts.on('--[no-]man', 'Presents the creation of man pages.', 'Default on.') do |onman|
|
164
|
+
InstallOptions.man = onman
|
165
|
+
end
|
113
166
|
opts.on('--[no-]tests', 'Prevents the execution of unit tests.', 'Default on.') do |ontest|
|
114
167
|
InstallOptions.tests = ontest
|
115
168
|
end
|
169
|
+
opts.on('--destdir[=OPTIONAL]', 'Installation prefix for all targets', 'Default essentially /') do |destdir|
|
170
|
+
InstallOptions.destdir = destdir
|
171
|
+
end
|
172
|
+
opts.on('--bindir[=OPTIONAL]', 'Installation directory for binaries', 'overrides Config::CONFIG["bindir"]') do |bindir|
|
173
|
+
InstallOptions.bindir = bindir
|
174
|
+
end
|
175
|
+
opts.on('--sbindir[=OPTIONAL]', 'Installation directory for system binaries', 'overrides Config::CONFIG["sbindir"]') do |sbindir|
|
176
|
+
InstallOptions.sbindir = sbindir
|
177
|
+
end
|
178
|
+
opts.on('--sitelibdir[=OPTIONAL]', 'Installation directory for libraries', 'overrides Config::CONFIG["sitelibdir"]') do |sitelibdir|
|
179
|
+
InstallOptions.sitelibdir = sitelibdir
|
180
|
+
end
|
181
|
+
opts.on('--mandir[=OPTIONAL]', 'Installation directory for man pages', 'overrides Config::CONFIG["mandir"]') do |mandir|
|
182
|
+
InstallOptions.mandir = mandir
|
183
|
+
end
|
116
184
|
opts.on('--quick', 'Performs a quick installation. Only the', 'installation is done.') do |quick|
|
117
185
|
InstallOptions.rdoc = false
|
118
186
|
InstallOptions.ri = false
|
@@ -132,80 +200,147 @@ def prepare_installation
|
|
132
200
|
opts.parse!
|
133
201
|
end
|
134
202
|
|
135
|
-
|
203
|
+
tmpdirs = [".", ENV['TMP'], ENV['TEMP'], "/tmp", "/var/tmp"]
|
136
204
|
|
137
205
|
version = [Config::CONFIG["MAJOR"], Config::CONFIG["MINOR"]].join(".")
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
206
|
+
libdir = File.join(Config::CONFIG["libdir"], "ruby", version)
|
207
|
+
|
208
|
+
# Mac OS X 10.5 declares bindir and sbindir as
|
209
|
+
# /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin
|
210
|
+
# /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/sbin
|
211
|
+
# which is not generally where people expect executables to be installed
|
212
|
+
if RUBY_PLATFORM == "universal-darwin9.0"
|
213
|
+
Config::CONFIG['bindir'] = "/usr/bin"
|
214
|
+
Config::CONFIG['sbindir'] = "/usr/sbin"
|
215
|
+
end
|
216
|
+
|
217
|
+
if not InstallOptions.bindir.nil?
|
218
|
+
bindir = InstallOptions.bindir
|
219
|
+
else
|
220
|
+
bindir = Config::CONFIG['bindir']
|
221
|
+
end
|
222
|
+
|
223
|
+
if not InstallOptions.sbindir.nil?
|
224
|
+
sbindir = InstallOptions.sbindir
|
225
|
+
else
|
226
|
+
sbindir = Config::CONFIG['sbindir']
|
227
|
+
end
|
228
|
+
|
229
|
+
if not InstallOptions.sitelibdir.nil?
|
230
|
+
sitelibdir = InstallOptions.sitelibdir
|
231
|
+
else
|
232
|
+
sitelibdir = Config::CONFIG["sitelibdir"]
|
233
|
+
if sitelibdir.nil?
|
234
|
+
sitelibdir = $:.find { |x| x =~ /site_ruby/ }
|
235
|
+
if sitelibdir.nil?
|
236
|
+
sitelibdir = File.join(libdir, "site_ruby")
|
237
|
+
elsif sitelibdir !~ Regexp.quote(version)
|
238
|
+
sitelibdir = File.join(sitelibdir, version)
|
239
|
+
end
|
147
240
|
end
|
148
241
|
end
|
242
|
+
|
243
|
+
if not InstallOptions.mandir.nil?
|
244
|
+
mandir = InstallOptions.mandir
|
245
|
+
else
|
246
|
+
mandir = Config::CONFIG['mandir']
|
247
|
+
end
|
149
248
|
|
249
|
+
# To be deprecated once people move over to using --destdir option
|
150
250
|
if (destdir = ENV['DESTDIR'])
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
FileUtils.makedirs(
|
157
|
-
|
158
|
-
|
159
|
-
|
251
|
+
bindir = "#{destdir}#{bindir}"
|
252
|
+
sbindir = "#{destdir}#{sbindir}"
|
253
|
+
mandir = "#{destdir}#{mandir}"
|
254
|
+
sitelibdir = "#{destdir}#{sitelibdir}"
|
255
|
+
|
256
|
+
FileUtils.makedirs(bindir)
|
257
|
+
FileUtils.makedirs(sbindir)
|
258
|
+
FileUtils.makedirs(mandir)
|
259
|
+
FileUtils.makedirs(sitelibdir)
|
260
|
+
# This is the new way forward
|
261
|
+
elsif (destdir = InstallOptions.destdir)
|
262
|
+
bindir = "#{destdir}#{bindir}"
|
263
|
+
sbindir = "#{destdir}#{sbindir}"
|
264
|
+
mandir = "#{destdir}#{mandir}"
|
265
|
+
sitelibdir = "#{destdir}#{sitelibdir}"
|
266
|
+
|
267
|
+
FileUtils.makedirs(bindir)
|
268
|
+
FileUtils.makedirs(sbindir)
|
269
|
+
FileUtils.makedirs(mandir)
|
270
|
+
FileUtils.makedirs(sitelibdir)
|
160
271
|
end
|
161
272
|
|
162
|
-
|
163
|
-
InstallOptions.site_dir = sd
|
164
|
-
InstallOptions.bin_dir = bd
|
165
|
-
InstallOptions.lib_dir = ld
|
273
|
+
tmpdirs << bindir
|
166
274
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
275
|
+
InstallOptions.tmp_dirs = tmpdirs.compact
|
276
|
+
InstallOptions.site_dir = sitelibdir
|
277
|
+
InstallOptions.bin_dir = bindir
|
278
|
+
InstallOptions.sbin_dir = sbindir
|
279
|
+
InstallOptions.lib_dir = libdir
|
280
|
+
InstallOptions.man_dir = mandir
|
171
281
|
end
|
172
282
|
|
173
283
|
##
|
174
284
|
# Build the rdoc documentation. Also, try to build the RI documentation.
|
175
285
|
#
|
176
286
|
def build_rdoc(files)
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
287
|
+
return unless $haverdoc
|
288
|
+
begin
|
289
|
+
r = RDoc::RDoc.new
|
290
|
+
r.document(["--main", "README", "--title",
|
291
|
+
"Puppet -- Site Configuration Management", "--line-numbers"] + files)
|
292
|
+
rescue RDoc::RDocError => e
|
293
|
+
$stderr.puts e.message
|
294
|
+
rescue Exception => e
|
295
|
+
$stderr.puts "Couldn't build RDoc documentation\n#{e.message}"
|
296
|
+
end
|
185
297
|
end
|
186
298
|
|
187
299
|
def build_ri(files)
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
300
|
+
return unless $haverdoc
|
301
|
+
begin
|
302
|
+
ri = RDoc::RDoc.new
|
303
|
+
#ri.document(["--ri-site", "--merge"] + files)
|
304
|
+
ri.document(["--ri-site"] + files)
|
305
|
+
rescue RDoc::RDocError => e
|
306
|
+
$stderr.puts e.message
|
307
|
+
rescue Exception => e
|
308
|
+
$stderr.puts "Couldn't build Ri documentation\n#{e.message}"
|
309
|
+
$stderr.puts "Continuing with install..."
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
def build_man(bins)
|
314
|
+
return unless $haveman
|
315
|
+
begin
|
316
|
+
# Locate rst2man
|
317
|
+
rst2man = %x{which rst2man.py}
|
318
|
+
rst2man.chomp!
|
319
|
+
# Create puppet.conf.8 man page
|
320
|
+
%x{bin/puppetdoc --reference configuration > ./puppet.conf.rst}
|
321
|
+
%x{#{rst2man} ./puppet.conf.rst ./man/man8/puppet.conf.8}
|
322
|
+
File.unlink("./puppet.conf.rst")
|
323
|
+
|
324
|
+
# Create binary man pages
|
325
|
+
bins.each do |bin|
|
326
|
+
b = bin.gsub( "bin/", "")
|
327
|
+
%x{#{bin} --help > ./#{b}.rst}
|
328
|
+
%x{#{rst2man} ./#{b}.rst ./man/man8/#{b}.8}
|
329
|
+
File.unlink("./#{b}.rst")
|
330
|
+
end
|
331
|
+
rescue SystemCallError
|
332
|
+
$stderr.puts "Couldn't build man pages: " + $!
|
333
|
+
$stderr.puts "Continuing with install..."
|
334
|
+
end
|
195
335
|
end
|
196
336
|
|
197
337
|
def run_tests(test_list)
|
198
338
|
begin
|
199
339
|
require 'test/unit/ui/console/testrunner'
|
200
|
-
require 'test/unit'
|
201
|
-
|
202
|
-
unless defined? Test::Unit::TestCase
|
203
|
-
raise LoadError, "Could not find unit test library"
|
204
|
-
end
|
205
340
|
$:.unshift "lib"
|
206
341
|
test_list.each do |test|
|
207
|
-
|
208
|
-
|
342
|
+
next if File.directory?(test)
|
343
|
+
require test
|
209
344
|
end
|
210
345
|
|
211
346
|
tests = []
|
@@ -227,8 +362,8 @@ end
|
|
227
362
|
# windows, we add an '.rb' extension and let file associations do their stuff.
|
228
363
|
def install_binfile(from, op_file, target)
|
229
364
|
tmp_dir = nil
|
230
|
-
InstallOptions.
|
231
|
-
if File.directory?(t) and File.
|
365
|
+
InstallOptions.tmp_dirs.each do |t|
|
366
|
+
if File.directory?(t) and File.writable?(t)
|
232
367
|
tmp_dir = t
|
233
368
|
break
|
234
369
|
end
|
@@ -242,12 +377,15 @@ def install_binfile(from, op_file, target)
|
|
242
377
|
File.open(tmp_file, "w") do |op|
|
243
378
|
ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
|
244
379
|
op.puts "#!#{ruby}"
|
245
|
-
|
380
|
+
contents = ip.readlines
|
381
|
+
if contents[0] =~ /^#!/
|
382
|
+
contents.shift
|
383
|
+
end
|
384
|
+
op.write contents.join()
|
246
385
|
end
|
247
386
|
end
|
248
387
|
|
249
|
-
|
250
|
-
if Config::CONFIG["target_os"] =~ /win/io and Config::CONFIG["target_os"] !~ /darwin/
|
388
|
+
if Config::CONFIG["target_os"] =~ /win/io and Config::CONFIG["target_os"] !~ /darwin/io
|
251
389
|
installed_wrapper = false
|
252
390
|
|
253
391
|
if File.exists?("#{from}.bat")
|
@@ -287,17 +425,14 @@ goto done
|
|
287
425
|
:done
|
288
426
|
EOS
|
289
427
|
|
428
|
+
check_prereqs
|
290
429
|
prepare_installation
|
291
430
|
|
292
431
|
run_tests(tests) if InstallOptions.tests
|
293
432
|
#build_rdoc(rdoc) if InstallOptions.rdoc
|
294
433
|
#build_ri(ri) if InstallOptions.ri
|
295
|
-
|
296
|
-
|
297
|
-
# bd = "#{destdir}#{Config::CONFIG['bindir']}"
|
298
|
-
#else
|
299
|
-
# bd = "#{Config::CONFIG['bindir']}"
|
300
|
-
#end
|
301
|
-
|
434
|
+
#build_man(bins) if InstallOptions.man
|
435
|
+
do_bins(sbins, InstallOptions.sbin_dir)
|
302
436
|
do_bins(bins, InstallOptions.bin_dir)
|
303
437
|
do_libs(libs)
|
438
|
+
do_man(man)
|
data/lib/facter.rb
CHANGED