facter 1.1.1 → 1.3.3

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.

Files changed (10) hide show
  1. data/CHANGELOG +63 -0
  2. data/COPYING +416 -251
  3. data/Rakefile +30 -277
  4. data/bin/facter +60 -7
  5. data/install.rb +303 -289
  6. data/lib/facter.rb +280 -137
  7. data/lib/facter/memory.rb +62 -0
  8. data/lib/facter/processor.rb +52 -0
  9. metadata +32 -34
  10. data/CHANGES +0 -21
data/Rakefile CHANGED
@@ -1,293 +1,46 @@
1
1
  # Rakefile for facter
2
2
 
3
- begin
4
- require 'rubygems'
5
- require 'rake/gempackagetask'
6
- rescue Exception
7
- nil
3
+ begin
4
+ require 'rake/reductive'
5
+ rescue LoadError
6
+ $stderr.puts "You must have the Reductive build library in your RUBYLIB."
7
+ exit(14)
8
8
  end
9
9
 
10
- require 'rake/clean'
11
- require 'rake/testtask'
12
-
13
- require 'rake/rdoctask'
14
- #CLEAN.include('**/*.o')
15
- CLOBBER.include('doc/*')
16
-
17
- def announce(msg='')
18
- STDERR.puts msg
19
- end
20
-
21
- # Determine the current version
22
-
23
- if `ruby -Ilib ./bin/facter --version` =~ /\S+$/
24
- CURRENT_VERSION = $&
25
- else
26
- CURRENT_VERSION = "0.0.0"
27
- end
28
-
29
- if ENV['REL']
30
- PKG_VERSION = ENV['REL']
31
- else
32
- PKG_VERSION = CURRENT_VERSION
33
- end
34
-
35
- DOWNDIR = "/export/docroots/reductivelabs.com/htdocs/downloads"
36
-
37
- # The default task is run if rake is given no explicit arguments.
38
-
39
- desc "Default Task"
40
- task :default => :unittests
41
-
42
- # Test Tasks ---------------------------------------------------------
43
-
44
- #task :u => :unittests
45
- #task :a => :alltests
46
-
47
- #task :alltests => :unittests
48
-
49
- #Rake::TestTask.new(:unittests) do |t|
50
- # t.test_files = FileList['tests/*.rb']
51
- # t.warning = true
52
- # t.verbose = false
53
- #end
54
-
55
- # SVN Tasks ----------------------------------------------------------
56
- # ... none.
57
-
58
- # Install rake using the standard install.rb script.
59
-
60
- desc "Install the application"
61
- task :install do
62
- ruby "install.rb"
63
- end
64
-
65
- # Create a task to build the RDOC documentation tree.
66
-
67
- rd = Rake::RDocTask.new(:html) { |rdoc|
68
- rdoc.rdoc_dir = 'html'
69
- rdoc.template = 'html'
70
- rdoc.title = "Facter"
71
- rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
72
- rdoc.rdoc_files.include('README', 'LICENSE', 'TODO', 'CHANGES')
73
- rdoc.rdoc_files.include('lib/**/*.rb')
74
- CLEAN.include("html")
75
- }
76
-
77
- # ====================================================================
78
- # Create a task that will package the Rake software into distributable
79
- # tar, zip and gem files.
80
-
81
- PKG_FILES = FileList[
82
- 'install.rb',
83
- '[A-Z]*',
84
- 'bin/**/*',
85
- 'lib/**/*.rb',
86
- 'test/**/*.rb',
87
- 'doc/**/*',
88
- 'etc/*'
89
- ]
90
- PKG_FILES.delete_if {|item| item.include?(".svn")}
91
-
92
- if ! defined?(Gem)
93
- puts "Package Target requires RubyGEMs"
94
- else
95
- spec = Gem::Specification.new do |s|
96
-
97
- #### Basic information.
98
-
99
- s.name = 'facter'
100
- s.version = PKG_VERSION
101
- s.summary = "Facter collects Operating system facts."
102
- s.description = <<-EOF
10
+ project = Rake::RedLabProject.new("facter") do |p|
11
+ p.summary = "Facter collects Operating system facts."
12
+ p.description = <<-EOF
103
13
  Facter is a module for collecting simple facts about a host
104
14
  Operating system.
105
15
  EOF
106
16
 
107
- #### Dependencies and requirements.
108
-
109
- #s.add_dependency('log4r', '> 1.0.4')
110
- #s.requirements << ""
111
-
112
- s.files = PKG_FILES.to_a
113
-
114
- #### Load-time details: library and application (you will need one or both).
115
-
116
- s.require_path = 'lib' # Use these for libraries.
117
-
118
- s.bindir = "bin" # Use these for applications.
119
- s.executables = ["facter"]
120
- s.default_executable = "facter"
17
+ p.filelist = [
18
+ 'install.rb',
19
+ '[A-Z]*',
20
+ 'bin/**/*',
21
+ 'lib/**/*.rb',
22
+ 'test/**/*.rb',
23
+ 'doc/**/*',
24
+ 'etc/*'
25
+ ]
121
26
 
