[Pkg-puppet-devel] [SCM] Packaging of Facter for debian branch, master, updated. debian/1.5.6-1
Micah Anderson
micah at riseup.net
Tue Jun 30 03:28:44 UTC 2009
The following commit has been merged in the master branch:
commit 4daf6be987f8a05a2bafda50757d402b5f15de00
Author: Micah Anderson <micah at riseup.net>
Date: Mon Jun 29 22:55:07 2009 -0400
update to 1.5.6 upstream release
diff --git a/CHANGELOG b/CHANGELOG
index fc0d4d7..141661d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,15 +1,73 @@
+1.5.6:
+ Bug #2303: Add executable facter in spec
+
+ Bug #2307: undefined local variable or method `zone'
+
+1.5.5:
+ Bug #2291 (Closed): Fix operatingsystemrelease for CentOS < 5
+
+ Bug #2278 (Closed): Virtual fact incorrect on Solaris sparc
+
+ Cleaned up Rakefile and removed requirement for Reductive Labs build library
+
+ Fixed #2131 (Closed): Facter doesn't populate lsbmajdistrelease on OEL
+
+ Fixed #2214 (Closed): Identify Oracle VM properly
+
+ Fixed #2231: ipaddress_pcn0 fact no longer exists on Solaris systems
+
+ Fixed #2236 (Closed): macaddress fact uses each_line on arrays
+
+ Fixed #1918 - facter --puppet doesn't work
+
+ Fixed #2011 - virtual fact reports always vserver_host if /proc/virtual
+
+ Fixed #2021 - Returning boolean not always possible
+
+ Fixed #2132 - Support for named interfaces under Linux
+
+ Fixed #1327 - Added SELinux facts
+
+ Fixed #2119 - Added support for non-global Solaris 10 zones
+
+ Fixed #2080 - IPAddress resolutions should be reordered
+
+ Fixed #2078 - ip.rb errors command not found
+
+ Fixed #2058 - Redirecting stderr doesn't work on all systems
+
+ Fixed #2081 - Fixed interfaces fact for vlan subinterfaces
+
+ Fixed #2063 - added kernelmajversion fact
+
+ Fixed #2055 - SunoS Interface error
+
+ Fixed #2044 - fixed virtual fact
+
+ Fixed lib install permissions
+
+ Fixed #2040 - Facter should provide a macosx_productversion_major fact
+
+ Fixed #2003 - Added is_virtual fact
+
+ Fixed #2035 - Missing brace for OSX preflight
+
+ Added EC2 facts
+
+ Fixed #2032 - file.open hanging on /proc/uptime on some platform
+
1.5.4:
Fixed #1966 - Added physicalprocessorcount fact
Fixed #1761 - changes to Solaris facts:
operatingsystemrelease == kernel release or uname -r
- kernelrelease == uname -r
+ kernelrelease == uname -r
kernelversion == uname -v
Added support for Oracle VM Server to operatingsystem
and operatingsystemrelease
- Added support for Oracle Enterprise Linux to operatingsystem
+ Added support for Oracle Enterprise Linux to operatingsystem
and operatingsystemrelease
Fixed #1927 - failing facts don't kill Facter
@@ -42,19 +100,19 @@
Added ci namespace and Rake tasks
- Fixed #1650 - OS X package creation script should be more selective
+ Fixed #1650 - OS X package creation script should be more selective
about cleaning out prior versions
Added Ubuntu to a variety of confines
Fixed #1619 - Applying patch by seanmil, adding support for SLES.
-
- Fixed #1634 - Update virtual fact to differentiate OpenVZ
+
+ Fixed #1634 - Update virtual fact to differentiate OpenVZ
hardware nodes and virtual environments
Fixed #1509 - Fixed version recognition for SLES.
- Fixes #1582 - Fix MAC address reporting for Linux bonding
+ Fixes #1582 - Fix MAC address reporting for Linux bonding
slave interfaces
Fixed #1575 - CentOS fix for Facter SPEC file
@@ -110,8 +168,8 @@
Fixes #1467 - macaddress not set on Ubuntu
- Enabled a number of Windows facts - operating system, domain, ipaddress, macaddress,
- kernel, ipconfig and others
+ Enabled a number of Windows facts - operating system, domain, ipaddress, macaddress,
+ kernel, ipconfig and others
1.5.0:
Fixed Rakefile to include additional files including tests et al
@@ -140,7 +198,7 @@
Add lsbmajdistrelease fact for CentOS and Red Hat
- Updated Red Hat spec file for new version
+ Updated Red Hat spec file for new version
The 'facter' executable now has an option (-p|--puppet) for loading the
Puppet libraries, which gives it access to Puppet's facts.
@@ -152,22 +210,22 @@
Significantly refactored Facter's internals, including creating tests
for all internal classes.
- A netmask fact has been added closing ticket #46. It only returns the
- netmask of the primary interface (in the same behaviour as the ipaddress
+ A netmask fact has been added closing ticket #46. It only returns the
+ netmask of the primary interface (in the same behaviour as the ipaddress
and macaddress facts).
- Facts to return multiple interfaces on a host have also been updated.
- If you have multiple interfaces on Linux, *BSD, or Solaris/SunOS you will
- now get facts for each interface's IP address, MAC address and netmask.
+ Facts to return multiple interfaces on a host have also been updated.
+ If you have multiple interfaces on Linux, *BSD, or Solaris/SunOS you will
+ now get facts for each interface's IP address, MAC address and netmask.
The facts will be structured like:
ipaddress_int = 10.0.0.x
macaddress_int = xx:xx:xx:xx
netmask_int = 255.255.255.0
- Facter now identifies Ubuntu hosts and their releases using the
+ Facter now identifies Ubuntu hosts and their releases using the
operatingsystem and operatingsystemrelease facts.
- The Debian operatingsystemrelease fact now correctly returns the current
+ The Debian operatingsystemrelease fact now correctly returns the current
Debian release.
Fixed ticket #48 - ioperatingsystem and operatingsystemrelease for CentOS
@@ -181,16 +239,16 @@
Fixed ticket #45
- Added netmask.rb closing ticket #46
+ Added netmask.rb closing ticket #46
1.3.8:
Fixed Rdoc::usage bug on CentOS 5 - closed Puppet #753 and Facter #40
- Added support to return multiple interfaces and their IP addresses and
- MAC addressess as facts. Returns interface_interfacename and
- macaddress_interfacename. Existing ipaddress and macaddress facts are
+ Added support to return multiple interfaces and their IP addresses and
+ MAC addressess as facts. Returns interface_interfacename and
+ macaddress_interfacename. Existing ipaddress and macaddress facts are
unchanged and still returned. Currently Linux only. Closes #6.
-
+
Added macaddress fact support for FreeBSD and OpenBSD - closes #37
Added hardwareisa support for *BSD platforms - closed #38
@@ -284,4 +342,4 @@
adding new fact resolution mechanisms at run-time.
1.0b1:
- Initial release.
+ Initial release.
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..3912109
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/Rakefile b/Rakefile
index b302c0c..0976b9e 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,70 +1,76 @@
# Rakefile for facter
-$LOAD_PATH << File.join(File.dirname(__FILE__), 'tasks')
-
-begin
- require 'rake/reductive'
-rescue LoadError
- $stderr.puts "You must have the Reductive build library in your RUBYLIB."
- exit(14)
+$: << File.expand_path('lib')
+
+require './lib/facter.rb'
+require 'rake'
+require 'rake/packagetask'
+require 'rake/gempackagetask'
+
+FILES = FileList[
+ '[A-Z]*',
+ 'install.rb',
+ 'bin/**/*',
+ 'lib/**/*',
+ 'conf/**/*',
+ 'etc/**/*',
+ 'spec/**/*'
+]
+
+spec = Gem::Specification.new do |spec|
+ spec.platform = Gem::Platform::RUBY
+ spec.name = 'facter'
+ spec.files = FILES.to_a
+ spec.executables = %w{facter}
+ spec.version = Facter::FACTERVERSION
+ spec.summary = 'Facter, a system inventory tool'
+ spec.author = 'Reductive Labs'
+ spec.email = 'puppet at reductivelabs.com'
+ spec.homepage = 'http://reductivelabs.com'
+ spec.rubyforge_project = 'facter'
+ spec.has_rdoc = true
+ spec.rdoc_options <<
+ '--title' << 'Facter - System Inventory Tool' <<
+ '--main' << 'README' <<
+ '--line-numbers'
end
-project = Rake::RedLabProject.new("facter") do |p|
- p.summary = "Facter collects Operating system facts."
- p.description = <<-EOF
- Facter is a module for collecting simple facts about a host
- Operating system.
- EOF
-
- p.filelist = [
- 'install.rb',
- '[A-Z]*',
- 'bin/**/*',
- 'lib/facter.rb',
- 'lib/**/*.rb',
- 'test/**/*.rb',
- 'spec/**/*',
- 'conf/**/*',
- 'documentation/**/*',
- 'etc/*'
- ]
-
+Rake::PackageTask.new("facter", Facter::FACTERVERSION) do |pkg|
+ pkg.package_dir = 'pkg'
+ pkg.need_tar_gz = true
+ pkg.package_files = FILES.to_a
end
-project.mkgemtask do |gem|
- gem.require_path = 'lib' # Use these for libraries.
-
- gem.bindir = "bin" # Use these for applications.
- gem.executables = ["facter"]
- gem.default_executable = "facter"
-
- gem.author = "Luke Kanies"
+Rake::GemPackageTask.new(spec) do |pkg|
end
-task :archive do
- raise ArgumentError, "You must specify the archive name by setting ARCHIVE; e.g., ARCHIVE=1.5.1rc1" unless archive = ENV["ARCHIVE"]
-
- sh "git archive --format=tar --prefix=facter-#{archive}/ HEAD | gzip -c > facter-#{archive}.tgz"
+desc "Run the specs under spec/"
+task :spec do
+ require 'spec'
+ require 'spec/rake/spectask'
+ # require 'rcov'
+ Spec::Rake::SpecTask.new do |t|
+ t.spec_opts = ['--format','s', '--loadby','mtime']
+ t.spec_files = FileList['spec/**/*.rb']
+ end
end
-namespace :ci do
-
- desc "Run the CI prep tasks"
- task :prep do
+desc "Prep CI RSpec tests"
+task :ci_prep do
require 'rubygems'
- gem 'ci_reporter'
- require 'ci/reporter/rake/rspec'
- require 'ci/reporter/rake/test_unit'
- ENV['CI_REPORTS'] = 'results'
- end
-
- desc "Run CI RSpec tests"
- task :spec => [:prep, 'ci:setup:rspec'] do
- sh "cd spec; rake all; exit 0"
- end
-
+ begin
+ gem 'ci_reporter'
+ require 'ci/reporter/rake/rspec'
+ require 'ci/reporter/rake/test_unit'
+ ENV['CI_REPORTS'] = 'results'
+ rescue LoadError
+ puts 'Missing ci_reporter gem. You must have the ci_reporter gem installed to run the CI spec tests'
+ end
end
+desc "Run the CI RSpec tests"
+task :ci_spec => [:ci_prep, 'ci:setup:rpsec', :spec]
+
desc "Send patch information to the puppet-dev list"
task :mail_patches do
if Dir.glob("00*.patch").length > 0
@@ -75,7 +81,7 @@ task :mail_patches do
raise "Could not get branch from 'git status'"
end
branch = $1
-
+
unless branch =~ %r{^([^\/]+)/([^\/]+)/([^\/]+)$}
raise "Branch name does not follow <type>/<parent>/<name> model; cannot autodetect parent branch"
end
@@ -83,7 +89,7 @@ task :mail_patches do
type, parent, name = $1, $2, $3
# Create all of the patches
- sh "git format-patch -C -M -s -n #{parent}..HEAD"
+ sh "git format-patch -C -M -s -n --subject-prefix='PATCH/facter' #{parent}..HEAD"
# And then mail them out.
@@ -95,7 +101,7 @@ task :mail_patches do
end
# Now send the mail.
- sh "git send-email #{compose} --no-chain-reply-to --no-signed-off-by-cc --suppress-from --no-thread --to puppet-dev at googlegroups.com 00*.patch"
+ sh "git send-email #{compose} --no-signed-off-by-cc --suppress-from --to puppet-dev at googlegroups.com 00*.patch"
# Finally, clean up the patches
sh "rm 00*.patch"
diff --git a/autotest/discover.rb b/autotest/discover.rb
deleted file mode 100644
index 7cf0916..0000000
--- a/autotest/discover.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require 'autotest'
-
-Autotest.add_discovery do
- "rspec"
-end
-
-Autotest.add_discovery do
- "facter"
-end
diff --git a/autotest/facter_rspec.rb b/autotest/facter_rspec.rb
deleted file mode 100644
index 0ec65b0..0000000
--- a/autotest/facter_rspec.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-require 'autotest'
-require 'autotest/rspec'
-
-Autotest.add_hook :initialize do |at|
- at.clear_mappings
-
- # the libraries under lib/facter
- at.add_mapping(%r%^lib/facter/(.*)\.rb$%) { |filename, m|
- at.files_matching %r!spec/(unit|integration)/#{m[1]}.rb!
- }
-
- # the actual spec files themselves
- at.add_mapping(%r%^spec/(unit|integration)/.*\.rb$%) { |filename, _|
- filename
- }
-
- # force a complete re-run for all of these:
-
- # main facter lib
- at.add_mapping(%r!^lib/facter\.rb$!) { |filename, _|
- at.files_matching %r!spec/(unit|integration)/.*\.rb!
- }
-
- # the spec_helper
- at.add_mapping(%r!^spec/spec_helper\.rb$!) { |filename, _|
- at.files_matching %r!spec/(unit|integration)/.*\.rb!
- }
-
- # the facter spec libraries
- at.add_mapping(%r!^spec/lib/spec.*!) { |filename, _|
- at.files_matching %r!spec/(unit|integration)/.*\.rb!
- }
-
- # the monkey patches for rspec
- at.add_mapping(%r!^spec/lib/monkey_patches/.*!) { |filename, _|
- at.files_matching %r!spec/(unit|integration)/.*\.rb!
- }
-end
-
-class Autotest::FacterRspec < Autotest::Rspec
- def spec_commands
- ENV["AUTOTEST"] = "true"
- ENV["PATH"].split(File::PATH_SEPARATOR).collect { |dir| File.join(dir, "spec") }
- end
-end
diff --git a/autotest/rspec.rb b/autotest/rspec.rb
deleted file mode 100644
index ebafbfe..0000000
--- a/autotest/rspec.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-require 'autotest'
-
-Autotest.add_hook :initialize do |at|
- at.clear_mappings
- # watch out: Ruby bug (1.8.6):
- # %r(/) != /\//
- at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _|
- filename
- }
- at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
- ["spec/#{m[1]}_spec.rb"]
- }
- at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
- at.files_matching %r{^spec/.*_spec\.rb$}
- }
-end
-
-class RspecCommandError < StandardError; end
-
-class Autotest::Rspec < Autotest
-
- def initialize
- super
-
- self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m
- self.completed_re = /\Z/ # FIX: some sort of summary line at the end?
- end
-
- def consolidate_failures(failed)
- filters = Hash.new { |h,k| h[k] = [] }
- failed.each do |spec, failed_trace|
- if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then
- filters[f] << spec
- break
- end
- end
- return filters
- end
-
- def make_test_cmd(files_to_test)
- return "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}"
- end
-
- def add_options_if_present
- File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
- end
-
- # Finds the proper spec command to use. Precendence is set in the
- # lazily-evaluated method spec_commands. Alias + Override that in
- # ~/.autotest to provide a different spec command then the default
- # paths provided.
- def spec_command(separator=File::ALT_SEPARATOR)
- unless defined? @spec_command then
- @spec_command = spec_commands.find { |cmd| File.exists? cmd }
-
- raise RspecCommandError, "No spec command could be found!" unless @spec_command
-
- @spec_command.gsub! File::SEPARATOR, separator if separator
- end
- @spec_command
- end
-
- # Autotest will look for spec commands in the following
- # locations, in this order:
- #
- # * bin/spec
- # * default spec bin/loader installed in Rubygems
- def spec_commands
- [
- File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec')),
- File.join(Config::CONFIG['bindir'], 'spec')
- ]
- end
-end
diff --git a/bin/facter b/bin/facter
index 902bed9..4ffd50a 100755
--- a/bin/facter
+++ b/bin/facter
@@ -1,4 +1,4 @@
-#!/usr/bin/env ruby
+#!/usr/bin/env ruby
#
# = Synopsis
#
@@ -15,7 +15,7 @@
# about a system from within the shell or within Ruby.
#
# If no facts are specifically asked for, then all facts will be returned.
-#
+#
# = Options
#
# debug::
@@ -58,39 +58,52 @@ rescue Exception
$haveusage = false
end
+def load_puppet
+ require 'puppet'
+ Puppet.parse_config
+
+ # If you've set 'vardir' but not 'libdir' in your
+ # puppet.conf, then the hook to add libdir to $:
+ # won't get triggered. This makes sure that it's setup
+ # correctly.
+ unless $LOAD_PATH.include?(Puppet[:libdir])
+ $LOAD_PATH << Puppet[:libdir]
+ end
+end
+
$debug = 0
config = nil
result = GetoptLong.new(
- [ "--version", "-v", GetoptLong::NO_ARGUMENT ],
- [ "--help", "-h", GetoptLong::NO_ARGUMENT ],
- [ "--debug", "-d", GetoptLong::NO_ARGUMENT ],
- [ "--yaml", "-y", GetoptLong::NO_ARGUMENT ],
- [ "--config", "-c", GetoptLong::REQUIRED_ARGUMENT ],
- [ "--puppet", "-p", GetoptLong::NO_ARGUMENT ]
+ [ "--version", "-v", GetoptLong::NO_ARGUMENT ],
+ [ "--help", "-h", GetoptLong::NO_ARGUMENT ],
+ [ "--debug", "-d", GetoptLong::NO_ARGUMENT ],
+ [ "--yaml", "-y", GetoptLong::NO_ARGUMENT ],
+ [ "--config", "-c", GetoptLong::REQUIRED_ARGUMENT ],
+ [ "--puppet", "-p", GetoptLong::NO_ARGUMENT ]
)
options = {
:yaml => false
}
-begin
- result.each { |opt,arg|
- case opt
+begin
+ result.each { |opt,arg|
+ case opt
when "--version"
- puts "%s" % Facter.version
- exit
+ puts "%s" % Facter.version
+ exit
when "--puppet"
- begin
- require 'puppet'
+ begin
+ load_puppet()
rescue LoadError => detail
$stderr.puts "Could not load Puppet: %s" % detail
end
when "--yaml"
- options[:yaml] = true
+ options[:yaml] = true
when "--debug"
- Facter.debugging(1)
+ Facter.debugging(1)
when "--help"
if $haveusage
RDoc::usage && exit
@@ -101,24 +114,24 @@ begin
else
$stderr.puts "Invalid option '#{opt}'"
exit(12)
- end
- }
+ end
+ }
rescue
- exit(12)
+ exit(12)
end
names = []
unless config.nil?
- File.open(config) { |file|
- names = file.readlines.collect { |line|
- line.chomp
- }
- }
+ File.open(config) { |file|
+ names = file.readlines.collect { |line|
+ line.chomp
+ }
+ }
end
ARGV.each { |item|
- names.push item
+ names.push item
}
if names.empty?
diff --git a/conf/osx/PackageInfo.plist b/conf/osx/PackageInfo.plist
index 38b76d8..6668e2e 100644
--- a/conf/osx/PackageInfo.plist
+++ b/conf/osx/PackageInfo.plist
@@ -2,35 +2,35 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
- <key>CFBundleIdentifier</key>
- <string>com.reductivelabs.facter</string>
- <key>CFBundleShortVersionString</key>
- <string>{SHORTVERSION}</string>
- <key>IFMajorVersion</key>
- <integer>{MAJORVERSION}</integer>
- <key>IFMinorVersion</key>
- <integer>{MINORVERSION}</integer>
- <key>IFPkgFlagAllowBackRev</key>
- <false/>
- <key>IFPkgFlagAuthorizationAction</key>
- <string>RootAuthorization</string>
- <key>IFPkgFlagDefaultLocation</key>
- <string>/</string>
- <key>IFPkgFlagFollowLinks</key>
- <true/>
- <key>IFPkgFlagInstallFat</key>
- <false/>
- <key>IFPkgFlagIsRequired</key>
- <false/>
- <key>IFPkgFlagOverwritePermissions</key>
- <false/>
- <key>IFPkgFlagRelocatable</key>
- <false/>
- <key>IFPkgFlagRestartAction</key>
- <string>None</string>
- <key>IFPkgFlagRootVolumeOnly</key>
- <true/>
- <key>IFPkgFlagUpdateInstalledLanguages</key>
- <false/>
+ <key>CFBundleIdentifier</key>
+ <string>com.reductivelabs.facter</string>
+ <key>CFBundleShortVersionString</key>
+ <string>{SHORTVERSION}</string>
+ <key>IFMajorVersion</key>
+ <integer>{MAJORVERSION}</integer>
+ <key>IFMinorVersion</key>
+ <integer>{MINORVERSION}</integer>
+ <key>IFPkgFlagAllowBackRev</key>
+ <false/>
+ <key>IFPkgFlagAuthorizationAction</key>
+ <string>RootAuthorization</string>
+ <key>IFPkgFlagDefaultLocation</key>
+ <string>/</string>
+ <key>IFPkgFlagFollowLinks</key>
+ <true/>
+ <key>IFPkgFlagInstallFat</key>
+ <false/>
+ <key>IFPkgFlagIsRequired</key>
+ <false/>
+ <key>IFPkgFlagOverwritePermissions</key>
+ <false/>
+ <key>IFPkgFlagRelocatable</key>
+ <false/>
+ <key>IFPkgFlagRestartAction</key>
+ <string>None</string>
+ <key>IFPkgFlagRootVolumeOnly</key>
+ <true/>
+ <key>IFPkgFlagUpdateInstalledLanguages</key>
+ <false/>
</dict>
</plist>
diff --git a/conf/osx/createpackage.sh b/conf/osx/createpackage.sh
index 4e99c91..768380e 100755
--- a/conf/osx/createpackage.sh
+++ b/conf/osx/createpackage.sh
@@ -7,13 +7,13 @@
# Last Updated: 2008-07-31
#
# Copyright 2008 Google Inc.
-#
+#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,7 +30,7 @@ PREFLIGHT="preflight"
function find_installer() {
- # we walk up three directories to make this executable from the root,
+ # we walk up three directories to make this executable from the root,
# root/conf or root/conf/osx
if [ -f "./${INSTALLRB}" ]; then
installer="$(pwd)/${INSTALLRB}"
@@ -64,7 +64,7 @@ function prepare_package() {
# to look at for package creation and substitue the version strings out.
# Major/Minor versions can only be integers, so we have "1" and "50" for
# facter version 1.5
- # Note too that for 10.5 compatibility this Info.plist *must* be set to
+ # Note too that for 10.5 compatibility this Info.plist *must* be set to
# follow symlinks.
VER1=$(echo ${facter_version} | awk -F "." '{print $1}')
VER2=$(echo ${facter_version} | awk -F "." '{print $2}')
@@ -75,12 +75,12 @@ function prepare_package() {
sed -i '' "s/{SHORTVERSION}/${facter_version}/g" "${pkgtemp}/${PROTO_PLIST}"
sed -i '' "s/{MAJORVERSION}/${major_version}/g" "${pkgtemp}/${PROTO_PLIST}"
sed -i '' "s/{MINORVERSION}/${minor_version}/g" "${pkgtemp}/${PROTO_PLIST}"
-
+
# We need to create a preflight script to remove traces of previous
# facter installs due to limitations in Apple's pkg format.
mkdir "${pkgtemp}/scripts"
cp "${facter_root}/conf/osx/${PREFLIGHT}" "${pkgtemp}/scripts"
-
+
# substitute in the sitelibdir specified above on the assumption that this
# is where any previous facter install exists that should be cleaned out.
sed -i '' "s|{SITELIBDIR}|${SITELIBDIR}|g" "${pkgtemp}/scripts/${PREFLIGHT}"
@@ -124,44 +124,44 @@ function main() {
fi
find_installer
-
+
if [ ! "${installer}" ]; then
echo "Unable to find ${INSTALLRB}"
cleanup_and_exit 1
fi
find_facter_root
-
+
if [ ! "${facter_root}" ]; then
echo "Unable to find facter repository root."
cleanup_and_exit 1
fi
-
+
pkgroot=$(mktemp -d -t facterpkg)
-
+
if [ ! "${pkgroot}" ]; then
echo "Unable to create temporary package root."
cleanup_and_exit 1
fi
-
+
pkgtemp=$(mktemp -d -t factertmp)
-
+
if [ ! "${pkgtemp}" ]; then
echo "Unable to create temporary package root."
cleanup_and_exit 1
fi
-
+
install_facter
get_facter_version
-
+
if [ ! "${facter_version}" ]; then
echo "Unable to retrieve facter version"
cleanup_and_exit 1
fi
-
+
prepare_package
create_package
-
+
cleanup_and_exit 0
}
diff --git a/conf/osx/preflight b/conf/osx/preflight
index 9b2c07e..98251bf 100755
--- a/conf/osx/preflight
+++ b/conf/osx/preflight
@@ -9,4 +9,4 @@
# when being installed to volumes other than the current OS.
/bin/rm -Rf "${3}{SITELIBDIR}/facter"
-/bin/rm -Rf "${3}{SITELIBDIR/facter.rb"
+/bin/rm -Rf "${3}{SITELIBDIR}/facter.rb"
diff --git a/conf/redhat/facter.spec b/conf/redhat/facter.spec
index efcb7af..b907d5b 100644
--- a/conf/redhat/facter.spec
+++ b/conf/redhat/facter.spec
@@ -5,12 +5,12 @@
Summary: Ruby module for collecting simple facts about a host operating system
Name: facter
-Version: 1.5.2
+Version: 1.5.5
Release: 1%{?dist}
License: GPLv2+
Group: System Environment/Base
URL: http://reductivelabs.com/projects/facter
-Source0: http://reductivelabs.com/downloads/facter/%{name}-%{version}.tgz
+Source0: http://reductivelabs.com/downloads/facter/%{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
%if %has_ruby_noarch
BuildArch: noarch
@@ -32,24 +32,10 @@ operating system. Additional facts can be added through simple Ruby scripts
%setup -q
%build
-sed -i -e 's@^#!.*$@#! /usr/bin/ruby@' bin/facter
%install
rm -rf %{buildroot}
-mkdir -p %{buildroot}
-
-%{__install} -d -m0755 %{buildroot}%{ruby_sitelibdir}
-%{__install} -d -m0755 %{buildroot}%{ruby_sitelibdir}/facter
-%{__install} -d -m0755 %{buildroot}%{ruby_sitelibdir}/facter/util
-%{__install} -d -m0755 %{buildroot}%{ruby_sitelibdir}/facter/util/plist
-%{__install} -d -m0755 %{buildroot}%{_bindir}
-%{__install} -d -m0755 %{buildroot}%{_docdir}/%{name}-%{version}
-
-%{__install} -p -m0644 lib/*.rb %{buildroot}%{ruby_sitelibdir}
-%{__install} -p -m0644 lib/facter/*.rb %{buildroot}%{ruby_sitelibdir}/facter
-%{__install} -p -m0644 lib/facter/util/*.rb %{buildroot}%{ruby_sitelibdir}/facter/util
-%{__install} -p -m0644 lib/facter/util/plist/*.rb %{buildroot}%{ruby_sitelibdir}/facter/util/plist
-%{__install} -p -m0755 bin/facter %{buildroot}%{_bindir}
+ruby install.rb --destdir=%{buildroot} --quick --no-rdoc
%clean
rm -rf %{buildroot}
@@ -64,6 +50,14 @@ rm -rf %{buildroot}
%changelog
+* Fri May 22 2009 Todd Zullinger <tmz at pobox.com> - 1.5.5-1
+- Update to 1.5.5
+- Drop upstreamed libperms patch
+
+* Sat Feb 28 2009 Todd Zullinger <tmz at pobox.com> - 1.5.4-1
+- New version
+- Use upstream install script
+
* Tue Sep 09 2008 Todd Zullinger <tmz at pobox.com> - 1.5.2-1
- New version
- Simplify spec file checking for Fedora and RHEL versions
diff --git a/documentation/custom.page b/documentation/custom.page
deleted file mode 100644
index 0708a70..0000000
--- a/documentation/custom.page
+++ /dev/null
@@ -1,22 +0,0 @@
----
-inMenu: true
-directoryName: Custom Facts
----
-
-Facter does everything it can to make adding custom facts easy. It will
-autoload any files it finds in a ``facter/`` directory in its search
-path, so you don't need to modify the package files. Also, Facter will
-search through your environment for any variables whose names start with
-'FACTER_' (case insensitive) and automatically add those facts.
-
-As a simple example, here is how I publish my home directory to Puppet:
-
- Facter.add("home") do
- setcode do
- ENV['HOME']
- end
- end
-
-I have ~/lib/ruby in my $RUBYLIB environment variable, so I just created
-~/lib/ruby/facter and dropped the above code into a ``home.rb`` file
-within that directory.
diff --git a/documentation/index.page b/documentation/index.page
deleted file mode 100644
index c64938a..0000000
--- a/documentation/index.page
+++ /dev/null
@@ -1,19 +0,0 @@
----
-inMenu: false
-directoryName: Facter
----
-
-A cross-platform Ruby library for retrieving facts from operating systems.
-Supports multiple resolution mechanisms, any of which can be restricted to
-working only on certain operating systems or environments. Facter is especially
-useful for retrieving things like operating system names, IP addresses, MAC
-addresses, and SSH keys.
-
-It is easy to extend Facter to include your own [custom facts](custom.html) or
-to include additional mechanisms for retrieving facts.
-
-* [Downloads](/downloads/facter/)
-* [Bug Tracking](/cgi-bin/facter.cgi)
-* [API Documentation](/downloads/facter/apidocs/)
-
-*$Id$*
diff --git a/install.rb b/install.rb
index 3e0d810..3be8952 100755
--- a/install.rb
+++ b/install.rb
@@ -81,33 +81,33 @@ libs = glob(%w{lib/**/*.rb lib/**/*.py})
tests = glob(%w{tests/**/*.rb})
def do_bins(bins, target, strip = 's?bin/')
- bins.each do |bf|
- obf = bf.gsub(/#{strip}/, '')
- install_binfile(bf, obf, target)
- end
+ bins.each do |bf|
+ obf = bf.gsub(/#{strip}/, '')
+ install_binfile(bf, obf, target)
+ end
end
def do_libs(libs, strip = 'lib/')
- libs.each do |lf|
- olf = File.join(InstallOptions.site_dir, lf.gsub(/#{strip}/, ''))
- op = File.dirname(olf)
- File.makedirs(op, true)
- File.chmod(0755, op)
- File.install(lf, olf, 0755, true)
- end
+ libs.each do |lf|
+ olf = File.join(InstallOptions.site_dir, lf.gsub(/#{strip}/, ''))
+ op = File.dirname(olf)
+ File.makedirs(op, true)
+ File.chmod(0755, op)
+ File.install(lf, olf, 0644, true)
+ end
end
def do_man(man, strip = 'man/')
- man.each do |mf|
- omf = File.join(InstallOptions.man_dir, mf.gsub(/#{strip}/, ''))
- om = File.dirname(omf)
- File.makedirs(om, true)
- File.chmod(0644, om)
- File.install(mf, omf, 0644, true)
- gzip = %x{which gzip}
- gzip.chomp!
- %x{#{gzip} -f #{omf}}
- end
+ man.each do |mf|
+ omf = File.join(InstallOptions.man_dir, mf.gsub(/#{strip}/, ''))
+ om = File.dirname(omf)
+ File.makedirs(om, true)
+ File.chmod(0644, om)
+ File.install(mf, omf, 0644, true)
+ gzip = %x{which gzip}
+ gzip.chomp!
+ %x{#{gzip} -f #{omf}}
+ end
end
# Verify that all of the prereqs are installed
@@ -126,158 +126,158 @@ end
# Prepare the file installation.
#
def prepare_installation
- # Only try to do docs if we're sure they have rdoc
- if $haverdoc
- InstallOptions.rdoc = true
- if RUBY_PLATFORM == "i386-mswin32"
+ # Only try to do docs if we're sure they have rdoc
+ if $haverdoc
+ InstallOptions.rdoc = true
+ if RUBY_PLATFORM == "i386-mswin32"
+ InstallOptions.ri = false
+ else
+ InstallOptions.ri = true
+ end
+ else
+ InstallOptions.rdoc = false
InstallOptions.ri = false
- else
- InstallOptions.ri = true
- end
- else
- InstallOptions.rdoc = false
- InstallOptions.ri = false
- end
-
-
- if $haveman
- InstallOptions.man = true
- if RUBY_PLATFORM == "i386-mswin32"
- InstallOptions.man = false
- end
- else
- InstallOptions.man = false
- end
-
- InstallOptions.tests = true
-
- ARGV.options do |opts|
- opts.banner = "Usage: #{File.basename($0)} [options]"
- opts.separator ""
- opts.on('--[no-]rdoc', 'Prevents the creation of RDoc output.', 'Default on.') do |onrdoc|
- InstallOptions.rdoc = onrdoc
- end
- opts.on('--[no-]ri', 'Prevents the creation of RI output.', 'Default off on mswin32.') do |onri|
- InstallOptions.ri = onri
end
- opts.on('--[no-]man', 'Presents the creation of man pages.', 'Default on.') do |onman|
- InstallOptions.man = onman
- end
- opts.on('--[no-]tests', 'Prevents the execution of unit tests.', 'Default on.') do |ontest|
- InstallOptions.tests = ontest
- end
- opts.on('--destdir[=OPTIONAL]', 'Installation prefix for all targets', 'Default essentially /') do |destdir|
- InstallOptions.destdir = destdir
- end
- opts.on('--bindir[=OPTIONAL]', 'Installation directory for binaries', 'overrides Config::CONFIG["bindir"]') do |bindir|
- InstallOptions.bindir = bindir
+
+
+ if $haveman
+ InstallOptions.man = true
+ if RUBY_PLATFORM == "i386-mswin32"
+ InstallOptions.man = false
+ end
+ else
+ InstallOptions.man = false
end
- opts.on('--sbindir[=OPTIONAL]', 'Installation directory for system binaries', 'overrides Config::CONFIG["sbindir"]') do |sbindir|
- InstallOptions.sbindir = sbindir
+
+ InstallOptions.tests = true
+
+ ARGV.options do |opts|
+ opts.banner = "Usage: #{File.basename($0)} [options]"
+ opts.separator ""
+ opts.on('--[no-]rdoc', 'Prevents the creation of RDoc output.', 'Default on.') do |onrdoc|
+ InstallOptions.rdoc = onrdoc
+ end
+ opts.on('--[no-]ri', 'Prevents the creation of RI output.', 'Default off on mswin32.') do |onri|
+ InstallOptions.ri = onri
+ end
+ opts.on('--[no-]man', 'Presents the creation of man pages.', 'Default on.') do |onman|
+ InstallOptions.man = onman
+ end
+ opts.on('--[no-]tests', 'Prevents the execution of unit tests.', 'Default on.') do |ontest|
+ InstallOptions.tests = ontest
+ end
+ opts.on('--destdir[=OPTIONAL]', 'Installation prefix for all targets', 'Default essentially /') do |destdir|
+ InstallOptions.destdir = destdir
+ end
+ opts.on('--bindir[=OPTIONAL]', 'Installation directory for binaries', 'overrides Config::CONFIG["bindir"]') do |bindir|
+ InstallOptions.bindir = bindir
+ end
+ opts.on('--sbindir[=OPTIONAL]', 'Installation directory for system binaries', 'overrides Config::CONFIG["sbindir"]') do |sbindir|
+ InstallOptions.sbindir = sbindir
+ end
+ opts.on('--sitelibdir[=OPTIONAL]', 'Installation directory for libraries', 'overrides Config::CONFIG["sitelibdir"]') do |sitelibdir|
+ InstallOptions.sitelibdir = sitelibdir
+ end
+ opts.on('--mandir[=OPTIONAL]', 'Installation directory for man pages', 'overrides Config::CONFIG["mandir"]') do |mandir|
+ InstallOptions.mandir = mandir
+ end
+ opts.on('--quick', 'Performs a quick installation. Only the', 'installation is done.') do |quick|
+ InstallOptions.rdoc = false
+ InstallOptions.ri = false
+ InstallOptions.tests = false
+ end
+ opts.on('--full', 'Performs a full installation. All', 'optional installation steps are run.') do |full|
+ InstallOptions.rdoc = true
+ InstallOptions.ri = true
+ InstallOptions.tests = true
+ end
+ opts.separator("")
+ opts.on_tail('--help', "Shows this help text.") do
+ $stderr.puts opts
+ exit
+ end
+
+ opts.parse!
end
- opts.on('--sitelibdir[=OPTIONAL]', 'Installation directory for libraries', 'overrides Config::CONFIG["sitelibdir"]') do |sitelibdir|
- InstallOptions.sitelibdir = sitelibdir
+
+ tmpdirs = [".", ENV['TMP'], ENV['TEMP'], "/tmp", "/var/tmp"]
+
+ version = [Config::CONFIG["MAJOR"], Config::CONFIG["MINOR"]].join(".")
+ libdir = File.join(Config::CONFIG["libdir"], "ruby", version)
+
+ # Mac OS X 10.5 declares bindir and sbindir as
+ # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin
+ # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/sbin
+ # which is not generally where people expect executables to be installed
+ if RUBY_PLATFORM == "universal-darwin9.0"
+ Config::CONFIG['bindir'] = "/usr/bin"
+ Config::CONFIG['sbindir'] = "/usr/sbin"
end
- opts.on('--mandir[=OPTIONAL]', 'Installation directory for man pages', 'overrides Config::CONFIG["mandir"]') do |mandir|
- InstallOptions.mandir = mandir
+
+ if not InstallOptions.bindir.nil?
+ bindir = InstallOptions.bindir
+ else
+ bindir = Config::CONFIG['bindir']
end
- opts.on('--quick', 'Performs a quick installation. Only the', 'installation is done.') do |quick|
- InstallOptions.rdoc = false
- InstallOptions.ri = false
- InstallOptions.tests = false
+
+ if not InstallOptions.sbindir.nil?
+ sbindir = InstallOptions.sbindir
+ else
+ sbindir = Config::CONFIG['sbindir']
end
- opts.on('--full', 'Performs a full installation. All', 'optional installation steps are run.') do |full|
- InstallOptions.rdoc = true
- InstallOptions.ri = true
- InstallOptions.tests = true
+
+ if not InstallOptions.sitelibdir.nil?
+ sitelibdir = InstallOptions.sitelibdir
+ else
+ sitelibdir = Config::CONFIG["sitelibdir"]
+ if sitelibdir.nil?
+ sitelibdir = $:.find { |x| x =~ /site_ruby/ }
+ if sitelibdir.nil?
+ sitelibdir = File.join(libdir, "site_ruby")
+ elsif sitelibdir !~ Regexp.quote(version)
+ sitelibdir = File.join(sitelibdir, version)
+ end
+ end
end
- opts.separator("")
- opts.on_tail('--help', "Shows this help text.") do
- $stderr.puts opts
- exit
+
+ if not InstallOptions.mandir.nil?
+ mandir = InstallOptions.mandir
+ else
+ mandir = Config::CONFIG['mandir']
end
- opts.parse!
- end
-
- tmpdirs = [".", ENV['TMP'], ENV['TEMP'], "/tmp", "/var/tmp"]
-
- version = [Config::CONFIG["MAJOR"], Config::CONFIG["MINOR"]].join(".")
- libdir = File.join(Config::CONFIG["libdir"], "ruby", version)
-
- # Mac OS X 10.5 declares bindir and sbindir as
- # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin
- # /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/sbin
- # which is not generally where people expect executables to be installed
- if RUBY_PLATFORM == "universal-darwin9.0"
- Config::CONFIG['bindir'] = "/usr/bin"
- Config::CONFIG['sbindir'] = "/usr/sbin"
- end
-
- if not InstallOptions.bindir.nil?
- bindir = InstallOptions.bindir
- else
- bindir = Config::CONFIG['bindir']
- end
-
- if not InstallOptions.sbindir.nil?
- sbindir = InstallOptions.sbindir
- else
- sbindir = Config::CONFIG['sbindir']
- end
-
- if not InstallOptions.sitelibdir.nil?
- sitelibdir = InstallOptions.sitelibdir
- else
- sitelibdir = Config::CONFIG["sitelibdir"]
- if sitelibdir.nil?
- sitelibdir = $:.find { |x| x =~ /site_ruby/ }
- if sitelibdir.nil?
- sitelibdir = File.join(libdir, "site_ruby")
- elsif sitelibdir !~ Regexp.quote(version)
- sitelibdir = File.join(sitelibdir, version)
- end
+ # To be deprecated once people move over to using --destdir option
+ if (destdir = ENV['DESTDIR'])
+ bindir = "#{destdir}#{bindir}"
+ sbindir = "#{destdir}#{sbindir}"
+ mandir = "#{destdir}#{mandir}"
+ sitelibdir = "#{destdir}#{sitelibdir}"
+
+ FileUtils.makedirs(bindir)
+ FileUtils.makedirs(sbindir)
+ FileUtils.makedirs(mandir)
+ FileUtils.makedirs(sitelibdir)
+ # This is the new way forward
+ elsif (destdir = InstallOptions.destdir)
+ bindir = "#{destdir}#{bindir}"
+ sbindir = "#{destdir}#{sbindir}"
+ mandir = "#{destdir}#{mandir}"
+ sitelibdir = "#{destdir}#{sitelibdir}"
+
+ FileUtils.makedirs(bindir)
+ FileUtils.makedirs(sbindir)
+ FileUtils.makedirs(mandir)
+ FileUtils.makedirs(sitelibdir)
end
- end
-
- if not InstallOptions.mandir.nil?
- mandir = InstallOptions.mandir
- else
- mandir = Config::CONFIG['mandir']
- end
-
- # To be deprecated once people move over to using --destdir option
- if (destdir = ENV['DESTDIR'])
- bindir = "#{destdir}#{bindir}"
- sbindir = "#{destdir}#{sbindir}"
- mandir = "#{destdir}#{mandir}"
- sitelibdir = "#{destdir}#{sitelibdir}"
-
- FileUtils.makedirs(bindir)
- FileUtils.makedirs(sbindir)
- FileUtils.makedirs(mandir)
- FileUtils.makedirs(sitelibdir)
- # This is the new way forward
- elsif (destdir = InstallOptions.destdir)
- bindir = "#{destdir}#{bindir}"
- sbindir = "#{destdir}#{sbindir}"
- mandir = "#{destdir}#{mandir}"
- sitelibdir = "#{destdir}#{sitelibdir}"
-
- FileUtils.makedirs(bindir)
- FileUtils.makedirs(sbindir)
- FileUtils.makedirs(mandir)
- FileUtils.makedirs(sitelibdir)
- end
-
- tmpdirs << bindir
-
- InstallOptions.tmp_dirs = tmpdirs.compact
- InstallOptions.site_dir = sitelibdir
- InstallOptions.bin_dir = bindir
- InstallOptions.sbin_dir = sbindir
- InstallOptions.lib_dir = libdir
- InstallOptions.man_dir = mandir
+
+ tmpdirs << bindir
+
+ InstallOptions.tmp_dirs = tmpdirs.compact
+ InstallOptions.site_dir = sitelibdir
+ InstallOptions.bin_dir = bindir
+ InstallOptions.sbin_dir = sbindir
+ InstallOptions.lib_dir = libdir
+ InstallOptions.man_dir = mandir
end
##
@@ -323,10 +323,10 @@ def build_man(bins)
# Create binary man pages
bins.each do |bin|
- b = bin.gsub( "bin/", "")
- %x{#{bin} --help > ./#{b}.rst}
- %x{#{rst2man} ./#{b}.rst ./man/man8/#{b}.8}
- File.unlink("./#{b}.rst")
+ b = bin.gsub( "bin/", "")
+ %x{#{bin} --help > ./#{b}.rst}
+ %x{#{rst2man} ./#{b}.rst ./man/man8/#{b}.8}
+ File.unlink("./#{b}.rst")
end
rescue SystemCallError
$stderr.puts "Couldn't build man pages: " + $!
@@ -335,24 +335,24 @@ def build_man(bins)
end
def run_tests(test_list)
- begin
- require 'test/unit/ui/console/testrunner'
- $:.unshift "lib"
- test_list.each do |test|
- next if File.directory?(test)
- require test
- end
-
- tests = []
- ObjectSpace.each_object { |o| tests << o if o.kind_of?(Class) }
- tests.delete_if { |o| !o.ancestors.include?(Test::Unit::TestCase) }
- tests.delete_if { |o| o == Test::Unit::TestCase }
-
- tests.each { |test| Test::Unit::UI::Console::TestRunner.run(test) }
- $:.shift
- rescue LoadError
- puts "Missing testrunner library; skipping tests"
- end
+ begin
+ require 'test/unit/ui/console/testrunner'
+ $:.unshift "lib"
+ test_list.each do |test|
+ next if File.directory?(test)
+ require test
+ end
+
+ tests = []
+ ObjectSpace.each_object { |o| tests << o if o.kind_of?(Class) }
+ tests.delete_if { |o| !o.ancestors.include?(Test::Unit::TestCase) }
+ tests.delete_if { |o| o == Test::Unit::TestCase }
+
+ tests.each { |test| Test::Unit::UI::Console::TestRunner.run(test) }
+ $:.shift
+ rescue LoadError
+ puts "Missing testrunner library; skipping tests"
+ end
end
##
@@ -361,57 +361,57 @@ end
# (e.g., bin/rdoc becomes rdoc); the shebang line handles running it. Under
# windows, we add an '.rb' extension and let file associations do their stuff.
def install_binfile(from, op_file, target)
- tmp_dir = nil
- InstallOptions.tmp_dirs.each do |t|
- if File.directory?(t) and File.writable?(t)
- tmp_dir = t
- break
+ tmp_dir = nil
+ InstallOptions.tmp_dirs.each do |t|
+ if File.directory?(t) and File.writable?(t)
+ tmp_dir = t
+ break
+ end
end
- end
-
- fail "Cannot find a temporary directory" unless tmp_dir
- tmp_file = File.join(tmp_dir, '_tmp')
- ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
-
- File.open(from) do |ip|
- File.open(tmp_file, "w") do |op|
- ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
- op.puts "#!#{ruby}"
- contents = ip.readlines
- if contents[0] =~ /^#!/
- contents.shift
- end
- op.write contents.join()
+
+ fail "Cannot find a temporary directory" unless tmp_dir
+ tmp_file = File.join(tmp_dir, '_tmp')
+ ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
+
+ File.open(from) do |ip|
+ File.open(tmp_file, "w") do |op|
+ ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
+ op.puts "#!#{ruby}"
+ contents = ip.readlines
+ if contents[0] =~ /^#!/
+ contents.shift
+ end
+ op.write contents.join()
+ end
end
- end
- if Config::CONFIG["target_os"] =~ /win/io and Config::CONFIG["target_os"] !~ /darwin/io
- installed_wrapper = false
+ if Config::CONFIG["target_os"] =~ /win/io and Config::CONFIG["target_os"] !~ /darwin/io
+ installed_wrapper = false
- if File.exists?("#{from}.bat")
- FileUtils.install("#{from}.bat", File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
- installed_wrapper = true
- end
+ if File.exists?("#{from}.bat")
+ FileUtils.install("#{from}.bat", File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
+ installed_wrapper = true
+ end
- if File.exists?("#{from}.cmd")
- FileUtils.install("#{from}.cmd", File.join(target, "#{op_file}.cmd"), :mode => 0755, :verbose => true)
- installed_wrapper = true
- end
+ if File.exists?("#{from}.cmd")
+ FileUtils.install("#{from}.cmd", File.join(target, "#{op_file}.cmd"), :mode => 0755, :verbose => true)
+ installed_wrapper = true
+ end
- if not installed_wrapper
- tmp_file2 = File.join(tmp_dir, '_tmp_wrapper')
- cwn = File.join(Config::CONFIG['bindir'], op_file)
- cwv = CMD_WRAPPER.gsub('<ruby>', ruby.gsub(%r{/}) { "\\" }).gsub!('<command>', cwn.gsub(%r{/}) { "\\" } )
+ if not installed_wrapper
+ tmp_file2 = File.join(tmp_dir, '_tmp_wrapper')
+ cwn = File.join(Config::CONFIG['bindir'], op_file)
+ cwv = CMD_WRAPPER.gsub('<ruby>', ruby.gsub(%r{/}) { "\\" }).gsub!('<command>', cwn.gsub(%r{/}) { "\\" } )
- File.open(tmp_file2, "wb") { |cw| cw.puts cwv }
- FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
+ File.open(tmp_file2, "wb") { |cw| cw.puts cwv }
+ FileUtils.install(tmp_file2, File.join(target, "#{op_file}.bat"), :mode => 0755, :verbose => true)
- File.unlink(tmp_file2)
- installed_wrapper = true
+ File.unlink(tmp_file2)
+ installed_wrapper = true
+ end
end
- end
- FileUtils.install(tmp_file, File.join(target, op_file), :mode => 0755, :verbose => true)
- File.unlink(tmp_file)
+ FileUtils.install(tmp_file, File.join(target, op_file), :mode => 0755, :verbose => true)
+ File.unlink(tmp_file)
end
CMD_WRAPPER = <<-EOS
diff --git a/lib/facter.rb b/lib/facter.rb
index c73f714..d75f275 100644
--- a/lib/facter.rb
+++ b/lib/facter.rb
@@ -27,14 +27,14 @@ module Facter
include Comparable
include Enumerable
- FACTERVERSION = '1.5.4'
- # = Facter
+ FACTERVERSION = '1.5.6'
+ # = Facter
# Functions as a hash of 'facts' you might care about about your
# system, such as mac address, IP address, Video card, etc.
# returns them dynamically
- # == Synopsis
- #
+ # == Synopsis
+ #
# Generally, treat <tt>Facter</tt> as a hash:
# == Example
# require 'facter'
@@ -49,7 +49,7 @@ module Facter
RESET = "[0m"
@@debug = 0
- # module methods
+ # module methods
def self.collection
unless defined?(@collection) and @collection
@@ -147,9 +147,9 @@ module Facter
Facter.reset
end
- # Set debugging on or off.
- def self.debugging(bit)
- if bit
+ # Set debugging on or off.
+ def self.debugging(bit)
+ if bit
case bit
when TrueClass; @@debug = 1
when FalseClass; @@debug = 0
@@ -168,10 +168,10 @@ module Facter
else
@@debug = 0
end
- else
- @@debug = 0
- end
- end
+ else
+ @@debug = 0
+ end
+ end
# Remove them all.
def self.reset
diff --git a/lib/facter/architecture.rb b/lib/facter/architecture.rb
index bc9910a..44fc97f 100644
--- a/lib/facter/architecture.rb
+++ b/lib/facter/architecture.rb
@@ -4,9 +4,20 @@ Facter.add(:architecture) do
model = Facter.value(:hardwaremodel)
case model
# most linuxen use "x86_64"
- when 'x86_64'
- Facter.value(:operatingsystem) == "Debian" ? "amd64" : model;
- when /(i[3456]86|pentium)/; "i386"
+ when "x86_64"
+ case Facter.value(:operatingsystem)
+ when "Debian", "Gentoo"
+ "amd64"
+ else
+ model
+ end
+ when /(i[3456]86|pentium)/
+ case Facter.value(:operatingsystem)
+ when "Gentoo"
+ "x86"
+ else
+ "i386"
+ end
else
model
end
diff --git a/lib/facter/ec2.rb b/lib/facter/ec2.rb
new file mode 100644
index 0000000..ef84757
--- /dev/null
+++ b/lib/facter/ec2.rb
@@ -0,0 +1,35 @@
+# Changelog:
+# Original facts - Tim Dysinger
+# Updated and added can_connect? function - KurtBe
+
+require 'open-uri'
+require 'timeout'
+
+def can_connect?(ip,port,wait_sec=2)
+ Timeout::timeout(wait_sec) {open(ip, port)}
+ return true
+rescue
+ return false
+end
+
+
+def metadata(id = "")
+ open("http://169.254.169.254/2008-02-01/meta-data/#{id||=''}").read.
+ split("\n").each do |o|
+ key = "#{id}#{o.gsub(/\=.*$/, '/')}"
+ if key[-1..-1] != '/'
+ value = open("http://169.254.169.254/2008-02-01/meta-data/#{key}").read.
+ split("\n")
+ value = value.size>1 ? value : value.first
+ symbol = "ec2_#{key.gsub(/\-|\//, '_')}".to_sym
+ Facter.add(symbol) { setcode { value } }
+ else
+ metadata(key)
+ end
+ end
+end
+
+if can_connect?("169.254.169.254","80")
+ metadata
+end
+
diff --git a/lib/facter/hardwareisa.rb b/lib/facter/hardwareisa.rb
index 6a67d96..45a16bc 100644
--- a/lib/facter/hardwareisa.rb
+++ b/lib/facter/hardwareisa.rb
@@ -1,4 +1,4 @@
Facter.add(:hardwareisa) do
setcode 'uname -p', '/bin/sh'
- confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD}
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD OEL OVS}
end
diff --git a/lib/facter/id.rb b/lib/facter/id.rb
index d620096..0a4067d 100644
--- a/lib/facter/id.rb
+++ b/lib/facter/id.rb
@@ -1,5 +1,5 @@
Facter.add(:id) do
- confine :operatingsystem => %w{Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX}
+ confine :operatingsystem => %w{Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX OEL OVS}
setcode "whoami"
end
diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb
index d7496f0..4c0bfe4 100644
--- a/lib/facter/ipaddress.rb
+++ b/lib/facter/ipaddress.rb
@@ -1,44 +1,3 @@
-Facter.add(:ipaddress, :ldapname => "iphostnumber", :timeout => 2) do
- setcode do
- require 'resolv'
-
- begin
- if hostname = Facter.value(:hostname)
- ip = Resolv.getaddress(hostname)
- unless ip == "127.0.0.1"
- ip
- end
- else
- nil
- end
- rescue Resolv::ResolvError
- nil
- rescue NoMethodError # i think this is a bug in resolv.rb?
- nil
- end
- end
-end
-
-Facter.add(:ipaddress, :timeout => 2) do
- setcode do
- if hostname = Facter.value(:hostname)
- # we need Hostname to exist for this to work
- host = nil
- if host = Facter::Util::Resolution.exec("host #{hostname}")
- list = host.chomp.split(/\s/)
- if defined? list[-1] and
- list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/
- list[-1]
- end
- else
- nil
- end
- else
- nil
- end
- end
-end
-
Facter.add(:ipaddress) do
confine :kernel => :linux
setcode do
@@ -168,3 +127,44 @@ Facter.add(:ipaddress) do
ip
end
end
+
+Facter.add(:ipaddress, :ldapname => "iphostnumber", :timeout => 2) do
+ setcode do
+ require 'resolv'
+
+ begin
+ if hostname = Facter.value(:hostname)
+ ip = Resolv.getaddress(hostname)
+ unless ip == "127.0.0.1"
+ ip
+ end
+ else
+ nil
+ end
+ rescue Resolv::ResolvError
+ nil
+ rescue NoMethodError # i think this is a bug in resolv.rb?
+ nil
+ end
+ end
+end
+
+Facter.add(:ipaddress, :timeout => 2) do
+ setcode do
+ if hostname = Facter.value(:hostname)
+ # we need Hostname to exist for this to work
+ host = nil
+ if host = Facter::Util::Resolution.exec("host #{hostname}")
+ list = host.chomp.split(/\s/)
+ if defined? list[-1] and
+ list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/
+ list[-1]
+ end
+ else
+ nil
+ end
+ else
+ nil
+ end
+ end
+end
diff --git a/lib/facter/kernel.rb b/lib/facter/kernel.rb
index d372607..d68aa3f 100644
--- a/lib/facter/kernel.rb
+++ b/lib/facter/kernel.rb
@@ -2,8 +2,8 @@ Facter.add(:kernel) do
setcode do
require 'rbconfig'
case Config::CONFIG['host_os']
- when /mswin/i; 'windows'
- else Facter::Util::Resolution.exec("uname -s")
+ when /mswin/i; 'windows'
+ else Facter::Util::Resolution.exec("uname -s")
end
end
end
diff --git a/lib/facter/kernelmajversion.rb b/lib/facter/kernelmajversion.rb
new file mode 100644
index 0000000..32fd7aa
--- /dev/null
+++ b/lib/facter/kernelmajversion.rb
@@ -0,0 +1,5 @@
+Facter.add("kernelmajversion") do
+ setcode do
+ Facter.value(:kernelversion).split('.')[0..1].join('.')
+ end
+end
diff --git a/lib/facter/lsb.rb b/lib/facter/lsb.rb
index fc07437..f54d75f 100644
--- a/lib/facter/lsb.rb
+++ b/lib/facter/lsb.rb
@@ -13,11 +13,11 @@
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
##
-{ "LSBRelease" => %r{^LSB Version:\t(.*)$},
- "LSBDistId" => %r{^Distributor ID:\t(.*)$},
- "LSBDistRelease" => %r{^Release:\t(.*)$},
- "LSBDistDescription" => %r{^Description:\t(.*)$},
- "LSBDistCodeName" => %r{^Codename:\t(.*)$}
+{ "LSBRelease" => %r{^LSB Version:\t(.*)$},
+ "LSBDistId" => %r{^Distributor ID:\t(.*)$},
+ "LSBDistRelease" => %r{^Release:\t(.*)$},
+ "LSBDistDescription" => %r{^Description:\t(.*)$},
+ "LSBDistCodeName" => %r{^Codename:\t(.*)$}
}.each do |fact, pattern|
Facter.add(fact) do
confine :kernel => :linux
diff --git a/lib/facter/lsbmajdistrelease.rb b/lib/facter/lsbmajdistrelease.rb
index f84c3c1..e091593 100644
--- a/lib/facter/lsbmajdistrelease.rb
+++ b/lib/facter/lsbmajdistrelease.rb
@@ -3,7 +3,7 @@
require 'facter'
Facter.add("lsbmajdistrelease") do
- confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo}
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo OEL OVS}
setcode do
if /(\d*)\./i =~ Facter.value(:lsbdistrelease)
result=$1
diff --git a/lib/facter/macaddress.rb b/lib/facter/macaddress.rb
index e048209..e8f40dc 100644
--- a/lib/facter/macaddress.rb
+++ b/lib/facter/macaddress.rb
@@ -1,9 +1,9 @@
Facter.add(:macaddress) do
- confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Gentoo Ubuntu}
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Gentoo Ubuntu OEL OVS}
setcode do
ether = []
output = %x{/sbin/ifconfig -a}
- output.each do |s|
+ output.each_line do |s|
ether.push($1) if s =~ /(?:ether|HWaddr) (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
end
ether[0]
@@ -15,7 +15,7 @@ Facter.add(:macaddress) do
setcode do
ether = []
output = %x{/sbin/ifconfig}
- output.each do |s|
+ output.each_line do |s|
if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/
ether.push($1)
end
@@ -47,12 +47,12 @@ Facter.add(:macaddress) do
ether = []
ip = nil
output = %x{/usr/sbin/ifconfig -a}
- output.each do |str|
+ output.each_line do |str|
if str =~ /([a-z]+\d+): flags=/
devname = $1
unless devname =~ /lo0/
output2 = %x{/usr/bin/entstat #{devname}}
- output2.each do |str2|
+ output2.each_line do |str2|
if str2 =~ /^Hardware Address: (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
ether.push($1)
end
@@ -69,7 +69,7 @@ Facter.add(:macaddress) do
setcode do
ether = []
output = %x{ipconfig /all}
- output.split(/\r\n/).each do |str|
+ output.split(/\r\n/).each do |str|
if str =~ /.*Physical Address.*: (\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2}-\w{1,2})/
ether.push($1.gsub(/-/, ":"))
end
diff --git a/lib/facter/manufacturer.rb b/lib/facter/manufacturer.rb
index d2b13b9..e1ac7be 100644
--- a/lib/facter/manufacturer.rb
+++ b/lib/facter/manufacturer.rb
@@ -6,14 +6,14 @@
require 'facter/util/manufacturer'
query = {
- '[Ss]ystem [Ii]nformation' => [
- { 'Manufacturer:' => 'manufacturer' },
- { 'Product(?: Name)?:' => 'productname' },
- { 'Serial Number:' => 'serialnumber' }
- ],
- '(Chassis Information|system enclosure or chassis)' => [
- { '(?:Chassis )?Type:' => 'type' }
- ]
+ '[Ss]ystem [Ii]nformation' => [
+ { 'Manufacturer:' => 'manufacturer' },
+ { 'Product(?: Name)?:' => 'productname' },
+ { 'Serial Number:' => 'serialnumber' }
+ ],
+ '(Chassis Information|system enclosure or chassis)' => [
+ { '(?:Chassis )?Type:' => 'type' }
+ ]
}
Facter::Manufacturer.dmi_find_system_info(query)
diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb
index 01858d8..6880731 100644
--- a/lib/facter/memory.rb
+++ b/lib/facter/memory.rb
@@ -7,10 +7,11 @@
#
require 'facter/util/memory'
-{:MemorySize => "MemTotal",
- :MemoryFree => "MemFree",
- :SwapSize => "SwapTotal",
- :SwapFree => "SwapFree"}.each do |fact, name|
+{ :MemorySize => "MemTotal",
+ :MemoryFree => "MemFree",
+ :SwapSize => "SwapTotal",
+ :SwapFree => "SwapFree"
+}.each do |fact, name|
Facter.add(fact) do
confine :kernel => :linux
setcode do
diff --git a/lib/facter/netmask.rb b/lib/facter/netmask.rb
index 309ef63..6ccef23 100644
--- a/lib/facter/netmask.rb
+++ b/lib/facter/netmask.rb
@@ -9,9 +9,9 @@
require 'facter/util/netmask'
Facter.add("netmask") do
- confine :kernel => [ :sunos, :linux ]
- setcode do
- Facter::NetMask.get_netmask
- end
+ confine :kernel => [ :sunos, :linux ]
+ setcode do
+ Facter::NetMask.get_netmask
+ end
end
diff --git a/lib/facter/network.rb b/lib/facter/network.rb
index 513282a..df53ce4 100644
--- a/lib/facter/network.rb
+++ b/lib/facter/network.rb
@@ -1,10 +1,9 @@
require 'facter/util/ip'
Facter::Util::IP.get_interfaces.each do |interface|
-
- Facter.add("network_" + Facter::Util::IP.alphafy(interface)) do
- setcode do
- Facter::Util::IP.get_network_value(interface)
- end
+ Facter.add("network_" + Facter::Util::IP.alphafy(interface)) do
+ setcode do
+ Facter::Util::IP.get_network_value(interface)
end
+ end
end
diff --git a/lib/facter/operatingsystem.rb b/lib/facter/operatingsystem.rb
index 72f25f5..335003a 100644
--- a/lib/facter/operatingsystem.rb
+++ b/lib/facter/operatingsystem.rb
@@ -20,12 +20,16 @@ Facter.add(:operatingsystem) do
"Mandriva"
elsif FileTest.exists?("/etc/mandrake-release")
"Mandrake"
- elsif FileTest.exists?("/etc/arch-release")
- "Archlinux"
+ elsif FileTest.exists?("/etc/arch-release")
+ "Archlinux"
elsif FileTest.exists?("/etc/enterprise-release")
- "OEL"
- elsif FileTest.exists?("/etc/ovs-release")
- "OVS"
+ if FileTest.exists?("/etc/ovs-release")
+ "OVS"
+ else
+ "OEL"
+ end
+ elsif FileTest.exists?("/etc/arch-release")
+ "Arch"
elsif FileTest.exists?("/etc/redhat-release")
txt = File.read("/etc/redhat-release")
if txt =~ /centos/i
@@ -37,8 +41,10 @@ Facter.add(:operatingsystem) do
txt = File.read("/etc/SuSE-release")
if txt =~ /^SUSE LINUX Enterprise Server/i
"SLES"
- elsif txt =~ /^openSUSE/i
- "OpenSuSE"
+ elsif txt =~ /^SUSE LINUX Enterprise Desktop/i
+ "SLED"
+ elsif txt =~ /^openSUSE/i
+ "OpenSuSE"
else
"SuSE"
end
diff --git a/lib/facter/operatingsystemrelease.rb b/lib/facter/operatingsystemrelease.rb
index 1ea2e75..0864b4d 100644
--- a/lib/facter/operatingsystemrelease.rb
+++ b/lib/facter/operatingsystemrelease.rb
@@ -53,8 +53,8 @@ end
Facter.add(:operatingsystemrelease) do
confine :operatingsystem => %w{CentOS}
setcode do
- centos_release = Facter::Util::Resolution.exec("sed -r -e 's/CentOS release //' -e 's/ \((Branch|Final)\)//' /etc/redhat-release")
- if centos_release =~ /5/
+ centos_release = Facter::Util::Resolution.exec("sed -r -e 's/CentOS release //' -e 's/ \\((Branch|Final)\\)//' /etc/redhat-release")
+ if centos_release =~ /^5/
release = Facter::Util::Resolution.exec('rpm -q --qf \'%{VERSION}.%{RELEASE}\' centos-release | cut -d. -f1,2')
else
release = centos_release
@@ -80,15 +80,15 @@ Facter.add(:operatingsystemrelease) do
end
Facter.add(:operatingsystemrelease) do
- confine :operatingsystem => %w{SLES OpenSuSE}
+ confine :operatingsystem => %w{SLES SLED OpenSuSE}
setcode do
releasefile = Facter::Util::Resolution.exec('cat /etc/SuSE-release')
if releasefile =~ /^VERSION\s*=\s*(\d+)/
releasemajor = $1
if releasefile =~ /^PATCHLEVEL\s*=\s*(\d+)/
releaseminor = $1
- elsif releasefile =~ /^VERSION\s=.*.(\d+)/
- releaseminor = $1
+ elsif releasefile =~ /^VERSION\s=.*.(\d+)/
+ releaseminor = $1
else
releaseminor = "0"
end
diff --git a/lib/facter/selinux.rb b/lib/facter/selinux.rb
new file mode 100644
index 0000000..0e9637d
--- /dev/null
+++ b/lib/facter/selinux.rb
@@ -0,0 +1,45 @@
+# Fact for SElinux
+# Written by immerda admin team (admin(at)immerda.ch)
+
+Facter.add("selinux") do
+ confine :kernel => :linux
+
+ setcode do
+ result = "false"
+ if FileTest.exists?("/selinux/enforce")
+ if FileTest.exists?("/proc/self/attr/current")
+ if (File.read("/proc/self/attr/current") != "kernel\0")
+ result = "true"
+ end
+ end
+ end
+ result
+ end
+end
+
+Facter.add("selinux_enforced") do
+ confine :selinux => :true
+
+ setcode do
+ result = "false"
+ if FileTest.exists?("/selinux/enforce") and File.read("/selinux/enforce") =~ /1/i
+ result = "true"
+ end
+ result
+ end
+end
+
+Facter.add("selinux_policyversion") do
+ confine :selinux => :true
+ setcode do
+ File.read("/selinux/policyvers")
+ end
+end
+
+Facter.add("selinux_mode") do
+ confine :selinux => :true
+ setcode do
+ %x{/usr/sbin/sestatus | /bin/grep "Policy from config file:" | awk '{print $5}'}
+ end
+end
+
diff --git a/lib/facter/timezone.rb b/lib/facter/timezone.rb
index e01c5e0..744e06a 100644
--- a/lib/facter/timezone.rb
+++ b/lib/facter/timezone.rb
@@ -1,5 +1,5 @@
Facter.add("timezone") do
- setcode do
+ setcode do
Time.new.zone
end
end
diff --git a/lib/facter/uniqueid.rb b/lib/facter/uniqueid.rb
index b199865..93f8a61 100644
--- a/lib/facter/uniqueid.rb
+++ b/lib/facter/uniqueid.rb
@@ -1,4 +1,4 @@
Facter.add(:uniqueid) do
- setcode 'hostid', '/bin/sh'
- confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX}
+ setcode 'hostid', '/bin/sh'
+ confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX OEL OVS}
end
diff --git a/lib/facter/uptime.rb b/lib/facter/uptime.rb
index 808bcec..3a3bc86 100644
--- a/lib/facter/uptime.rb
+++ b/lib/facter/uptime.rb
@@ -12,9 +12,9 @@ if FileTest.exists?("/proc/uptime")
%w{days hours seconds}.each do |label|
Facter.add("uptime_" + label) do
- setcode do
- Facter::Util::Uptime.get_uptime_period(uptime, label)
- end
+ setcode do
+ Facter::Util::Uptime.get_uptime_period(uptime, label)
+ end
end
end
end
diff --git a/lib/facter/util/confine.rb b/lib/facter/util/confine.rb
index a430bbe..4cbb32c 100644
--- a/lib/facter/util/confine.rb
+++ b/lib/facter/util/confine.rb
@@ -1,22 +1,20 @@
# A restricting tag for fact resolution mechanisms. The tag must be true
# for the resolution mechanism to be suitable.
+
+require 'facter/util/values'
+
class Facter::Util::Confine
attr_accessor :fact, :values
+ include Facter::Util::Values
+
# Add the restriction. Requires the fact name, an operator, and the value
# we're comparing to.
def initialize(fact, *values)
raise ArgumentError, "The fact name must be provided" unless fact
raise ArgumentError, "One or more values must be provided" if values.empty?
- fact = fact.to_s if fact.is_a? Symbol
@fact = fact
- @values = values.collect do |value|
- if value.is_a? String
- value
- else
- value.to_s
- end
- end
+ @values = values
end
def to_s
@@ -29,13 +27,15 @@ class Facter::Util::Confine
Facter.debug "No fact for %s" % @fact
return false
end
- value = fact.value
+ value = convert(fact.value)
return false if value.nil?
- @values.each { |v|
- return true if value.downcase == v.downcase
- }
+ @values.each do |v|
+ v = convert(v)
+ next unless v.class == value.class
+ return true if value == v
+ end
return false
end
end
diff --git a/lib/facter/util/ip.rb b/lib/facter/util/ip.rb
index 4d4d936..fb32d70 100644
--- a/lib/facter/util/ip.rb
+++ b/lib/facter/util/ip.rb
@@ -5,20 +5,20 @@ module Facter::Util::IP
# a given platform or set of platforms.
REGEX_MAP = {
:linux => {
- :ipaddress => /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
- :macaddress => /(?:ether|HWaddr)\s+(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/,
- :netmask => /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
+ :ipaddress => /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
+ :macaddress => /(?:ether|HWaddr)\s+(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/,
+ :netmask => /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
},
- :bsd => {
- :aliases => [:openbsd, :netbsd, :freebsd, :darwin],
- :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
- :macaddress => /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/,
- :netmask => /netmask\s+0x(\w{8})/
+ :bsd => {
+ :aliases => [:openbsd, :netbsd, :freebsd, :darwin],
+ :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
+ :macaddress => /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/,
+ :netmask => /netmask\s+0x(\w{8})/
},
:sunos => {
- :addr => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
- :macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/,
- :netmask => /netmask\s+(\w{8})/
+ :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
+ :macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/,
+ :netmask => /netmask\s+(\w{8})/
}
}
@@ -45,17 +45,13 @@ module Facter::Util::IP
end
def self.get_interfaces
- int = nil
-
- output = Facter::Util::IP.get_all_interface_output()
+ return [] unless output = Facter::Util::IP.get_all_interface_output()
- # We get lots of warnings on platforms that don't get an output
- # made.
- if output
- int = output.scan(/^\w+[.:]?\d+/)
- else
- []
- end
+ # Our regex appears to be stupid, in that it leaves colons sitting
+ # at the end of interfaces. So, we have to trim those trailing
+ # characters. I tried making the regex better but supporting all
+ # platforms with a single regex is probably a bit too much.
+ output.scan(/^\w+[.:]?\d+[.:]?\d*[.:]?\w*/).collect { |i| i.sub(/:$/, '') }
end
def self.get_all_interface_output
@@ -124,7 +120,7 @@ module Facter::Util::IP
output_int = get_single_interface_output(interface)
if interface != /^lo[0:]?\d?/
- output_int.each do |s|
+ output_int.each_line do |s|
if s =~ regex
value = $1
if label == 'netmask' && convert_from_hex?(kernel)
diff --git a/lib/facter/util/macosx.rb b/lib/facter/util/macosx.rb
index 6e7986e..f5f83f3 100644
--- a/lib/facter/util/macosx.rb
+++ b/lib/facter/util/macosx.rb
@@ -58,6 +58,11 @@ module Facter::Util::Macosx
[ "productName", "productVersion", "buildVersion" ].each do |option|
ver["macosx_#{option}"] = %x{sw_vers -#{option}}.strip
end
+ productversion = ver["macosx_productVersion"]
+ if not productversion.nil?
+ ver["macosx_productversion_major"] = productversion.scan(/(\d+\.\d+)/)[0][0]
+ ver["macosx_productversion_minor"] = productversion.scan(/(\d+)\.(\d+)\.(\d+)/)[0].last
+ end
ver
end
end
diff --git a/lib/facter/util/manufacturer.rb b/lib/facter/util/manufacturer.rb
index ff12e7e..954637e 100644
--- a/lib/facter/util/manufacturer.rb
+++ b/lib/facter/util/manufacturer.rb
@@ -2,45 +2,45 @@
# Support methods for manufacturer specific facts
module Facter::Manufacturer
- def self.dmi_find_system_info(name)
- splitstr="Handle"
- case Facter.value(:kernel)
- when 'Linux'
- return nil unless FileTest.exists?("/usr/sbin/dmidecode")
-
- output=%x{/usr/sbin/dmidecode 2>/dev/null}
- when 'OpenBSD', 'FreeBSD'
- return nil unless FileTest.exists?("/usr/local/sbin/dmidecode")
-
- output=%x{/usr/local/sbin/dmidecode 2>/dev/null}
- when 'NetBSD'
- return nil unless FileTest.exists?("/usr/pkg/sbin/dmidecode")
+ def self.dmi_find_system_info(name)
+ splitstr="Handle"
+ case Facter.value(:kernel)
+ when 'Linux'
+ return nil unless FileTest.exists?("/usr/sbin/dmidecode")
- output=%x{/usr/pkg/sbin/dmidecode 2>/dev/null}
- when 'SunOS'
- return nil unless FileTest.exists?("/usr/sbin/smbios")
- splitstr="ID SIZE TYPE"
- output=%x{/usr/sbin/smbios 2>/dev/null}
+ output=%x{/usr/sbin/dmidecode 2>/dev/null}
+ when 'OpenBSD', 'FreeBSD'
+ return nil unless FileTest.exists?("/usr/local/sbin/dmidecode")
- else
- return
- end
- name.each_pair do |key,v|
- v.each do |v2|
- v2.each_pair do |value,facterkey|
- output.split(splitstr).each do |line|
- if line =~ /#{key}/ and ( line =~ /#{value} 0x\d+ \(([-\w].*)\)\n*./ or line =~ /#{value} ([-\w].*)\n*./ )
- result = $1
- Facter.add(facterkey) do
- confine :kernel => [ :linux, :freebsd, :netbsd, :openbsd, :sunos ]
- setcode do
- result
- end
- end
- end
- end
- end
- end
+ output=%x{/usr/local/sbin/dmidecode 2>/dev/null}
+ when 'NetBSD'
+ return nil unless FileTest.exists?("/usr/pkg/sbin/dmidecode")
+
+ output=%x{/usr/pkg/sbin/dmidecode 2>/dev/null}
+ when 'SunOS'
+ return nil unless FileTest.exists?("/usr/sbin/smbios")
+ splitstr="ID SIZE TYPE"
+ output=%x{/usr/sbin/smbios 2>/dev/null}
+
+ else
+ return
+ end
+ name.each_pair do |key,v|
+ v.each do |v2|
+ v2.each_pair do |value,facterkey|
+ output.split(splitstr).each do |line|
+ if line =~ /#{key}/ and ( line =~ /#{value} 0x\d+ \(([-\w].*)\)\n*./ or line =~ /#{value} ([-\w].*)\n*./ )
+ result = $1
+ Facter.add(facterkey) do
+ confine :kernel => [ :linux, :freebsd, :netbsd, :openbsd, :sunos ]
+ setcode do
+ result
+ end
+ end
+ end
+ end
+ end
+ end
end
end
end
diff --git a/lib/facter/util/plist/generator.rb b/lib/facter/util/plist/generator.rb
index 9e44b80..6c0796b 100644
--- a/lib/facter/util/plist/generator.rb
+++ b/lib/facter/util/plist/generator.rb
@@ -7,220 +7,222 @@
#++
# See Plist::Emit.
module Plist
- # === Create a plist
- # You can dump an object to a plist in one of two ways:
- #
- # * <tt>Plist::Emit.dump(obj)</tt>
- # * <tt>obj.to_plist</tt>
- # * This requires that you mixin the <tt>Plist::Emit</tt> module, which is already done for +Array+ and +Hash+.
- #
- # The following Ruby classes are converted into native plist types:
- # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time, true, false
- # * +Array+ and +Hash+ are both recursive; their elements will be converted into plist nodes inside the <array> and <dict> containers (respectively).
- # * +IO+ (and its descendants) and +StringIO+ objects are read from and their contents placed in a <data> element.
- # * User classes may implement +to_plist_node+ to dictate how they should be serialized; otherwise the object will be passed to <tt>Marshal.dump</tt> and the result placed in a <data> element.
- #
- # For detailed usage instructions, refer to USAGE[link:files/docs/USAGE.html] and the methods documented below.
- module Emit
- # Helper method for injecting into classes. Calls <tt>Plist::Emit.dump</tt> with +self+.
- def to_plist(envelope = true)
- return Plist::Emit.dump(self, envelope)
- end
-
- # Helper method for injecting into classes. Calls <tt>Plist::Emit.save_plist</tt> with +self+.
- def save_plist(filename)
- Plist::Emit.save_plist(self, filename)
- end
-
- # The following Ruby classes are converted into native plist types:
- # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time
+ # === Create a plist
+ # You can dump an object to a plist in one of two ways:
#
- # Write us (via RubyForge) if you think another class can be coerced safely into one of the expected plist classes.
+ # * <tt>Plist::Emit.dump(obj)</tt>
+ # * <tt>obj.to_plist</tt>
+ # * This requires that you mixin the <tt>Plist::Emit</tt> module, which is already done for +Array+ and +Hash+.
#
- # +IO+ and +StringIO+ objects are encoded and placed in <data> elements; other objects are <tt>Marshal.dump</tt>'ed unless they implement +to_plist_node+.
+ # The following Ruby classes are converted into native plist types:
+ # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time, true, false
+ # * +Array+ and +Hash+ are both recursive; their elements will be converted into plist nodes inside the <array> and <dict> containers (respectively).
+ # * +IO+ (and its descendants) and +StringIO+ objects are read from and their contents placed in a <data> element.
+ # * User classes may implement +to_plist_node+ to dictate how they should be serialized; otherwise the object will be passed to <tt>Marshal.dump</tt> and the result placed in a <data> element.
#
- # The +envelope+ parameters dictates whether or not the resultant plist fragment is wrapped in the normal XML/plist header and footer. Set it to false if you only want the fragment.
- def self.dump(obj, envelope = true)
- output = plist_node(obj)
+ # For detailed usage instructions, refer to USAGE[link:files/docs/USAGE.html] and the methods documented below.
+ module Emit
+ # Helper method for injecting into classes. Calls <tt>Plist::Emit.dump</tt> with +self+.
+ def to_plist(envelope = true)
+ return Plist::Emit.dump(self, envelope)
+ end
- output = wrap(output) if envelope
+ # Helper method for injecting into classes. Calls <tt>Plist::Emit.save_plist</tt> with +self+.
+ def save_plist(filename)
+ Plist::Emit.save_plist(self, filename)
+ end
- return output
- end
+ # The following Ruby classes are converted into native plist types:
+ # Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time
+ #
+ # Write us (via RubyForge) if you think another class can be coerced safely into one of the expected plist classes.
+ #
+ # +IO+ and +StringIO+ objects are encoded and placed in <data> elements; other objects are <tt>Marshal.dump</tt>'ed unless they implement +to_plist_node+.
+ #
+ # The +envelope+ parameters dictates whether or not the resultant plist fragment is wrapped in the normal XML/plist header and footer. Set it to false if you only want the fragment.
+ def self.dump(obj, envelope = true)
+ output = plist_node(obj)
- # Writes the serialized object's plist to the specified filename.
- def self.save_plist(obj, filename)
- File.open(filename, 'wb') do |f|
- f.write(obj.to_plist)
- end
- end
+ output = wrap(output) if envelope
- private
- def self.plist_node(element)
- output = ''
-
- if element.respond_to? :to_plist_node
- output << element.to_plist_node
- else
- case element
- when Array
- if element.empty?
- output << "<array/>\n"
- else
- output << tag('array') {
- element.collect {|e| plist_node(e)}
- }
- end
- when Hash
- if element.empty?
- output << "<dict/>\n"
- else
- inner_tags = []
-
- element.keys.sort.each do |k|
- v = element[k]
- inner_tags << tag('key', CGI::escapeHTML(k.to_s))
- inner_tags << plist_node(v)
+ return output
+ end
+
+ # Writes the serialized object's plist to the specified filename.
+ def self.save_plist(obj, filename)
+ File.open(filename, 'wb') do |f|
+ f.write(obj.to_plist)
+ end
+ end
+
+ private
+ def self.plist_node(element)
+ output = ''
+
+ if element.respond_to? :to_plist_node
+ output << element.to_plist_node
+ else
+ case element
+ when Array
+ if element.empty?
+ output << "<array/>\n"
+ else
+ output << tag('array') {
+ element.collect {|e| plist_node(e)}
+ }
+ end
+ when Hash
+ if element.empty?
+ output << "<dict/>\n"
+ else
+ inner_tags = []
+
+ element.keys.sort.each do |k|
+ v = element[k]
+ inner_tags << tag('key', CGI::escapeHTML(k.to_s))
+ inner_tags << plist_node(v)
+ end
+
+ output << tag('dict') {
+ inner_tags
+ }
+ end
+ when true, false
+ output << "<#{element}/>\n"
+ when Time
+ output << tag('date', element.utc.strftime('%Y-%m-%dT%H:%M:%SZ'))
+ when Date # also catches DateTime
+ output << tag('date', element.strftime('%Y-%m-%dT%H:%M:%SZ'))
+ when String, Symbol, Fixnum, Bignum, Integer, Float
+ output << tag(element_type(element), CGI::escapeHTML(element.to_s))
+ when IO, StringIO
+ element.rewind
+ contents = element.read
+ # note that apple plists are wrapped at a different length then
+ # what ruby's base64 wraps by default.
+ # I used #encode64 instead of #b64encode (which allows a length arg)
+ # because b64encode is b0rked and ignores the length arg.
+ data = "\n"
+ Base64::encode64(contents).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" }
+ output << tag('data', data)
+ else
+ output << comment( 'The <data> element below contains a Ruby object which has been serialized with Marshal.dump.' )
+ data = "\n"
+ Base64::encode64(Marshal.dump(element)).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" }
+ output << tag('data', data )
+ end
end
- output << tag('dict') {
- inner_tags
- }
- end
- when true, false
- output << "<#{element}/>\n"
- when Time
- output << tag('date', element.utc.strftime('%Y-%m-%dT%H:%M:%SZ'))
- when Date # also catches DateTime
- output << tag('date', element.strftime('%Y-%m-%dT%H:%M:%SZ'))
- when String, Symbol, Fixnum, Bignum, Integer, Float
- output << tag(element_type(element), CGI::escapeHTML(element.to_s))
- when IO, StringIO
- element.rewind
- contents = element.read
- # note that apple plists are wrapped at a different length then
- # what ruby's base64 wraps by default.
- # I used #encode64 instead of #b64encode (which allows a length arg)
- # because b64encode is b0rked and ignores the length arg.
- data = "\n"
- Base64::encode64(contents).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" }
- output << tag('data', data)
- else
- output << comment( 'The <data> element below contains a Ruby object which has been serialized with Marshal.dump.' )
- data = "\n"
- Base64::encode64(Marshal.dump(element)).gsub(/\s+/, '').scan(/.{1,68}/o) { data << $& << "\n" }
- output << tag('data', data )
+ return output
end
- end
- return output
- end
+ def self.comment(content)
+ return "<!-- #{content} -->\n"
+ end
- def self.comment(content)
- return "<!-- #{content} -->\n"
- end
+ def self.tag(type, contents = '', &block)
+ out = nil
+
+ if block_given?
+ out = IndentedString.new
+ out << "<#{type}>"
+ out.raise_indent
- def self.tag(type, contents = '', &block)
- out = nil
+ out << block.call
- if block_given?
- out = IndentedString.new
- out << "<#{type}>"
- out.raise_indent
+ out.lower_indent
+ out << "</#{type}>"
+ else
+ out = "<#{type}>#{contents.to_s}</#{type}>\n"
+ end
- out << block.call
+ return out.to_s
+ end
- out.lower_indent
- out << "</#{type}>"
- else
- out = "<#{type}>#{contents.to_s}</#{type}>\n"
- end
+ def self.wrap(contents)
+ output = ''
- return out.to_s
- end
+ output << '<?xml version="1.0" encoding="UTF-8"?>' + "\n"
+ output << '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' + "\n"
+ output << '<plist version="1.0">' + "\n"
+
+ output << contents
+
+ output << '</plist>' + "\n"
- def self.wrap(contents)
- output = ''
+ return output
+ end
- output << '<?xml version="1.0" encoding="UTF-8"?>' + "\n"
- output << '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' + "\n"
- output << '<plist version="1.0">' + "\n"
+ def self.element_type(item)
+ return case item
+ when String, Symbol; 'string'
+ when Fixnum, Bignum, Integer; 'integer'
+ when Float; 'real'
+ else
+ raise "Don't know about this data type... something must be wrong!"
+ end
+ end
- output << contents
+ private
- output << '</plist>' + "\n"
+ class IndentedString #:nodoc:
+ attr_accessor :indent_string
- return output
- end
+ @@indent_level = 0
- def self.element_type(item)
- return case item
- when String, Symbol; 'string'
- when Fixnum, Bignum, Integer; 'integer'
- when Float; 'real'
- else
- raise "Don't know about this data type... something must be wrong!"
- end
- end
- private
- class IndentedString #:nodoc:
- attr_accessor :indent_string
-
- @@indent_level = 0
-
- def initialize(str = "\t")
- @indent_string = str
- @contents = ''
- end
-
- def to_s
- return @contents
- end
-
- def raise_indent
- @@indent_level += 1
- end
-
- def lower_indent
- @@indent_level -= 1 if @@indent_level > 0
- end
-
- def <<(val)
- if val.is_a? Array
- val.each do |f|
- self << f
- end
- else
- # if it's already indented, don't bother indenting further
- unless val =~ /\A#{@indent_string}/
- indent = @indent_string * @@indent_level
-
- @contents << val.gsub(/^/, indent)
- else
- @contents << val
- end
-
- # it already has a newline, don't add another
- @contents << "\n" unless val =~ /\n$/
+ def initialize(str = "\t")
+ @indent_string = str
+ @contents = ''
+ end
+
+ def to_s
+ return @contents
+ end
+
+ def raise_indent
+ @@indent_level += 1
+ end
+
+ def lower_indent
+ @@indent_level -= 1 if @@indent_level > 0
+ end
+
+ def <<(val)
+ if val.is_a? Array
+ val.each do |f|
+ self << f
+ end
+ else
+ # if it's already indented, don't bother indenting further
+ unless val =~ /\A#{@indent_string}/
+ indent = @indent_string * @@indent_level
+
+ @contents << val.gsub(/^/, indent)
+ else
+ @contents << val
+ end
+
+ # it already has a newline, don't add another
+ @contents << "\n" unless val =~ /\n$/
+ end
+ end
end
- end
end
- end
end
# we need to add this so sorting hash keys works properly
class Symbol #:nodoc:
- def <=> (other)
- self.to_s <=> other.to_s
- end
+ def <=> (other)
+ self.to_s <=> other.to_s
+ end
end
class Array #:nodoc:
- include Plist::Emit
+ include Plist::Emit
end
class Hash #:nodoc:
- include Plist::Emit
+ include Plist::Emit
end
# $Id: generator.rb 1781 2006-10-16 01:01:35Z luke $
diff --git a/lib/facter/util/plist/parser.rb b/lib/facter/util/plist/parser.rb
index 24f791f..48e1034 100644
--- a/lib/facter/util/plist/parser.rb
+++ b/lib/facter/util/plist/parser.rb
@@ -21,207 +21,206 @@ module Plist
# If you encounter such an error, or if you have a Date element which
# can't be parsed into a Time object, please send your plist file to
# plist at hexane.org so that I can implement the proper support.
- def Plist::parse_xml( filename_or_xml )
- listener = Listener.new
- #parser = REXML::Parsers::StreamParser.new(File.new(filename), listener)
- parser = StreamParser.new(filename_or_xml, listener)
- parser.parse
- listener.result
- end
-
- class Listener
- #include REXML::StreamListener
-
- attr_accessor :result, :open
-
- def initialize
- @result = nil
- @open = Array.new
+ def Plist::parse_xml( filename_or_xml )
+ listener = Listener.new
+ #parser = REXML::Parsers::StreamParser.new(File.new(filename), listener)
+ parser = StreamParser.new(filename_or_xml, listener)
+ parser.parse
+ listener.result
end
+ class Listener
+ #include REXML::StreamListener
- def tag_start(name, attributes)
- @open.push PTag::mappings[name].new
- end
+ attr_accessor :result, :open
- def text( contents )
- @open.last.text = contents if @open.last
- end
+ def initialize
+ @result = nil
+ @open = Array.new
+ end
- def tag_end(name)
- last = @open.pop
- if @open.empty?
- @result = last.to_ruby
- else
- @open.last.children.push last
- end
- end
- end
- class StreamParser
- def initialize( filename_or_xml, listener )
- @filename_or_xml = filename_or_xml
- @listener = listener
- end
+ def tag_start(name, attributes)
+ @open.push PTag::mappings[name].new
+ end
- TEXT = /([^<]+)/
- XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/um
- DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um
- COMMENT_START = /\A<!--/u
- COMMENT_END = /.*?-->/um
-
-
- def parse
- plist_tags = PTag::mappings.keys.join('|')
- start_tag = /<(#{plist_tags})([^>]*)>/i
- end_tag = /<\/(#{plist_tags})[^>]*>/i
-
- require 'strscan'
-
- contents = (
- if (File.exists? @filename_or_xml)
- File.open(@filename_or_xml) {|f| f.read}
- else
- @filename_or_xml
- end
- )
-
- @scanner = StringScanner.new( contents )
- until @scanner.eos?
- if @scanner.scan(COMMENT_START)
- @scanner.scan(COMMENT_END)
- elsif @scanner.scan(XMLDECL_PATTERN)
- elsif @scanner.scan(DOCTYPE_PATTERN)
- elsif @scanner.scan(start_tag)
- @listener.tag_start(@scanner[1], nil)
- if (@scanner[2] =~ /\/$/)
- @listener.tag_end(@scanner[1])
- end
- elsif @scanner.scan(TEXT)
- @listener.text(@scanner[1])
- elsif @scanner.scan(end_tag)
- @listener.tag_end(@scanner[1])
- else
- raise "Unimplemented element"
- end
- end
- end
- end
+ def text( contents )
+ @open.last.text = contents if @open.last
+ end
- class PTag
- @@mappings = { }
- def PTag::mappings
- @@mappings
+ def tag_end(name)
+ last = @open.pop
+ if @open.empty?
+ @result = last.to_ruby
+ else
+ @open.last.children.push last
+ end
+ end
end
- def PTag::inherited( sub_class )
- key = sub_class.to_s.downcase
- key.gsub!(/^plist::/, '' )
- key.gsub!(/^p/, '') unless key == "plist"
+ class StreamParser
+ def initialize( filename_or_xml, listener )
+ @filename_or_xml = filename_or_xml
+ @listener = listener
+ end
- @@mappings[key] = sub_class
+ TEXT = /([^<]+)/
+ XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/um
+ DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um
+ COMMENT_START = /\A<!--/u
+ COMMENT_END = /.*?-->/um
+
+ def parse
+ plist_tags = PTag::mappings.keys.join('|')
+ start_tag = /<(#{plist_tags})([^>]*)>/i
+ end_tag = /<\/(#{plist_tags})[^>]*>/i
+
+ require 'strscan'
+
+ contents = (
+ if (File.exists? @filename_or_xml)
+ File.open(@filename_or_xml) {|f| f.read}
+ else
+ @filename_or_xml
+ end
+ )
+
+ @scanner = StringScanner.new( contents )
+ until @scanner.eos?
+ if @scanner.scan(COMMENT_START)
+ @scanner.scan(COMMENT_END)
+ elsif @scanner.scan(XMLDECL_PATTERN)
+ elsif @scanner.scan(DOCTYPE_PATTERN)
+ elsif @scanner.scan(start_tag)
+ @listener.tag_start(@scanner[1], nil)
+ if (@scanner[2] =~ /\/$/)
+ @listener.tag_end(@scanner[1])
+ end
+ elsif @scanner.scan(TEXT)
+ @listener.text(@scanner[1])
+ elsif @scanner.scan(end_tag)
+ @listener.tag_end(@scanner[1])
+ else
+ raise "Unimplemented element"
+ end
+ end
+ end
end
- attr_accessor :text, :children
- def initialize
- @children = Array.new
- end
+ class PTag
+ @@mappings = { }
+ def PTag::mappings
+ @@mappings
+ end
- def to_ruby
- raise "Unimplemented: " + self.class.to_s + "#to_ruby on #{self.inspect}"
+ def PTag::inherited( sub_class )
+ key = sub_class.to_s.downcase
+ key.gsub!(/^plist::/, '' )
+ key.gsub!(/^p/, '') unless key == "plist"
+
+ @@mappings[key] = sub_class
+ end
+
+ attr_accessor :text, :children
+ def initialize
+ @children = Array.new
+ end
+
+ def to_ruby
+ raise "Unimplemented: " + self.class.to_s + "#to_ruby on #{self.inspect}"
+ end
end
- end
- class PList < PTag
- def to_ruby
- children.first.to_ruby if children.first
+ class PList < PTag
+ def to_ruby
+ children.first.to_ruby if children.first
+ end
end
- end
- class PDict < PTag
- def to_ruby
- dict = Hash.new
- key = nil
+ class PDict < PTag
+ def to_ruby
+ dict = Hash.new
+ key = nil
- children.each do |c|
- if key.nil?
- key = c.to_ruby
- else
- dict[key] = c.to_ruby
- key = nil
- end
- end
+ children.each do |c|
+ if key.nil?
+ key = c.to_ruby
+ else
+ dict[key] = c.to_ruby
+ key = nil
+ end
+ end
- dict
+ dict
+ end
end
- end
- class PKey < PTag
- def to_ruby
- CGI::unescapeHTML(text || '')
+ class PKey < PTag
+ def to_ruby
+ CGI::unescapeHTML(text || '')
+ end
end
- end
- class PString < PTag
- def to_ruby
- CGI::unescapeHTML(text || '')
+ class PString < PTag
+ def to_ruby
+ CGI::unescapeHTML(text || '')
+ end
end
- end
- class PArray < PTag
- def to_ruby
- children.collect do |c|
- c.to_ruby
- end
+ class PArray < PTag
+ def to_ruby
+ children.collect do |c|
+ c.to_ruby
+ end
+ end
end
- end
- class PInteger < PTag
- def to_ruby
- text.to_i
+ class PInteger < PTag
+ def to_ruby
+ text.to_i
+ end
end
- end
- class PTrue < PTag
- def to_ruby
- true
+ class PTrue < PTag
+ def to_ruby
+ true
+ end
end
- end
- class PFalse < PTag
- def to_ruby
- false
+ class PFalse < PTag
+ def to_ruby
+ false
+ end
end
- end
- class PReal < PTag
- def to_ruby
- text.to_f
+ class PReal < PTag
+ def to_ruby
+ text.to_f
+ end
end
- end
- require 'date'
- class PDate < PTag
- def to_ruby
- DateTime.parse(text)
+ require 'date'
+ class PDate < PTag
+ def to_ruby
+ DateTime.parse(text)
+ end
end
- end
-
- require 'base64'
- class PData < PTag
- def to_ruby
- data = Base64.decode64(text.gsub(/\s+/, ''))
-
- begin
- return Marshal.load(data)
- rescue Exception => e
- io = StringIO.new
- io.write data
- io.rewind
- return io
- end
+
+ require 'base64'
+ class PData < PTag
+ def to_ruby
+ data = Base64.decode64(text.gsub(/\s+/, ''))
+
+ begin
+ return Marshal.load(data)
+ rescue Exception => e
+ io = StringIO.new
+ io.write data
+ io.rewind
+ return io
+ end
+ end
end
- end
end
# $Id: parser.rb 1781 2006-10-16 01:01:35Z luke $
diff --git a/lib/facter/util/resolution.rb b/lib/facter/util/resolution.rb
index 0dfb3b2..04d5e47 100644
--- a/lib/facter/util/resolution.rb
+++ b/lib/facter/util/resolution.rb
@@ -16,7 +16,7 @@ class Facter::Util::Resolution
if Config::CONFIG['host_os'] =~ /mswin/
@have_which = false
else
- %x{which which 2>/dev/null}
+ %x{which which >/dev/null 2>&1}
@have_which = ($? == 0)
end
end
@@ -33,7 +33,7 @@ class Facter::Util::Resolution
if binary !~ /^\//
path = %x{which #{binary} 2>/dev/null}.chomp
# we don't have the binary necessary
- return nil if path == ""
+ return nil if path == "" or path.match(/Command not found\./)
else
path = binary
end
diff --git a/lib/facter/util/uptime.rb b/lib/facter/util/uptime.rb
index 1be3b98..c1e339b 100644
--- a/lib/facter/util/uptime.rb
+++ b/lib/facter/util/uptime.rb
@@ -1,25 +1,25 @@
# A module to gather uptime facts
#
module Facter::Util::Uptime
-
def self.get_uptime_simple
time = Facter::Util::Resolution.exec('uptime')
- if time =~ /up\s*(\d+\s\w+)/
- $1
- elsif time =~ /up\s*(\d+:\d+)/
- $1 + " hours"
- else
- "unknown"
- end
+ if time =~ /up\s*(\d+\s\w+)/
+ $1
+ elsif time =~ /up\s*(\d+:\d+)/
+ $1 + " hours"
+ else
+ "unknown"
+ end
end
def self.get_uptime
- uptime, idletime = File.open("/proc/uptime").gets.split(" ")
+ r = IO.popen("/bin/cat /proc/uptime")
+ uptime, idletime = r.readline.split(" ")
+ r.close
uptime_seconds = uptime.to_i
end
def self.get_uptime_period(seconds, label)
-
case label
when 'days'
value = seconds / 86400
@@ -28,7 +28,5 @@ module Facter::Util::Uptime
when 'seconds'
seconds
end
-
end
-
end
diff --git a/lib/facter/util/values.rb b/lib/facter/util/values.rb
new file mode 100644
index 0000000..ebc7614
--- /dev/null
+++ b/lib/facter/util/values.rb
@@ -0,0 +1,14 @@
+# A util module for facter containing helper methods
+module Facter
+ module Util
+ module Values
+ module_function
+
+ def convert(value)
+ value = value.to_s if value.is_a?(Symbol)
+ value = value.downcase if value.is_a?(String)
+ value
+ end
+ end
+ end
+end
diff --git a/lib/facter/virtual.rb b/lib/facter/virtual.rb
index fdb340f..72bfe51 100644
--- a/lib/facter/virtual.rb
+++ b/lib/facter/virtual.rb
@@ -4,48 +4,67 @@ Facter.add("virtual") do
result = "physical"
setcode do
- if FileTest.exists?("/proc/user_beancounters")
- # openvz. can be hardware node or virtual environment
- # read the init process' status file, it has laxer permissions
- # than /proc/user_beancounters (so this won't fail as non-root)
- txt = File.read("/proc/1/status")
- if txt =~ /^envID:[[:blank:]]+0$/mi
+ require 'thread'
+
+ if FileTest.exists?("/sbin/zonename")
+ z = %x{"/sbin/zonename"}.chomp
+ if z != 'global'
+ result = 'zone'
+ end
+ end
+
+ if FileTest.exists?("/proc/vz/veinfo")
+ if FileTest.exists?("/proc/vz/version")
result = "openvzhn"
else
result = "openvzve"
end
end
- if FileTest.exists?("/proc/xen/capabilities") && FileTest.readable?("/proc/xen/capabilities")
+ if FileTest.exists?("/proc/self/status")
+ txt = File.read("/proc/self/status")
+ if txt =~ /^(s_context|VxID):[[:blank:]]*[1-9]/
+ result = "vserver"
+ end
+ end
+
+ if FileTest.exists?("/proc/virtual")
+ result = "vserver_host"
+ end
+
+ # new Xen domains have this in dom0 not domu :(
+ if FileTest.exists?("/proc/sys/xen/independent_wallclock")
+ result = "xenu"
+ end
+ if FileTest.exists?("/sys/bus/xen")
+ result = "xenu"
+ end
+
+ if FileTest.exists?("/proc/xen/capabilities")
txt = File.read("/proc/xen/capabilities")
if txt =~ /control_d/i
- result = "xen0"
- else
- result = "xenu"
+ result = "xen0"
end
end
-
+
if result == "physical"
- path = %x{which lspci 2> /dev/null}.chomp
- if path !~ /no lspci/
- output = %x{#{path}}
- output.each do |p|
+ output = Facter::Util::Resolution.exec('lspci')
+ if not output.nil?
+ output.each_line do |p|
# --- look for the vmware video card to determine if it is virtual => vmware.
# --- 00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter
result = "vmware" if p =~ /VM[wW]are/
end
else
- path = %x{which dmidecode 2> /dev/null}.chomp
- if path !~ /no dmidecode/
- output = %x{#{path}}
- output.each do |pd|
+ output = Facter::Util::Resolution.exec('dmidecode')
+ if not output.nil?
+ output.each_line do |pd|
result = "vmware" if pd =~ /VMware|Parallels/
end
else
- path = %x{which prtdiag 2> /dev/null}.chomp
- if path !~ /no prtdiag/
- output = %x{#{path}}
- output.each do |pd|
+ output = Facter::Util::Resolution.exec('prtdiag')
+ if not output.nil?
+ output.each_line do |pd|
result = "vmware" if pd =~ /VMware|Parallels/
end
end
@@ -58,18 +77,19 @@ Facter.add("virtual") do
result = "vmware_server"
end
- mountexists = system "which mount > /dev/null 2>&1"
- if $?.exitstatus == 0
- output = %x{mount}
- output.each do |p|
- result = "vserver" if p =~ /\/dev\/hdv1/
- end
- end
+ result
+ end
+end
+
+Facter.add("is_virtual") do
+ confine :kernel => %w{Linux FreeBSD OpenBSD SunOS}
- if FileTest.directory?('/proc/virtual')
- result = "vserver_host"
+ setcode do
+ case Facter.value(:virtual)
+ when "xenu", "openvzve", "vmware"
+ true
+ else
+ false
end
-
- result
end
end
diff --git a/spec/unit/data/darwin_ifconfig_all_with_multiple_interfaces b/spec/unit/data/darwin_ifconfig_all_with_multiple_interfaces
new file mode 100644
index 0000000..fb94751
--- /dev/null
+++ b/spec/unit/data/darwin_ifconfig_all_with_multiple_interfaces
@@ -0,0 +1,10 @@
+lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
+ inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
+ inet 127.0.0.1 netmask 0xff000000
+ inet6 ::1 prefixlen 128
+en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
+ inet6 fe80::223:6cff:fe99:602b%en1 prefixlen 64 scopeid 0x5
+ inet 192.168.0.10 netmask 0xffffff00 broadcast 192.168.0.255
+ ether 00:23:6c:99:60:2b
+ media: autoselect status: active
+ supported media: autoselect
diff --git a/spec/unit/operatingsystem.rb b/spec/unit/operatingsystem.rb
new file mode 100644
index 0000000..4c3fb3b
--- /dev/null
+++ b/spec/unit/operatingsystem.rb
@@ -0,0 +1,36 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../spec_helper'
+
+require 'facter'
+
+describe "Operating System fact" do
+
+
+ after do
+ Facter.clear
+ end
+
+ it "should default to the kernel name" do
+ Facter.fact(:kernel).stubs(:value).returns("Nutmeg")
+
+ Facter.fact(:operatingsystem).value.should == "Nutmeg"
+ end
+
+ it "should be Solaris for SunOS" do
+ Facter.fact(:kernel).stubs(:value).returns("SunOS")
+
+ Facter.fact(:operatingsystem).value.should == "Solaris"
+ end
+
+ it "should identify Oracle VM as OVS" do
+
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ FileTest.stubs(:exists?).returns false
+
+ FileTest.expects(:exists?).with("/etc/ovs-release").returns true
+ FileTest.expects(:exists?).with("/etc/enterprise-release").returns true
+
+ Facter.fact(:operatingsystem).value.should == "OVS"
+ end
+end
diff --git a/spec/unit/selinux.rb b/spec/unit/selinux.rb
new file mode 100644
index 0000000..8afa463
--- /dev/null
+++ b/spec/unit/selinux.rb
@@ -0,0 +1,48 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../spec_helper'
+
+require 'facter'
+
+describe "SELinux facts" do
+
+
+ after do
+ Facter.clear
+ end
+
+ it "should return true if SELinux enabled" do
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+
+ FileTest.stubs(:exists?).returns false
+ File.stubs(:read).with("/proc/self/attr/current").returns("notkernel")
+
+ FileTest.expects(:exists?).with("/selinux/enforce").returns true
+ FileTest.expects(:exists?).with("/proc/self/attr/current").returns true
+ File.expects(:read).with("/proc/self/attr/current").returns("kernel")
+
+ Facter.fact(:selinux).value.should == "true"
+ end
+
+ it "should return true if SELinux policy enabled" do
+ Facter.fact(:selinux).stubs(:value).returns("true")
+
+ FileTest.stubs(:exists?).returns false
+ File.stubs(:read).with("/selinux/enforce").returns("0")
+
+ FileTest.expects(:exists?).with("/selinux/enforce").returns true
+ File.expects(:read).with("/selinux/enforce").returns("1")
+
+ Facter.fact(:selinux_enforced).value.should == "true"
+ end
+
+ it "should return an SELinux policy version" do
+ Facter.fact(:selinux).stubs(:value).returns("true")
+
+ File.stubs(:read).with("/selinux/policyvers").returns("")
+
+ File.expects(:read).with("/selinux/policyvers").returns("1")
+
+ Facter.fact(:selinux_policyversion).value.should == "1"
+ end
+end
diff --git a/spec/unit/util/confine.rb b/spec/unit/util/confine.rb
index 5c1ce3b..757ca26 100755
--- a/spec/unit/util/confine.rb
+++ b/spec/unit/util/confine.rb
@@ -3,6 +3,9 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require 'facter/util/confine'
+require 'facter/util/values'
+
+include Facter::Util::Values
describe Facter::Util::Confine do
it "should require a fact name" do
@@ -17,10 +20,6 @@ describe Facter::Util::Confine do
Facter::Util::Confine.new("yay", "test", "other").values.should == ["test", "other"]
end
- it "should convert all values to strings" do
- Facter::Util::Confine.new("yay", :test).values.should == %w{test}
- end
-
it "should fail if no fact name is provided" do
lambda { Facter::Util::Confine.new(nil, :test) }.should raise_error(ArgumentError)
end
@@ -35,7 +34,7 @@ describe Facter::Util::Confine do
describe "when evaluating" do
before do
- @confine = Facter::Util::Confine.new("yay", "one", "two")
+ @confine = Facter::Util::Confine.new("yay", "one", "two", "Four", :xy, true, 1, [3,4])
@fact = mock 'fact'
Facter.stubs(:[]).returns @fact
end
@@ -66,10 +65,76 @@ describe Facter::Util::Confine do
@confine.true?.should be_true
end
+ it "should return true if any of the provided symbol values matches the fact's value" do
+ @fact.stubs(:value).returns :xy
+
+ @confine.true?.should be_true
+ end
+
+ it "should return true if any of the provided integer values matches the fact's value" do
+ @fact.stubs(:value).returns 1
+
+ @confine.true?.should be_true
+ end
+
+ it "should return true if any of the provided boolan values matches the fact's value" do
+ @fact.stubs(:value).returns true
+
+ @confine.true?.should be_true
+ end
+
+ it "should return true if any of the provided array values matches the fact's value" do
+ @fact.stubs(:value).returns [3,4]
+
+ @confine.true?.should be_true
+ end
+
+ it "should return true if any of the provided symbol values matches the fact's string value" do
+ @fact.stubs(:value).returns :one
+
+ @confine.true?.should be_true
+ end
+
+ it "should return true if any of the provided string values matches case-insensitive the fact's value" do
+ @fact.stubs(:value).returns "four"
+
+ @confine.true?.should be_true
+ end
+
+ it "should return true if any of the provided symbol values matches case-insensitive the fact's string value" do
+ @fact.stubs(:value).returns :four
+
+ @confine.true?.should be_true
+ end
+
+ it "should return true if any of the provided symbol values matches the fact's string value" do
+ @fact.stubs(:value).returns :Xy
+
+ @confine.true?.should be_true
+ end
+
it "should return false if none of the provided values matches the fact's value" do
@fact.stubs(:value).returns "three"
@confine.true?.should be_false
end
+
+ it "should return false if none of the provided integer values matches the fact's value" do
+ @fact.stubs(:value).returns 2
+
+ @confine.true?.should be_false
+ end
+
+ it "should return false if none of the provided boolan values matches the fact's value" do
+ @fact.stubs(:value).returns false
+
+ @confine.true?.should be_false
+ end
+
+ it "should return false if none of the provided array values matches the fact's value" do
+ @fact.stubs(:value).returns [1,2]
+
+ @confine.true?.should be_false
+ end
end
end
diff --git a/spec/unit/util/ip.rb b/spec/unit/util/ip.rb
index 4f6e2c0..512c07b 100644
--- a/spec/unit/util/ip.rb
+++ b/spec/unit/util/ip.rb
@@ -27,6 +27,12 @@ describe Facter::Util::IP do
Facter::Util::IP.get_interfaces().should == ["eth0"]
end
+ it "should return a list two interfaces on Darwin with two interfaces" do
+ sample_output_file = File.dirname(__FILE__) + '/../data/darwin_ifconfig_all_with_multiple_interfaces'
+ darwin_ifconfig = File.new(sample_output_file).read()
+ Facter::Util::IP.stubs(:get_all_interface_output).returns(darwin_ifconfig)
+ Facter::Util::IP.get_interfaces().should == ["lo0", "en0"]
+ end
it "should return a value for a specific interface" do
Facter::Util::IP.should respond_to(:get_interface_value)
@@ -37,7 +43,17 @@ describe Facter::Util::IP do
Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == []
end
- it "should return interface information for directly supported platforms" do
+ it "should return ipaddress information for Solaris" do
+ sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface"
+ solaris_ifconfig_interface = File.new(sample_output_file).read()
+
+ Facter::Util::IP.expects(:get_single_interface_output).with("e1000g0").returns(solaris_ifconfig_interface)
+ Facter.stubs(:value).with(:kernel).returns("SunOS")
+
+ Facter::Util::IP.get_interface_value("e1000g0", "ipaddress").should == "172.16.15.138"
+ end
+
+ it "should return netmask information for Solaris" do
sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface"
solaris_ifconfig_interface = File.new(sample_output_file).read()
@@ -47,7 +63,7 @@ describe Facter::Util::IP do
Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == "255.255.255.0"
end
- it "should return interface information for platforms supported via an alias" do
+ it "should return interface information for FreeBSD supported via an alias" do
sample_output_file = File.dirname(__FILE__) + "/../data/6.0-STABLE_FreeBSD_ifconfig"
ifconfig_interface = File.new(sample_output_file).read()
@@ -57,7 +73,7 @@ describe Facter::Util::IP do
Facter::Util::IP.get_interface_value("fxp0", "macaddress").should == "00:0e:0c:68:67:7c"
end
- it "should return interface information for OS X" do
+ it "should return macaddress information for OS X" do
sample_output_file = File.dirname(__FILE__) + "/../data/Mac_OS_X_10.5.5_ifconfig"
ifconfig_interface = File.new(sample_output_file).read()
@@ -67,6 +83,16 @@ describe Facter::Util::IP do
Facter::Util::IP.get_interface_value("en1", "macaddress").should == "00:1b:63:ae:02:66"
end
+ it "should return all interfaces correctly on OS X" do
+ sample_output_file = File.dirname(__FILE__) + "/../data/Mac_OS_X_10.5.5_ifconfig"
+ ifconfig_interface = File.new(sample_output_file).read()
+
+ Facter::Util::IP.expects(:get_all_interface_output).returns(ifconfig_interface)
+ Facter.stubs(:value).with(:kernel).returns("Darwin")
+
+ Facter::Util::IP.get_interfaces().should == ["lo0", "gif0", "stf0", "en0", "fw0", "en1", "vmnet8", "vmnet1"]
+ end
+
it "should return a human readable netmask on Solaris" do
sample_output_file = File.dirname(__FILE__) + "/../data/solaris_ifconfig_single_interface"
solaris_ifconfig_interface = File.new(sample_output_file).read()
diff --git a/tasks/rake/redlabpackage.rb b/tasks/rake/redlabpackage.rb
deleted file mode 100644
index 2de8005..0000000
--- a/tasks/rake/redlabpackage.rb
+++ /dev/null
@@ -1,265 +0,0 @@
-#!/usr/bin/env ruby
-
-# A raw platform for creating packages.
-
-require 'rbconfig'
-require 'rake'
-require 'rake/tasklib'
-
-# The PackageTask will create the following targets:
-#
-# [<b>:clobber_package</b>]
-# Delete all the package files. This target is automatically
-# added to the main clobber target.
-#
-# [<b>:repackage</b>]
-# Rebuild the package files from scratch, even if they are not out
-# of date.
-#
-# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tgz"</b>]
-# Create a gzipped tar package (if <em>need_tar</em> is true).
-#
-# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.gz"</b>]
-# Create a gzipped tar package (if <em>need_tar_gz</em> is true).
-#
-# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tar.bz2"</b>]
-# Create a bzip2'd tar package (if <em>need_tar_bz2</em> is true).
-#
-# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.zip"</b>]
-# Create a zip package archive (if <em>need_zip</em> is true).
-#
-# Example:
-#
-# Rake::PackageTask.new("rake", "1.2.3") do |p|
-# p.need_tar = true
-# p.package_files.include("lib/**/*.rb")
-# end
-#
-class Rake::RedLabPackageTask < Rake::TaskLib
- # The different directory types we can manage.
- DIRTYPES = {
- :bindir => :bins,
- :sbindir => :sbins,
- :sitelibdir => :rubylibs
- }
-
- # Name of the package (from the GEM Spec).
- attr_accessor :name
-
- # Version of the package (e.g. '1.3.2').
- attr_accessor :version
-
- # Directory used to store the package files (default is 'pkg').
- attr_accessor :package_dir
-
- # The directory to which to publish packages and html and such.
- attr_accessor :publishdir
-
- # The package-specific publishing directory
- attr_accessor :pkgpublishdir
-
- # The Product name. Defaults to a capitalized version of the
- # package name
- attr_accessor :product
-
- # The copyright message.
- attr_accessor :copyright
-
- # The vendor.
- attr_accessor :vendor
-
- # The license file. Defaults to COPYING.
- attr_accessor :license
-
- # The readme file. Defaults to README.
- attr_accessor :readme
-
- # The description.
- attr_accessor :description
-
- # The summary.
- attr_accessor :summary
-
- # The directory in which to put the binaries. Defaults to the system
- # default.
- attr_accessor :bindir
-
- # The executables.
- attr_accessor :bins
-
- # The directory in which to put the system binaries. Defaults to the
- # system default.
- attr_accessor :sbindir
-
- # The system binaries.
- attr_accessor :sbins
-
- # The libraries.
- attr_accessor :rubylibs
-
- # The directory in which to put Ruby libraries. Defaults to the
- # system site_dir.
- attr_accessor :sitelibdir
-
- # The URL for the package.
- attr_accessor :url
-
- # The source for the package.
- attr_accessor :source
-
- # Our operating system.
- attr_reader :os
-
- # Add a required package.
- def add_dependency(name, version = nil)
- @requires[name] = version
- end
-
- # Create the tasks defined by this task library.
- def define
- fail "Version required (or :noversion)" if @version.nil?
- @version = nil if :noversion == @version
-
- directory pkgdest
- file pkgdest => self.package_dir
-
- directory self.package_dir
-
- self.mkcopytasks
-
- self
- end
-
- # Return the list of files associated with a dirname.
- def files(dirname)
- if @dirtypes.include?(dirname)
- return self.send(@dirtypes[dirname])
- else
- raise "Could not find directory type %s" % dirname
- end
- end
-
- # Create a Package Task with the given name and version.
- def initialize(name=nil, version=nil)
- # Theoretically, one could eventually add directory types here.
- @dirtypes = DIRTYPES.dup
-
- @requires = {}
-
- @name = name
- @version = version
- @package_dir = 'pkg'
- @product = name.capitalize
-
- @bindir = Config::CONFIG["bindir"]
- @sbindir = Config::CONFIG["sbindir"]
- @sitelibdir = Config::CONFIG["sitelibdir"]
-
- @license = "COPYING"
- @readme = "README"
-
- yield self if block_given?
-
- define unless name.nil?
-
- # Make sure they've provided everything necessary.
- %w{copyright vendor description}.each do |attr|
- unless self.send(attr)
- raise "You must provide the attribute %s" % attr
- end
- end
- end
-
- # Make tasks for copying/linking all of the necessary files.
- def mkcopytasks
- basedir = pkgdest()
-
- tasks = []
-
- # Iterate across all of the file locations...
- @dirtypes.each do |dirname, filemethod|
- tname = ("copy" + dirname.to_s).intern
-
- dir = self.send(dirname)
-
- reqs = []
-
- # This is where we're putting the files.
- targetdir = self.targetdir(dirname)
-
- # Make sure our target directories exist
- directory targetdir
- file targetdir => basedir
-
- # Get the file list and remove the leading directory.
- files = self.files(dirname) or next
-
- reqs = []
- files.each do |sourcefile|
- # The file without the basedir. This is necessary because
- # files are created with the path from ".", but they often
- # have 'lib' changed to 'site_ruby' or something similar.
- destfile = File.join(targetdir, sourcefile.sub(/^\w+\//, ''))
- reqs << destfile
-
- # Make sure the base directory is listed as a prereq
- sourcedir = File.dirname(sourcefile)
- destdir = nil
- unless sourcedir == "."
- destdir = File.dirname(destfile)
- reqs << destdir
- directory(destdir)
- end
-
- # Now make the task associated with creating the object in
- # question.
- if FileTest.directory?(sourcefile)
- directory(destfile)
- else
- file(destfile => sourcefile) do
- if FileTest.exists?(destfile)
- if File.stat(sourcefile) > File.stat(destfile)
- rm_f destfile
- safe_ln(sourcefile, destfile)
- end
- else
- safe_ln(sourcefile, destfile)
- end
- end
-
- # If we've set the destdir, then list it as a prereq.
- if destdir
- file destfile => destdir
- end
- end
- end
-
- # And create a task for each one
- task tname => reqs
-
- # And then mark our task as a prereq
- tasks << tname
- end
-
- task :copycode => [self.package_dir, pkgdest]
-
- task :copycode => tasks do
- puts "Finished copying"
- end
- end
-
- # Where we're copying a given type of file.
- def targetdir(dirname)
- File.join(pkgdest(), self.send(dirname)).sub("//", "/")
- end
-
- private
-
- def package_name
- @version ? "#{@name}-#{@version}" : @name
- end
-
- def package_dir_path
- "#{package_dir}/#{package_name}"
- end
-end
diff --git a/tasks/rake/reductive.rb b/tasks/rake/reductive.rb
deleted file mode 100644
index 2fbd2b4..0000000
--- a/tasks/rake/reductive.rb
+++ /dev/null
@@ -1,538 +0,0 @@
-#!/usr/bin/env ruby
-
-# The tasks associated with building Reductive Labs projects
-
-require 'rbconfig'
-require 'rake'
-require 'rake/tasklib'
-
-require 'rake/clean'
-require 'rake/testtask'
-
-$features = {}
-
-begin
- require 'rubygems'
- require 'rake/gempackagetask'
- $features[:gem] = true
-rescue Exception
- $features[:gem] = false
- $stderr.puts "No Gems; skipping"
- nil
-end
-
-begin
- require 'rdoc/rdoc'
- $features[:rdoc] = true
-rescue => detail
- $features[:rdoc] = false
- puts "No rdoc: %s" % detail
-end
-
-if $features[:rdoc]
- require 'rake/rdoctask'
-end
-
-# Create all of the standard targets for a Reductive Labs project.
-# NOTE: The reason so many of the rake tasks are generated, rather than being
-# declared directly, is that they need information from the project instance.
-# Any rake task with an instance variable (e.g., @name or @version) needs
-# to have that variable assigned *before* the task is defined. Suckage.
-class Rake::RedLabProject < Rake::TaskLib
- # The project name.
- attr_accessor :name
-
- # The project version.
- attr_accessor :version
-
- # The directory to which to publish packages and html and such.
- attr_accessor :publishdir
-
- # The package-specific publishing directory
- attr_accessor :pkgpublishdir
-
- # Create a Gem file.
- attr_accessor :mkgem
-
- # The hosts to run all of our tests on.
- attr_accessor :testhosts
-
- # The summary of this project.
- attr_accessor :summary
-
- # The description of this project.
- attr_accessor :description
-
- # The author of this project.
- attr_accessor :author
-
- # A Contact email address.
- attr_accessor :email
-
- # The URL for the project.
- attr_accessor :url
-
- # Where to get the source code.
- attr_accessor :source
-
- # Who the vendor is.
- attr_accessor :vendor
-
- # The copyright for this project
- attr_accessor :copyright
-
- # The RubyForge project.
- attr_accessor :rfproject
-
- # The list of files. Only used for gem tasks.
- attr_writer :filelist
-
- # The directory in which to store packages. Defaults to "pkg".
- attr_accessor :package_dir
-
- # The default task. Defaults to the 'alltests' task.
- attr_accessor :defaulttask
-
- # The defined requirements
- attr_reader :requires
-
- # The file containing the version string.
- attr_accessor :versionfile
-
- # Print messages on stdout
- def announce(msg = nil)
- puts msg
- end
-
- # Print messages on stderr
- def warn(msg = nil)
- $stderr.puts msg
- end
-
- def add_dependency(name, version)
- @requires[name] = version
- end
-
- # Where we'll be putting the code.
- def codedir
- unless defined? @codedir
- @codedir = File.join(self.package_dir, "#{@name}-#{@version}")
- end
-
- return @codedir
- end
-
- # Retrieve the current version from the code.
- def currentversion
- unless defined? @currentversion
- ver = %x{ruby -Ilib ./bin/#{@name} --version}.chomp
- if $? == 0 and ver != ""
- @currentversion = ver
- else
- warn "Could not retrieve current version; using 0.0.0"
- @currentversion = "0.0.0"
- end
- end
-
- return @currentversion
- end
-
- # Define all of our package tasks. We just search through all of our
- # defined methods and call anything that's listed as making tasks.
- def define
- self.methods.find_all { |method| method.to_s =~ /^mktask/ }.each { |method|
- self.send(method)
- }
- end
-
- def egrep(pattern)
- Dir['**/*.rb'].each do |fn|
- count = 0
- open(fn) do |f|
- while line = f.gets
- count += 1
- if line =~ pattern
- puts "#{fn}:#{count}:#{line}"
- end
- end
- end
- end
- end
-
- # List all of the files.
- def filelist
- unless defined? @createdfilelist
- # If they passed in a file list as an array, then create a FileList
- # object out of it.
- if defined? @filelist
- unless @filelist.is_a? FileList
- @filelist = FileList[@filelist]
- end
- else
- # Use a default file list.
- @filelist = FileList[
- 'install.rb',
- '[A-Z]*',
- 'lib/**/*.rb',
- 'test/**/*.rb',
- 'bin/**/*',
- 'ext/**/*',
- 'examples/**/*',
- 'conf/**/*'
- ]
- end
- @filelist.delete_if {|item| item.include?(".git")}
-
- @createdfilelist = true
- end
-
- @filelist
- end
-
- def has?(feature)
- feature = feature.intern if feature.is_a? String
- if $features.include?(feature)
- return $features[feature]
- else
- return true
- end
- end
-
- def initialize(name, version = nil)
- @name = name
-
- if ENV['REL']
- @version = ENV['REL']
- else
- @version = version || self.currentversion
- end
-
- @defaulttask = :alltests
- @publishdir = "/opt/rl/docroots/reductivelabs.com/htdocs/downloads"
- @pkgpublishdir = "#{@publishdir}/#{@name}"
-
- @email = "dev at reductivelabs.com"
- @url = "http://reductivelabs.com/projects/#{@name}"
- @source = "http://reductivelabs.com/downloads/#{@name}/#{@name}-#{@version}.tgz"
- @vendor = "Reductive Labs, LLC"
- @copyright = "Copyright 2003-2008, Reductive Labs, LLC. Some Rights Reserved."
- @rfproject = @name
-
- @defaulttask = :package
-
- @package_dir = "pkg"
-
- @requires = {}
-
- @versionfile = "lib/#{@name}.rb"
-
- CLOBBER.include('doc/*')
-
- yield self if block_given?
- define if block_given?
- end
-
- def mktaskhtml
- if $features[:rdoc]
- Rake::RDocTask.new(:html) { |rdoc|
- rdoc.rdoc_dir = 'html'
- rdoc.template = 'html'
- rdoc.title = @name.capitalize
- rdoc.options << '--line-numbers' << '--inline-source' <<
- '--main' << 'README'
- rdoc.rdoc_files.include('README', 'COPYING', 'CHANGELOG')
- rdoc.rdoc_files.include('lib/**/*.rb')
- CLEAN.include("html")
- }
-
- # Publish the html.
- task :publish => [:package, :html] do
- puts Dir.getwd
- sh %{cp -r html #{self.pkgpublishdir}/apidocs}
- end
- else
- warn "No rdoc; skipping html"
- end
- end
-
- # Create a release task.
- def mktaskrelease
- desc "Make a new release"
- task :release => [
- :prerelease,
- :clobber,
- :update_version,
- :commit_newversion,
- :trac_version,
- :tag, # tag everything before we make a bunch of extra dirs
- :html,
- :package,
- :publish
- ] do
-
- announce
- announce "**************************************************************"
- announce "* Release #{@version} Complete."
- announce "* Packages ready to upload."
- announce "**************************************************************"
- announce
- end
- end
-
- # Do any prerelease work.
- def mktaskprerelease
- # Validate that everything is ready to go for a release.
- task :prerelease do
- announce
- announce "**************************************************************"
- announce "* Making Release #{@version}"
- announce "* (current version #{self.currentversion})"
- announce "**************************************************************"
- announce
-
- # Is a release number supplied?
- unless ENV['REL']
- warn "You must provide a release number when releasing"
- fail "Usage: rake release REL=x.y.z [REUSE=tag_suffix]"
- end
-
- # Is the release different than the current release.
- # (or is REUSE set?)
- if @version == self.currentversion && ! ENV['REUSE']
- fail "Current version is #{@version}, must specify REUSE=tag_suffix to reuse version"
- end
-
- # Are all source files checked in?
- if ENV['RELTEST']
- announce "Release Task Testing, skipping checked-in file test"
- else
- announce "Checking for unchecked-in files..."
- data = %x{git status}
- unless data.include?("nothing to commit")
- fail "git status is not clean ... do you have unchecked-in files?"
- end
- announce "No outstanding checkins found ... OK"
- end
- end
- end
-
- # Create the task to update versions.
- def mktaskupdateversion
- task :update_version => [:prerelease] do
- if @version == self.currentversion
- announce "No version change ... skipping version update"
- else
- announce "Updating #{@versionfile} version to #{@version}"
- open(@versionfile) do |rakein|
- open("#{@versionfile}.new", "w") do |rakeout|
- rakein.each do |line|
- if line =~ /^(\s*)#{@name.upcase}VERSION\s*=\s*/
- rakeout.puts "#{$1}#{@name.upcase}VERSION = '#{@version}'"
- else
- rakeout.puts line
- end
- end
- end
- end
- mv "#{@versionfile}.new", @versionfile
-
- end
- end
-
- desc "Commit the new versions to SVN."
- task :commit_newversion => [:update_version] do
- if ENV['RELTEST']
- announce "Release Task Testing, skipping commiting of new version"
- else
- sh %{git commit -m "Updated to version #{@version}" #{@versionfile}}
- end
- end
- end
-
- def mktasktrac_version
- task :trac_version => [:update_version] do
- tracpath = "/opt/rl/trac/#{@name}"
-
- unless FileTest.exists?(tracpath)
- announce "No Trac instance at %s" % tracpath
- else
- output = %x{sudo trac-admin #{tracpath} version list}.chomp.split("\n")
- versions = {}
- output[3..-1].each do |line|
- name, time = line.chomp.split(/\s+/)
- versions[name] = time
- end
-
- if versions.include?(@version)
- announce "Version #{@version} already in Trac"
- else
- announce "Adding #{@name} version #{@version} to Trac"
- date = [Time.now.year.to_s,
- Time.now.month.to_s,
- Time.now.day.to_s].join("-")
- system("sudo trac-admin #{tracpath} version add #{@version} #{date}")
- end
- end
- end
- end
-
- # Create the tag task.
- def mktasktag
- desc "Tag all the files with the latest release number (REL=x.y.z)"
- task :tag => [:prerelease] do
- reltag = @version
- announce "Tagging with [#{reltag}]"
-
- if ENV['RELTEST']
- announce "Release Task Testing, skipping tagging"
- else
- sh %{git tag #{reltag}}
- end
- end
- end
-
- # Create the task for testing across all hosts.
- def mktaskhosttest
- desc "Test Puppet on each test host"
- task :hosttest do
- out = ""
- TESTHOSTS.each { |host|
- puts "testing %s" % host
- cwd = Dir.getwd
- file = "/tmp/#{@name}-#{host}test.out"
- system("ssh #{host} 'cd git/#{@name}/test; sudo rake' 2>&1 >#{file}")
-
- if $? != 0
- puts "%s failed; output is in %s" % [host, file]
- end
- }
- end
- end
-
- def mktaskri
- # Create a task to build the RDOC documentation tree.
-
- #Rake::RDocTask.new("ri") { |rdoc|
- # #rdoc.rdoc_dir = 'html'
- # #rdoc.template = 'html'
- # rdoc.title = "Puppet"
- # rdoc.options << '--ri' << '--line-numbers' << '--inline-source' << '--main' << 'README'
- # rdoc.rdoc_files.include('README', 'COPYING', 'CHANGELOG')
- # rdoc.rdoc_files.include('lib/**/*.rb', 'doc/**/*.rdoc')
- #}
-
- if $features[:rdoc]
- task :ri do |ri|
- files = ['README', 'COPYING', 'CHANGELOG'] + Dir.glob('lib/**/*.rb')
- puts "files are \n%s" % files.join("\n")
- begin
- ri = RDoc::RDoc.new
- ri.document(["--ri-site"] + files)
- rescue RDoc::RDocError => detail
- puts "Failed to build docs: %s" % detail
- return nil
- rescue LoadError
- puts "Missing rdoc; cannot build documentation"
- return nil
- end
- end
- else
- warn "No rdoc; skipping ri."
- end
- end
-
- desc "Install the application using the standard install.rb script"
- task :install do
- ruby "install.rb"
- end
-
- def mktaskdefault
- if dtask = self.defaulttask
- desc "Default task"
- task :default => dtask
- end
- end
-
- desc "Run all unit tests."
- task :alltests do
- if FileTest.exists?("test/Rakefile")
- sh %{cd test; rake}
- else
- Dir.chdir("test") do
- Dir.entries(".").find_all { |f| f =~ /\.rb/ }.each do |f|
- sh %{ruby #{f}}
- end
- end
- end
- end
-
- desc "List all ruby files"
- task :rubyfiles do
- puts Dir['**/*.rb'].reject { |fn| fn =~ /^pkg/ }
- puts Dir['**/bin/*'].reject { |fn| fn =~ /svn|(~$)|(\.rb$)/ }
- end
-
- desc "Look for TODO and FIXME tags in the code"
- task :todo do
- egrep "/#.*(FIXME|TODO|TBD)/"
- end
-
- # This task requires extra information from the Rake file.
- def mkgemtask
- # ====================================================================
- # Create a task that will package the Rake software into distributable
- # tar, zip and gem files.
- if ! defined?(Gem)
- puts "Package Target requires RubyGEMs"
- else
- spec = Gem::Specification.new { |s|
-
- #### Basic information.
-
- s.name = self.name
- s.version = self.version
- s.summary = self.summary
- s.description = self.description
- s.platform = Gem::Platform::RUBY
-
- #### Dependencies and requirements.
-
- # I'd love to explicitly list all of the libraries that I need,
- # but gems seem to only be able to handle dependencies on other
- # gems, which is, um, stupid.
- self.requires.each do |name, version|
- s.add_dependency(name, ">= #{version}")
- end
-
- s.files = filelist.to_a
-
- #### Signing key and cert chain
- #s.signing_key = '/..../gem-private_key.pem'
- #s.cert_chain = ['gem-public_cert.pem']
-
- #### Author and project details.
-
- s.author = [self.author]
- s.email = self.email
- s.homepage = self.url
- s.rubyforge_project = self.rfproject
-
- yield s
- }
-
- Rake::GemPackageTask.new(spec) { |pkg|
- pkg.need_tar = true
- }
-
- desc "Copy the newly created package into the downloads directory"
- task :publish => [:package] do
- puts Dir.getwd
- sh %{cp pkg/#{@name}-#{@version}.gem #{self.publishdir}/gems}
- sh %{gem generate_index -d #{self.publishdir}}
- sh %{cp pkg/#{@name}-#{@version}.tgz #{self.pkgpublishdir}}
- sh %{ln -sf #{@name}-#{@version}.tgz #{self.pkgpublishdir}/#{@name}-latest.tgz}
- end
- CLEAN.include("pkg")
- end
- end
-end
--
Packaging of Facter for debian
More information about the Pkg-puppet-devel
mailing list