122
- #### Documentation and testing.
123
-
124
- s.has_rdoc = true
125
- s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
126
- s.rdoc_options <<
127
- '--title' << 'Facter' <<
128
- '--main' << 'README' <<
129
- '--line-numbers'
130
-
131
- #### Author and project details.
132
-
133
- s.author = "Luke Kanies"
134
- s.email = "dev@reductivelabs.com"
135
- s.homepage = "http://reductivelabs.com/projects/facter"
136
- #s.rubyforge_project = "facter"
137
- end
138
-
139
- Rake::GemPackageTask.new(spec) do |pkg|
140
- #pkg.need_zip = true
141
- pkg.need_tar = true
142
- end
143
-
144
- CLEAN.include("pkg")
145
- end
146
-
147
- # Misc tasks =========================================================
148
-
149
- #ARCHIVEDIR = '/...'
150
-
151
- #task :archive => [:package] do
152
- # cp FileList["pkg/*.tgz", "pkg/*.zip", "pkg/*.gem"], ARCHIVEDIR
153
- #end
154
-
155
- # Define an optional publish target in an external file. If the
156
- # publish.rf file is not found, the publish targets won't be defined.
157
-
158
- #load "publish.rf" if File.exist? "publish.rf"
159
-
160
- # Support Tasks ------------------------------------------------------
161
-
162
- def egrep(pattern)
163
- Dir['**/*.rb'].each do |fn|
164
- count = 0
165
- open(fn) do |f|
166
- while line = f.gets
167
- count += 1
168
- if line =~ pattern
169
- puts "#{fn}:#{count}:#{line}"
170
- end
171
- end
172
- end
173
- end
174
- end
175
-
176
- desc "Look for TODO and FIXME tags in the code"
177
- task :todo do
178
- egrep "/#.*(FIXME|TODO|TBD)/"
27
+ p.epmhosts = %w{culain}
28
+ p.rpmhost = "fedora1"
29
+ p.sunpkghost = "sol10b"
179
30
  end
180
31
 
181
- #desc "Look for Debugging print lines"
182
- #task :dbg do
183
- # egrep /\bDBG|\bbreakpoint\b/
184
- #end
185
-
186
- #desc "List all ruby files"
187
- #task :rubyfiles do
188
- # puts Dir['**/*.rb'].reject { |fn| fn =~ /^pkg/ }
189
- # puts Dir['bin/*'].reject { |fn| fn =~ /CVS|(~$)|(\.rb$)/ }
190
- #end
32
+ project.mkgemtask do |gem|
33
+ gem.require_path = 'lib' # Use these for libraries.
191
34
 
192
- # --------------------------------------------------------------------
193
- # Creating a release
194
-
195
- desc "Make a new release"
196
- task :release => [
197
- :prerelease,
198
- :clobber,
199
- :update_version,
200
- :tag,
201
- :package,
202
- :copy] do
203
- #:alltests,
204
-
205
- announce
206
- announce "**************************************************************"
207
- announce "* Release #{PKG_VERSION} Complete."
208
- announce "* Packages ready to upload."
209
- announce "**************************************************************"
210
- announce
35
+ gem.bindir = "bin" # Use these for applications.
36
+ gem.executables = ["facter"]
37
+ gem.default_executable = "facter"
211
38
  end
212
39
 
213
- # Validate that everything is ready to go for a release.
214
- task :prerelease do
215
- announce
216
- announce "**************************************************************"
217
- announce "* Making RubyGem Release #{PKG_VERSION}"
218
- announce "* (current version #{CURRENT_VERSION})"
219
- announce "**************************************************************"
220
- announce
221
-
222
- # Is a release number supplied?
223
- unless ENV['REL']
224
- fail "Usage: rake release REL=x.y.z [REUSE=tag_suffix]"
225
- end
226
-
227
- # Is the release different than the current release.
228
- # (or is REUSE set?)
229
- if PKG_VERSION == CURRENT_VERSION && ! ENV['REUSE']
230
- fail "Current version is #{PKG_VERSION}, must specify REUSE=tag_suffix to reuse version"
231
- end
232
-
233
- # Are all source files checked in?
234
- if ENV['RELTEST']
235
- announce "Release Task Testing, skipping checked-in file test"
236
- else
237
- announce "Checking for unchecked-in files..."
238
- data = `svn -q update`
239
- unless data =~ /^$/
240
- fail "SVN update is not clean ... do you have unchecked-in files?"
40
+ if project.has?(:epm)
41
+ project.mkepmtask do |task|
42
+ task.bins = FileList.new("bin/facter")
43
+ task.rubylibs = FileList.new('lib/**/*')
241
44
  end
242
- announce "No outstanding checkins found ... OK"
243
- end
244
45
  end
245
-
246
- task :update_version => [:prerelease] do
247
- if PKG_VERSION == CURRENT_VERSION
248
- announce "No version change ... skipping version update"
249
- else
250
- announce "Updating Facter version to #{PKG_VERSION}"
251
- open("lib/facter.rb") do |rakein|
252
- open("lib/facter.rb.new", "w") do |rakeout|
253
- rakein.each do |line|
254
- if line =~ /^\s*FACTERVERSION\s*=\s*/
255
- rakeout.puts "FACTERVERSION = '#{PKG_VERSION}'"
256
- else
257
- rakeout.puts line
258
- end
259
- end
260
- end
261
- end
262
- mv "lib/facter.rb.new", "lib/facter.rb"
263
- if ENV['RELTEST']
264
- announce "Release Task Testing, skipping commiting of new version"
265
- else
266
- sh %{svn commit -m "Updated to version #{PKG_VERSION}" lib/facter.rb}
267
- end
268
- end
269
- end
270
-
271
- desc "Tag all the SVN files with the latest release number (REL=x.y.z)"
272
- task :tag => [:prerelease] do
273
- reltag = "REL_#{PKG_VERSION.gsub(/\./, '_')}"
274
- reltag << ENV['REUSE'].gsub(/\./, '_') if ENV['REUSE']
275
- announce "Tagging SVN copy with [#{reltag}]"
276
- if ENV['RELTEST']
277
- announce "Release Task Testing, skipping SVN tagging"
278
- else
279
- sh %{svn copy ../trunk/ ../tags/#{reltag}}
280
- sh %{cd ../tags; svn ci -m 'Adding Release tag #{reltag}'}
281
- end
282
- end
283
-
284
- desc "Copy the newly created package into the downloads directory"
285
- task :copy => [:package, :html] do
286
- sh %{cp pkg/facter-#{PKG_VERSION}.gem #{DOWNDIR}/gems}
287
- sh %{generate_yaml_index.rb -d #{DOWNDIR}}
288
- sh %{cp pkg/facter-#{PKG_VERSION}.tgz #{DOWNDIR}/facter}
289
- sh %{ln -sf facter-#{PKG_VERSION}.tgz #{DOWNDIR}/facter/facter-latest.tgz}
290
- sh %{cp -r html #{DOWNDIR}/facter/apidocs}
291
- end
292
-
293
- # $Id$
46
+ # $Id: Rakefile 148 2006-06-27 05:34:07Z luke $
data/bin/facter CHANGED
@@ -1,13 +1,56 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- #--------------------
4
- # duh, it's facter!
5
2
  #
6
- # $Id: facter,v 1.1.1.1 2004/03/21 21:06:27 luke Exp $
3
+ # = Synopsis
4
+ #
5
+ # Collect and display facts about the system.
6
+ #
7
+ # = Usage
8
+ #
9
+ # facter [-d|--debug] [-h|--help] [-v|--version] [fact] [fact] [...]
10
+ #
11
+ # = Description
12
+ #
13
+ # Collect and display facts about the current system. The library behind
14
+ # Facter is easy to expand, making Facter an easy way to collect information
15
+ # about a system from within the shell or within Ruby.
16
+ #
17
+ # If no facts are specifically asked for, then all facts will be returned.
18
+ #
19
+ # = Options
20
+ #
21
+ # debug::
22
+ # Enable debugging.
23
+ #
24
+ # help::
25
+ # Print this help message
26
+ #
27
+ # version::
28
+ # Print the version and exit.
29
+ #
30
+ # = Example
31
+ #
32
+ # facter kernel
33
+ #
34
+ # = Author
35
+ #
36
+ # Luke Kanies
37
+ #
38
+ # = Copyright
39
+ #
40
+ # Copyright (c) 2006 Reductive Labs, LLC
41
+ # Licensed under the GNU Public License
7
42
 
8
43
  require 'getoptlong'
9
44
  require 'facter'
10
45
 
46
+ $haveusage = true
47
+
48
+ begin
49
+ require 'rdoc/usage'
50
+ rescue LoadError
51
+ $haveusage = false
52
+ end
53
+
11
54
  $debug = 0
12
55
 
13
56
  config = nil
@@ -27,8 +70,12 @@ result.each { |opt,arg|
27
70
  when "--debug"
28
71
  Facter.debugging(1)
29
72
  when "--help"
30
- puts "There is no help yet"
31
- exit
73
+ if $haveusage
74
+ RDoc::usage && exit
75
+ else
76
+ puts "No help available unless you have RDoc::usage installed"
77
+ exit
78
+ end
32
79
  else
33
80
  $stderr.puts "Invalid option '#{opt}'"
34
81
  exit(12)
@@ -67,5 +114,11 @@ else
67
114
  end
68
115
 
69
116
  facts.each { |name,value|
70
- puts "%s => %s" % [name,value]
117
+ if facts.length == 1
118
+ puts value
119
+ else
120
+ puts "%s => %s" % [name,value]
121
+ end
71
122
  }
123
+
124
+ # $Id: facter,v 1.1.1.1 2004/03/21 21:06:27 luke Exp $
data/install.rb CHANGED
@@ -1,289 +1,303 @@
1
- #! /usr/bin/env ruby
2
- #--
3
- # Copyright 2004 Austin Ziegler <ruby-install@halostatue.ca>
4
- # Install utility. Based on the original installation script for rdoc by the
5
- # Pragmatic Programmers.
6
- #
7
- # This program is free software. It may be redistributed and/or modified under
8
- # the terms of the GPL version 2 (or later) or the Ruby licence.
9
- #
10
- # Usage
11
- # -----
12
- # In most cases, if you have a typical project layout, you will need to do
13
- # absolutely nothing to make this work for you. This layout is:
14
- #
15
- # bin/ # executable files -- "commands"
16
- # lib/ # the source of the library
17
- # tests/ # unit tests
18
- #
19
- # The default behaviour:
20
- # 1) Run all unit test files (ending in .rb) found in all directories under
21
- # tests/.
22
- # 2) Build Rdoc documentation from all files in bin/ (excluding .bat and .cmd),
23
- # all .rb files in lib/, ./README, ./ChangeLog, and ./Install.
24
- # 3) Build ri documentation from all files in bin/ (excluding .bat and .cmd),
25
- # and all .rb files in lib/. This is disabled by default on Win32.
26
- # 4) Install commands from bin/ into the Ruby bin directory. On Windows, if a
27
- # if a corresponding batch file (.bat or .cmd) exists in the bin directory,
28
- # it will be copied over as well. Otherwise, a batch file (always .bat) will
29
- # be created to run the specified command.
30
- # 5) Install all library files ending in .rb from lib/ into Ruby's
31
- # site_lib/version directory.
32
- #
33
- # $Id: install.rb,v 1.6 2004/08/08 20:33:09 austin Exp $
34
- #++
35
-
36
- require 'rbconfig'
37
- require 'find'
38
- require 'fileutils'
39
- require 'optparse'
40
- require 'ostruct'
41
-
42
- InstallOptions = OpenStruct.new
43
-
44
- $loadedrdoc = false
45
-
46
- begin
47
- require 'rdoc/rdoc'
48
- $loadedrdoc = true
49
- rescue LoadError => detail
50
- $stderr.puts "Could not load rdoc/rdoc: %s" % detail
51
- InstallOptions.rdoc = false
52
- end
53
-
54
-
55
- def glob(list)
56
- g = list.map { |i| Dir.glob(i) }
57
- g.flatten!
58
- g.compact!
59
- g.reject! { |e| e =~ /CVS/ }
60
- g
61
- end
62
-
63
- # Set these values to what you want installed.
64
- #bins = glob(%w{bin/**/*}).reject { |e| e =~ /\.(bat|cmd)$/ }
65
- bins = ["bin/facter"]
66
- rdoc = glob(%w{bin/**/* lib/**/*.rb README CHANGELOG INSTALL}).reject { |e| e=~ /\.(bat|cmd)$/ }
67
- ri = glob(%w(bin/**/* lib/**/*.rb)).reject { |e| e=~ /\.(bat|cmd)$/ }
68
- libs = glob(%w{lib/**/*.rb})
69
- tests = glob(%w{tests/**/*.rb})
70
-
71
- def do_bins(bins, target, strip = 'bin/')
72
- bins.each do |bf|
73
- obf = bf.gsub(/#{strip}/, '')
74
- install_binfile(bf, obf, target)
75
- end
76
- end
77
-
78
- def do_libs(libs, strip = 'lib/')
79
- libs.each do |lf|
80
- olf = File.join(InstallOptions.site_dir, lf.gsub(/#{strip}/, ''))
81
- op = File.dirname(olf)
82
- #if File.respond_to?(:makedirs)
83
- FileUtils.makedirs(op)
84
- #else
85
- # recmkdir(op)
86
- #end
87
- File.chmod(0755, op)
88
- FileUtils.install(lf, olf, :mode => 0755, :verbose => true)
89
- end
90
- end
91
-
92
- ##
93
- # Prepare the file installation.
94
- #
95
- def prepare_installation
96
- InstallOptions.rdoc = true
97
- if RUBY_PLATFORM == "i386-mswin32"
98
- InstallOptions.ri = false
99
- else
100
- InstallOptions.ri = true
101
- end
102
- InstallOptions.tests = true
103
-
104
- ARGV.options do |opts|
105
- opts.banner = "Usage: #{File.basename($0)} [options]"
106
- opts.separator ""
107
- opts.on('--[no-]rdoc', 'Prevents the creation of RDoc output.', 'Default on.') do |onrdoc|
108
- InstallOptions.rdoc = onrdoc
109
- end
110
- opts.on('--[no-]ri', 'Prevents the creation of RI output.', 'Default off on mswin32.') do |onri|
111
- InstallOptions.ri = onri
112
- end
113
- opts.on('--[no-]tests', 'Prevents the execution of unit tests.', 'Default on.') do |ontest|
114
- InstallOptions.tests = ontest
115
- end
116
- opts.on('--quick', 'Performs a quick installation. Only the', 'installation is done.') do |quick|
117
- InstallOptions.rdoc = false
118
- InstallOptions.ri = false
119
- InstallOptions.tests = false
120
- end
121
- opts.on('--full', 'Performs a full installation. All', 'optional installation steps are run.') do |full|
122
- InstallOptions.rdoc = true
123
- InstallOptions.ri = true
124
- InstallOptions.tests = true
125
- end
126
- opts.separator("")
127
- opts.on_tail('--help', "Shows this help text.") do
128
- $stderr.puts opts
129
- exit
130
- end
131
-
132
- opts.parse!
133
- end
134
-
135
- bds = [".", ENV['TMP'], ENV['TEMP'], "/tmp"]
136
-
137
- version = [Config::CONFIG["MAJOR"], Config::CONFIG["MINOR"]].join(".")
138
- ld = File.join(Config::CONFIG["libdir"], "ruby", version)
139
-
140
- sd = Config::CONFIG["sitelibdir"]
141
- if sd.nil?
142
- sd = $:.find { |x| x =~ /site_ruby/ }
143
- if sd.nil?
144
- sd = File.join(ld, "site_ruby")
145
- elsif sd !~ Regexp.quote(version)
146
- sd = File.join(sd, version)
147
- end
148
- end
149
-
150
- if (destdir = ENV['DESTDIR'])
151
- bd = "#{destdir}#{Config::CONFIG['bindir']}"
152
- sd = "#{destdir}#{sd}"
153
- bds << bd
154
-
155
- FileUtils.makedirs(bd)
156
- FileUtils.makedirs(sd)
157
- else
158
- bds << Config::CONFIG['bindir']
159
- end
160
-
161
- InstallOptions.bin_dirs = bds.compact
162
- InstallOptions.site_dir = sd
163
- InstallOptions.bin_dir = bd
164
- InstallOptions.lib_dir = ld
165
-
166
- unless $loadedrdoc
167
- InstallOptions.rdoc = false
168
- InstallOptions.ri = false
169
- end
170
- end
171
-
172
- ##
173
- # Build the rdoc documentation. Also, try to build the RI documentation.
174
- #
175
- def build_rdoc(files)
176
- r = RDoc::RDoc.new
177
- r.document(["--main", "README", "--title", "Facter -- A Fact Collecter",
178
- "--line-numbers"] + files)
179
-
180
- rescue RDoc::RDocError => e
181
- $stderr.puts e.message
182
- rescue Exception => e
183
- $stderr.puts "Couldn't build RDoc documentation\n#{e.message}"
184
- end
185
-
186
- def build_ri(files)
187
- ri = RDoc::RDoc.new
188
- ri.document(["--ri-site", "--merge"] + files)
189
- rescue RDoc::RDocError => e
190
- $stderr.puts e.message
191
- rescue Exception => e
192
- $stderr.puts e.class
193
- $stderr.puts "Couldn't build Ri documentation\n#{e.message}"
194
- end
195
-
196
- def run_tests(test_list)
197
- begin
198
- require 'test/unit/ui/console/testrunner'
199
- $:.unshift "lib"
200
- test_list.each do |test|
201
- next if File.directory?(test)
202
- require test
203
- end
204
-
205
- tests = []
206
- ObjectSpace.each_object { |o| tests << o if o.kind_of?(Class) }
207
- tests.delete_if { |o| !o.ancestors.include?(Test::Unit::TestCase) }
208
- tests.delete_if { |o| o == Test::Unit::TestCase }
209
-
210
- tests.each { |test| Test::Unit::UI::Console::TestRunner.run(test) }
211
- $:.shift
212
- rescue LoadError
213
- puts "Missing testrunner library; skipping tests"
214
- end
215
- end
216
-
217
- ##
218
- # Install file(s) from ./bin to Config::CONFIG['bindir']. Patch it on the way
219
- # to insert a #! line; on a Unix install, the command is named as expected
220
- # (e.g., bin/rdoc becomes rdoc); the shebang line handles running it. Under
221
- # windows, we add an '.rb' extension and let file associations do their stuff.
222
- def install_binfile(from, op_file, target)
223
- tmp_dir = nil
224
- InstallOptions.bin_dirs.each do |t|
225
- if File.directory?(t) and File.writable_real?(t)
226
- tmp_dir = t
227
- break
228
- end
229
- end
230
-
231
- fail "Cannot find a temporary directory" unless tmp_dir
232
- tmp_file = File.join(tmp_dir, '_tmp')
233
- ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
234
-
235
- File.open(from) do |ip|
236
- File.open(tmp_file, "w") do |op|
237
- ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
238
- op.puts "#!#{ruby}"
239
- op.write ip.read
240
- end
241
- end
242
-
243
- if Config::CONFIG["target_os"] =~ /win/io
244
- installed_wrapper = false
245
-
246
- if File.exists?("#{from}.bat")
247
- FileUtils.install("#{from}.bat", File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
248
- installed_wrapper = true
249
- end
250
-
251
- if File.exists?("#{from}.cmd")
252
- FileUtils.install("#{from}.cmd", File.join(target, "#{op_file}.cmd"), :mode => 0755, :verbose => true)
253
- installed_wrapper = true
254
- end
255
-
256
- if not installed_wrapper
257
- tmp_file2 = File.join(tmp_dir, '_tmp_wrapper')
258
- cwn = File.join(Config::CONFIG['bindir'], op_file)
259
- cwv = CMD_WRAPPER.gsub('<ruby>', ruby.gsub(%r{/}) { "\\" }).gsub!('<command>', cwn.gsub(%r{/}) { "\\" } )
260
-
261
- File.open(tmp_file2, "wb") { |cw| cw.puts cwv }
262
- FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
263
-
264
- File.unlink(tmp_file2)
265
- installed_wrapper = true
266
- end
267
- end
268
- FileUtils.install(tmp_file, File.join(target, op_file), :mode => 0755, :verbose => true)
269
- File.unlink(tmp_file)
270
- end
271
-
272
- CMD_WRAPPER = <<-EOS
273
- @echo off
274
- if "%OS%"=="Windows_NT" goto WinNT
275
- <ruby> -x "<command>" %1 %2 %3 %4 %5 %6 %7 %8 %9
276
- goto done
277
- :WinNT
278
- <ruby> -x "<command>" %*
279
- goto done
280
- :done
281
- EOS
282
-
283
- prepare_installation
284
-
285
- run_tests(tests) if InstallOptions.tests
286
- #build_rdoc(rdoc) if InstallOptions.rdoc
287
- #build_ri(ri) if InstallOptions.ri
288
- do_bins(bins, Config::CONFIG['bindir'])
289
- do_libs(libs)
1
+ #! /usr/bin/env ruby
2
+ #--
3
+ # Copyright 2004 Austin Ziegler <ruby-install@halostatue.ca>
4
+ # Install utility. Based on the original installation script for rdoc by the
5
+ # Pragmatic Programmers.
6
+ #
7
+ # This program is free software. It may be redistributed and/or modified under
8
+ # the terms of the GPL version 2 (or later) or the Ruby licence.
9
+ #
10
+ # Usage
11
+ # -----
12
+ # In most cases, if you have a typical project layout, you will need to do
13
+ # absolutely nothing to make this work for you. This layout is:
14
+ #
15
+ # bin/ # executable files -- "commands"
16
+ # lib/ # the source of the library
17
+ # tests/ # unit tests
18
+ #
19
+ # The default behaviour:
20
+ # 1) Run all unit test files (ending in .rb) found in all directories under
21
+ # tests/.
22
+ # 2) Build Rdoc documentation from all files in bin/ (excluding .bat and .cmd),
23
+ # all .rb files in lib/, ./README, ./ChangeLog, and ./Install.
24
+ # 3) Build ri documentation from all files in bin/ (excluding .bat and .cmd),
25
+ # and all .rb files in lib/. This is disabled by default on Win32.
26
+ # 4) Install commands from bin/ into the Ruby bin directory. On Windows, if a
27
+ # if a corresponding batch file (.bat or .cmd) exists in the bin directory,
28
+ # it will be copied over as well. Otherwise, a batch file (always .bat) will
29
+ # be created to run the specified command.
30
+ # 5) Install all library files ending in .rb from lib/ into Ruby's
31
+ # site_lib/version directory.
32
+ #
33
+ # $Id: install.rb,v 1.6 2004/08/08 20:33:09 austin Exp $
34
+ #++
35
+
36
+ require 'rbconfig'
37
+ require 'find'
38
+ require 'fileutils'
39
+ require 'optparse'
40
+ require 'ostruct'
41
+
42
+ InstallOptions = OpenStruct.new
43
+
44
+ $loadedrdoc = false
45
+
46
+ begin
47
+ require 'rdoc/rdoc'
48
+ $loadedrdoc = true
49
+ rescue LoadError => detail
50
+ $stderr.puts "Could not load rdoc/rdoc: %s" % detail
51
+ InstallOptions.rdoc = false
52
+ end
53
+
54
+
55
+ def glob(list)
56
+ g = list.map { |i| Dir.glob(i) }
57
+ g.flatten!
58
+ g.compact!
59
+ g.reject! { |e| e =~ /CVS/ }
60
+ g
61
+ end
62
+
63
+ # Set these values to what you want installed.
64
+ #bins = glob(%w{bin/**/*}).reject { |e| e =~ /\.(bat|cmd)$/ }
65
+ bins = ["bin/facter"]
66
+ rdoc = glob(%w{bin/**/* lib/**/*.rb README CHANGELOG INSTALL}).reject { |e| e=~ /\.(bat|cmd)$/ }
67
+ ri = glob(%w(bin/**/* lib/**/*.rb)).reject { |e| e=~ /\.(bat|cmd)$/ }
68
+ libs = glob(%w{lib/**/*.rb})
69
+ tests = glob(%w{tests/**/*.rb})
70
+
71
+ def do_bins(bins, target, strip = 'bin/')
72
+ bins.each do |bf|
73
+ obf = bf.gsub(/#{strip}/, '')
74
+ install_binfile(bf, obf, target)
75
+ end
76
+ end
77
+
78
+ def do_libs(libs, strip = 'lib/')
79
+ libs.each do |lf|
80
+ olf = File.join(InstallOptions.site_dir, lf.gsub(/#{strip}/, ''))
81
+ op = File.dirname(olf)
82
+ #if File.respond_to?(:makedirs)
83
+ FileUtils.makedirs(op)
84
+ #else
85
+ # recmkdir(op)
86
+ #end
87
+ File.chmod(0755, op)
88
+ FileUtils.install(lf, olf, :mode => 0755, :verbose => true)
89
+ end
90
+ end
91
+
92
+ ##
93
+ # Prepare the file installation.
94
+ #
95
+ def prepare_installation
96
+ InstallOptions.rdoc = true
97
+ if RUBY_PLATFORM == "i386-mswin32"
98
+ InstallOptions.ri = false
99
+ else
100
+ InstallOptions.ri = true
101
+ end
102
+ InstallOptions.tests = true
103
+
104
+ ARGV.options do |opts|
105
+ opts.banner = "Usage: #{File.basename($0)} [options]"
106
+ opts.separator ""
107
+ opts.on('--[no-]rdoc', 'Prevents the creation of RDoc output.', 'Default on.') do |onrdoc|
108
+ InstallOptions.rdoc = onrdoc
109
+ end
110
+ opts.on('--[no-]ri', 'Prevents the creation of RI output.', 'Default off on mswin32.') do |onri|
111
+ InstallOptions.ri = onri
112
+ end
113
+ opts.on('--[no-]tests', 'Prevents the execution of unit tests.', 'Default on.') do |ontest|
114
+ InstallOptions.tests = ontest
115
+ end
116
+ opts.on('--quick', 'Performs a quick installation. Only the', 'installation is done.') do |quick|
117
+ InstallOptions.rdoc = false
118
+ InstallOptions.ri = false
119
+ InstallOptions.tests = false
120
+ end
121
+ opts.on('--full', 'Performs a full installation. All', 'optional installation steps are run.') do |full|
122
+ InstallOptions.rdoc = true
123
+ InstallOptions.ri = true
124
+ InstallOptions.tests = true
125
+ end
126
+ opts.separator("")
127
+ opts.on_tail('--help', "Shows this help text.") do
128
+ $stderr.puts opts
129
+ exit
130
+ end
131
+
132
+ opts.parse!
133
+ end
134
+
135
+ bds = [".", ENV['TMP'], ENV['TEMP'], "/tmp"]
136
+
137
+ version = [Config::CONFIG["MAJOR"], Config::CONFIG["MINOR"]].join(".")
138
+ ld = File.join(Config::CONFIG["libdir"], "ruby", version)
139
+
140
+ sd = Config::CONFIG["sitelibdir"]
141
+ if sd.nil?
142
+ sd = $:.find { |x| x =~ /site_ruby/ }
143
+ if sd.nil?
144
+ sd = File.join(ld, "site_ruby")
145
+ elsif sd !~ Regexp.quote(version)
146
+ sd = File.join(sd, version)
147
+ end
148
+ end
149
+
150
+ if (destdir = ENV['DESTDIR'])
151
+ bd = "#{destdir}#{Config::CONFIG['bindir']}"
152
+ sd = "#{destdir}#{sd}"
153
+ bds << bd
154
+
155
+ FileUtils.makedirs(bd)
156
+ FileUtils.makedirs(sd)
157
+ else
158
+ bd = Config::CONFIG['bindir']
159
+ bds << Config::CONFIG['bindir']
160
+ end
161
+
162
+ InstallOptions.bin_dirs = bds.compact
163
+ InstallOptions.site_dir = sd
164
+ InstallOptions.bin_dir = bd
165
+ InstallOptions.lib_dir = ld
166
+
167
+ unless $loadedrdoc
168
+ InstallOptions.rdoc = false
169
+ InstallOptions.ri = false
170
+ end
171
+ end
172
+
173
+ ##
174
+ # Build the rdoc documentation. Also, try to build the RI documentation.
175
+ #
176
+ def build_rdoc(files)
177
+ r = RDoc::RDoc.new
178
+ r.document(["--main", "README", "--title", "Facter -- A Fact Collecter",
179
+ "--line-numbers"] + files)
180
+
181
+ rescue RDoc::RDocError => e
182
+ $stderr.puts e.message
183
+ rescue Exception => e
184
+ $stderr.puts "Couldn't build RDoc documentation\n#{e.message}"
185
+ end
186
+
187
+ def build_ri(files)
188
+ ri = RDoc::RDoc.new
189
+ ri.document(["--ri-site", "--merge"] + files)
190
+ rescue RDoc::RDocError => e
191
+ $stderr.puts e.message
192
+ rescue Exception => e
193
+ $stderr.puts e.class
194
+ $stderr.puts "Couldn't build Ri documentation\n#{e.message}"
195
+ end
196
+
197
+ def run_tests(test_list)
198
+ begin
199
+ 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
+ $:.unshift "lib"
206
+ test_list.each do |test|
207
+ next if File.directory?(test)
208
+ require test
209
+ end
210
+
211
+ tests = []
212
+ ObjectSpace.each_object { |o| tests << o if o.kind_of?(Class) }
213
+ tests.delete_if { |o| !o.ancestors.include?(Test::Unit::TestCase) }
214
+ tests.delete_if { |o| o == Test::Unit::TestCase }
215
+
216
+ tests.each { |test| Test::Unit::UI::Console::TestRunner.run(test) }
217
+ $:.shift
218
+ rescue LoadError
219
+ puts "Missing testrunner library; skipping tests"
220
+ end
221
+ end
222
+
223
+ ##
224
+ # Install file(s) from ./bin to Config::CONFIG['bindir']. Patch it on the way
225
+ # to insert a #! line; on a Unix install, the command is named as expected
226
+ # (e.g., bin/rdoc becomes rdoc); the shebang line handles running it. Under
227
+ # windows, we add an '.rb' extension and let file associations do their stuff.
228
+ def install_binfile(from, op_file, target)
229
+ tmp_dir = nil
230
+ InstallOptions.bin_dirs.each do |t|
231
+ if File.directory?(t) and File.writable_real?(t)
232
+ tmp_dir = t
233
+ break
234
+ end
235
+ end
236
+
237
+ fail "Cannot find a temporary directory" unless tmp_dir
238
+ tmp_file = File.join(tmp_dir, '_tmp')
239
+ ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
240
+
241
+ File.open(from) do |ip|
242
+ File.open(tmp_file, "w") do |op|
243
+ ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
244
+ op.puts "#!#{ruby}"
245
+ op.write ip.read
246
+ end
247
+ end
248
+
249
+ # We don't want bat files on darwin
250
+ if Config::CONFIG["target_os"] =~ /win/io and Config::CONFIG["target_os"] !~ /darwin/
251
+ installed_wrapper = false
252
+
253
+ if File.exists?("#{from}.bat")
254
+ FileUtils.install("#{from}.bat", File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
255
+ installed_wrapper = true
256
+ end
257
+
258
+ if File.exists?("#{from}.cmd")
259
+ FileUtils.install("#{from}.cmd", File.join(target, "#{op_file}.cmd"), :mode => 0755, :verbose => true)
260
+ installed_wrapper = true
261
+ end
262
+
263
+ if not installed_wrapper
264
+ tmp_file2 = File.join(tmp_dir, '_tmp_wrapper')
265
+ cwn = File.join(Config::CONFIG['bindir'], op_file)
266
+ cwv = CMD_WRAPPER.gsub('<ruby>', ruby.gsub(%r{/}) { "\\" }).gsub!('<command>', cwn.gsub(%r{/}) { "\\" } )
267
+
268
+ File.open(tmp_file2, "wb") { |cw| cw.puts cwv }
269
+ FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
270
+
271
+ File.unlink(tmp_file2)
272
+ installed_wrapper = true
273
+ end
274
+ end
275
+ FileUtils.install(tmp_file, File.join(target, op_file), :mode => 0755, :verbose => true)
276
+ File.unlink(tmp_file)
277
+ end
278
+
279
+ CMD_WRAPPER = <<-EOS
280
+ @echo off
281
+ if "%OS%"=="Windows_NT" goto WinNT
282
+ <ruby> -x "<command>" %1 %2 %3 %4 %5 %6 %7 %8 %9
283
+ goto done
284
+ :WinNT
285
+ <ruby> -x "<command>" %*
286
+ goto done
287
+ :done
288
+ EOS
289
+
290
+ prepare_installation
291
+
292
+ run_tests(tests) if InstallOptions.tests
293
+ #build_rdoc(rdoc) if InstallOptions.rdoc
294
+ #build_ri(ri) if InstallOptions.ri
295
+ bd = nil
296
+ #if (destdir = ENV['DESTDIR'])
297
+ # bd = "#{destdir}#{Config::CONFIG['bindir']}"
298
+ #else
299
+ # bd = "#{Config::CONFIG['bindir']}"
300
+ #end
301
+
302
+ do_bins(bins, InstallOptions.bin_dir)
303
+ do_libs(libs)