diff -Nru facter-1.3.8/bin/facter facter-1.5.6/bin/facter --- facter-1.3.8/bin/facter 2007-09-24 07:00:05.000000000 +0000 +++ facter-1.5.6/bin/facter 2009-05-18 22:19:03.000000000 +0000 @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +#!/usr/bin/env ruby # # = Synopsis # @@ -6,7 +6,7 @@ # # = Usage # -# facter [-d|--debug] [-h|--help] [-v|--version] [-y|--yaml] [fact] [fact] [...] +# facter [-d|--debug] [-h|--help] [-p|--puppet] [-v|--version] [-y|--yaml] [fact] [fact] [...] # # = Description # @@ -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:: @@ -24,6 +24,9 @@ # help:: # Print this help message # +# puppet:: +# Load the Puppet libraries, thus allowing Facter to load Puppet-specific facts. +# # version:: # Print the version and exit. # @@ -55,31 +58,52 @@ $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 ] + [ "--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 } -result.each { |opt,arg| - case opt +begin + result.each { |opt,arg| + case opt when "--version" puts "%s" % Facter.version exit + when "--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 @@ -90,30 +114,30 @@ else $stderr.puts "Invalid option '#{opt}'" exit(12) - end -} + end + } +rescue + 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 } -facts = {} - if names.empty? - Facter.each { |name,fact| - facts[name] = fact - } + facts = Facter.to_hash else + facts = {} names.each { |name| begin facts[name] = Facter.value(name) @@ -139,5 +163,3 @@ puts "%s => %s" % [name,value] end } - -# $Id: facter,v 1.1.1.1 2004/03/21 21:06:27 luke Exp $ diff -Nru facter-1.3.8/CHANGELOG facter-1.5.6/CHANGELOG --- facter-1.3.8/CHANGELOG 2007-09-24 07:00:14.000000000 +0000 +++ facter-1.5.6/CHANGELOG 2009-06-04 22:08:10.000000000 +0000 @@ -1,11 +1,254 @@ +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 + kernelversion == uname -v + + Added support for Oracle VM Server to operatingsystem + and operatingsystemrelease + + Added support for Oracle Enterprise Linux to operatingsystem + and operatingsystemrelease + + Fixed #1927 - failing facts don't kill Facter + + Fixed #1850 - Facter updates for Ruby 1.9 + + Fixed #1926 - IPAddr to_s issue + + Fixed Ubuntu operatingsystem identification + + Fixed generic uptime fact + + Fixed #1924 - Fixed lo / lo:0 local interface matching +1.5.3: + Added network fact + + Fixed #1870 - Format all subnet masks as human-readable + + Added uptime facts + + Fixed autotest on win32 + + Fixed #1870 - Added interface support for Darwin + + Fixed #1791 - support for virtual fact on Solaris 10 + + Fixed #1793 - Added more Solaris 10 facts + + Fixed errors on unrecognised option in binary + + Added ci namespace and Rake tasks + + 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 + hardware nodes and virtual environments + + Fixed #1509 - Fixed version recognition for SLES. + + Fixes #1582 - Fix MAC address reporting for Linux bonding + slave interfaces + + Fixed #1575 - CentOS fix for Facter SPEC file + + Fixed #1569 - createpackage.sh bug + + Fixed #1567 - createpackage.sh output + + Fixed #1547 - finally killed dots in IP address facts + +1.5.2: + Fixed #1562 - Removed facter from PREREQS + + Fixed #1558 - Updated virtual fact for xenu and xen0 + + Fixed #1555 - Ddded operatingsystemrelease for Solaris + + Fixed #1559 - Update to dmidecode fact + +1.5.1: + Added a Process.waitall thread when there's a timeout, to avoid zombies. + + Set the timeout the host-based and resolve-based resolutions to 2. + + Fixed #1495 - CentOS version detection is now better. + + Fixed #1422 - Facter now defaults to 0 timeout. + + Fixes #1492 - added kernelversion fact + + Added virtual fact + + Modified the operatingsystem fact for Debian so it looks in + /etc/debian_version instead of /proc/version. + + Fixes #1467 - macaddress not set on Ubuntu + + Adding a rake task for creating an archive. + + Adding better SuSE detection for both operatingsystem and release. + + Add sample test and strawman solution for IP parsing code + + Add module level tests for Facter::IPAddress + + Fixed #1425 - Solaris + + Feature #1487: Package creation scripts for Mac OS X + + Feature #1478: Allow specification of --bindir --sbindir --sitelibdir --mandir + + Feature #1475: CONFIG['bindir'] CONFIG['sbindir'] have undesirable defaults on + + Fixes #1467 - macaddress not set on Ubuntu + + 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 + + Fixed #1400 - OperatingSystemRelease should now work on CentOS + + Changed 'timeout' option to 'limit' to avoid scope issue + + Fixes #1376 - Display memory facts for AIX + + Fixes #1334 - Forced Facter to use LANG=C + + Fixes #1357 - Change ps syntax for OSX and BSD + + Set the timeout on the AIX kernelrelease fact to 5 seconds. + + Refactored so each fact resolution can specify a separate timeout, + but the default is still 0.5. + + Refactered ipmess.rb and util/ip.rb to support separate *BSD logic for + *BSD aliased interfaces. + + Updated dmidecode facts fixing ticket #60 + + Added AIX support for some facts + + Add lsbmajdistrelease fact for CentOS and Red Hat + + 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. + + Added autoloading to Facter with a default of not loading all facts, + which results in a significant speedup when only one fact is sought. + Facts are autoloaded in either a single file named after the fact or + in any file in a directory named after the fact. + + 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 + 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. + 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 + operatingsystem and operatingsystemrelease facts. + + The Debian operatingsystemrelease fact now correctly returns the current + Debian release. + + Fixed ticket #48 - ioperatingsystem and operatingsystemrelease for CentOS + + Fixed ticket #44 and allowed support for Xen multiple interfaces and aliased + interfaces. Supports both Linux and *BSD. + + Added interfaces fact to add as index for ip/MAC address facts + + Added Mandrake support for operatingsystem fact - closed ticket #47 + + Fixed ticket #45 + + 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 @@ -99,4 +342,4 @@ adding new fact resolution mechanisms at run-time. 1.0b1: - Initial release. + Initial release. diff -Nru facter-1.3.8/conf/osx/createpackage.sh facter-1.5.6/conf/osx/createpackage.sh --- facter-1.3.8/conf/osx/createpackage.sh 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/conf/osx/createpackage.sh 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,168 @@ +#!/bin/bash +# +# Script to build an "old style" not flat pkg out of the facter repository. +# +# Author: Nigel Kersten (nigelk@google.com) +# +# 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. +# See the License for the specific language governing permissions and +# limitations under the License + + +INSTALLRB="install.rb" +BINDIR="/usr/bin" +SITELIBDIR="/usr/lib/ruby/site_ruby/1.8" +PACKAGEMAKER="/Developer/usr/bin/packagemaker" +PROTO_PLIST="PackageInfo.plist" +PREFLIGHT="preflight" + + +function find_installer() { + # 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}" + elif [ -f "../${INSTALLRB}" ]; then + installer="$(pwd)/../${INSTALLRB}" + elif [ -f "../../${INSTALLRB}" ]; then + installer="$(pwd)/../${INSTALLRB}" + else + installer="" + fi +} + +function find_facter_root() { + facter_root=$(dirname "${installer}") +} + +function install_facter() { + echo "Installing Facter to ${pkgroot}" + cd "$facter_root" + ./"${INSTALLRB}" --destdir="${pkgroot}" --bindir="${BINDIR}" --sitelibdir="${SITELIBDIR}" + chown -R root:admin "${pkgroot}" +} + +function get_facter_version() { + facter_version=$(RUBYLIB="${pkgroot}/${SITELIBDIR}:${RUBYLIB}" ruby -e "require 'facter'; puts Facter.version") +} + +function prepare_package() { + # As we can't specify to follow symlinks from the command line, we have + # to go through the hassle of creating an Info.plist file for packagemaker + # 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 + # follow symlinks. + VER1=$(echo ${facter_version} | awk -F "." '{print $1}') + VER2=$(echo ${facter_version} | awk -F "." '{print $2}') + VER3=$(echo ${facter_version} | awk -F "." '{print $3}') + major_version="${VER1}" + minor_version="${VER2}${VER3}" + cp "${facter_root}/conf/osx/${PROTO_PLIST}" "${pkgtemp}" + 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}" + chmod 0755 "${pkgtemp}/scripts/${PREFLIGHT}" +} + +function create_package() { + rm -fr "$(pwd)/facter-${facter_version}.pkg" + echo "Building package" + echo "Note that packagemaker is reknowned for spurious errors. Don't panic." + "${PACKAGEMAKER}" --root "${pkgroot}" \ + --info "${pkgtemp}/${PROTO_PLIST}" \ + --scripts ${pkgtemp}/scripts \ + --out "$(pwd)/facter-${facter_version}.pkg" + if [ $? -ne 0 ]; then + echo "There was a problem building the package." + cleanup_and_exit 1 + exit 1 + else + echo "The package has been built at:" + echo "$(pwd)/facter-${facter_version}.pkg" + fi +} + +function cleanup_and_exit() { + if [ -d "${pkgroot}" ]; then + rm -fr "${pkgroot}" + fi + if [ -d "${pkgtemp}" ]; then + rm -fr "${pkgtemp}" + fi + exit $1 +} + +# Program entry point +function main() { + + if [ $(whoami) != "root" ]; then + echo "This script needs to be run as root via su or sudo." + cleanup_and_exit 1 + 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 +} + +main "$@" diff -Nru facter-1.3.8/conf/osx/PackageInfo.plist facter-1.5.6/conf/osx/PackageInfo.plist --- facter-1.3.8/conf/osx/PackageInfo.plist 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/conf/osx/PackageInfo.plist 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,36 @@ + + + + + CFBundleIdentifier + com.reductivelabs.facter + CFBundleShortVersionString + {SHORTVERSION} + IFMajorVersion + {MAJORVERSION} + IFMinorVersion + {MINORVERSION} + IFPkgFlagAllowBackRev + + IFPkgFlagAuthorizationAction + RootAuthorization + IFPkgFlagDefaultLocation + / + IFPkgFlagFollowLinks + + IFPkgFlagInstallFat + + IFPkgFlagIsRequired + + IFPkgFlagOverwritePermissions + + IFPkgFlagRelocatable + + IFPkgFlagRestartAction + None + IFPkgFlagRootVolumeOnly + + IFPkgFlagUpdateInstalledLanguages + + + diff -Nru facter-1.3.8/conf/osx/preflight facter-1.5.6/conf/osx/preflight --- facter-1.3.8/conf/osx/preflight 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/conf/osx/preflight 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,12 @@ +#!/bin/bash +# +# Make sure that old facter cruft is removed +# This also allows us to downgrade facter as +# it's more likely that installing old versions +# over new will cause issues. +# +# ${3} is the destination volume so that this works correctly +# when being installed to volumes other than the current OS. + +/bin/rm -Rf "${3}{SITELIBDIR}/facter" +/bin/rm -Rf "${3}{SITELIBDIR}/facter.rb" diff -Nru facter-1.3.8/conf/redhat/facter.spec facter-1.5.6/conf/redhat/facter.spec --- facter-1.3.8/conf/redhat/facter.spec 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/conf/redhat/facter.spec 2009-06-04 22:08:10.000000000 +0000 @@ -0,0 +1,130 @@ +%{!?ruby_sitelibdir: %define ruby_sitelibdir %(ruby -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]')} + +%define has_ruby_abi 0%{?fedora} || 0%{?rhel} >= 5 +%define has_ruby_noarch %has_ruby_abi + +Summary: Ruby module for collecting simple facts about a host operating system +Name: facter +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}.tar.gz +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) +%if %has_ruby_noarch +BuildArch: noarch +%endif + +Requires: ruby >= 1.8.1 +Requires: which +%if %has_ruby_abi +Requires: ruby(abi) = 1.8 +%endif +BuildRequires: ruby >= 1.8.1 + +%description +Ruby module for collecting simple facts about a host Operating +system. Some of the facts are preconfigured, such as the hostname and the +operating system. Additional facts can be added through simple Ruby scripts + +%prep +%setup -q + +%build + +%install +rm -rf %{buildroot} +ruby install.rb --destdir=%{buildroot} --quick --no-rdoc + +%clean +rm -rf %{buildroot} + + +%files +%defattr(-,root,root,-) +%{_bindir}/facter +%{ruby_sitelibdir}/facter.rb +%{ruby_sitelibdir}/facter +%doc CHANGELOG COPYING INSTALL LICENSE README + + +%changelog +* Fri May 22 2009 Todd Zullinger - 1.5.5-1 +- Update to 1.5.5 +- Drop upstreamed libperms patch + +* Sat Feb 28 2009 Todd Zullinger - 1.5.4-1 +- New version +- Use upstream install script + +* Tue Sep 09 2008 Todd Zullinger - 1.5.2-1 +- New version +- Simplify spec file checking for Fedora and RHEL versions + +* Mon Sep 8 2008 David Lutterkort - 1.5.1-1 +- New version + +* Thu Jul 17 2008 David Lutterkort - 1.5.0-3 +- Change 'mkdir' in install to 'mkdir -p' + +* Thu Jul 17 2008 David Lutterkort - 1.5.0-2 +- Remove files that were listed twice in files section + +* Mon May 19 2008 James Turnbull - 1.5.0-1 +- New version +- Added util and plist files + +* Mon Sep 24 2007 David Lutterkort - 1.3.8-1 +- Update license tag +- Copy all of lib/ into ruby_sitelibdir + +* Thu Mar 29 2007 David Lutterkort - 1.3.7-1 +- New version + +* Fri Jan 19 2007 David Lutterkort - 1.3.6-1 +- New version + +* Thu Jan 18 2007 David Lutterkort - 1.3.5-3 +- require which; facter is very unhappy without it + +* Mon Nov 20 2006 David Lutterkort - 1.3.5-2 +- Make require ruby(abi) and buildarch: noarch conditional for fedora 5 or + later to allow building on older fedora releases + +* Tue Oct 10 2006 David Lutterkort - 1.3.5-1 +- New version + +* Tue Sep 26 2006 David Lutterkort - 1.3.4-1 +- New version + +* Wed Sep 13 2006 David Lutterkort - 1.3.3-2 +- Rebuilt for FC6 + +* Wed Jun 28 2006 David Lutterkort - 1.3.3-1 +- Rebuilt + +* Fri Jun 19 2006 Luke Kanies - 1.3.0-1 +- Fixed spec file to work again with the extra memory and processor files. +- Require ruby(abi). Build as noarch + +* Fri Jun 9 2006 Luke Kanies - 1.3.0-1 +- Added memory.rb and processor.rb + +* Mon Apr 17 2006 David Lutterkort - 1.1.4-4 +- Rebuilt with changed upstream tarball + +* Tue Mar 21 2006 David Lutterkort - 1.1.4-3 +- Do not rely on install.rb, it will be deleted upstream + +* Mon Mar 13 2006 David Lutterkort - 1.1.4-2 +- Commented out noarch; requires fix for bz184199 + +* Mon Mar 6 2006 David Lutterkort - 1.1.4-1 +- Removed unused macros + +* Mon Feb 6 2006 David Lutterkort - 1.1.1-2 +- Fix BuildRoot. Add dist to release tag + +* Wed Jan 11 2006 David Lutterkort - 1.1.1-1 +- Initial build. diff -Nru facter-1.3.8/conf/solaris/pkginfo facter-1.5.6/conf/solaris/pkginfo --- facter-1.3.8/conf/solaris/pkginfo 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/conf/solaris/pkginfo 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,7 @@ +PKG=CSWfacter +NAME=facter - System Fact Gatherer +VERSION=1.3.5 +CATEGORY=application +VENDOR=http://reductivelabs.com/projects/facter +HOTLINE=http://reductivelabs.com/cgi-bin/facter.cgi +EMAIL=luke@madstop.com diff -Nru facter-1.3.8/COPYING facter-1.5.6/COPYING --- facter-1.3.8/COPYING 2007-09-24 06:57:18.000000000 +0000 +++ facter-1.5.6/COPYING 2009-05-18 22:19:03.000000000 +0000 @@ -1,397 +1,221 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + 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. -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -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 and use pieces of -it in new free programs; and that you are informed that you can do -these things. +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 -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. +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. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. +modification follow. - GNU LESSER GENERAL PUBLIC LICENSE + GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, 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 library. + 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 +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete 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 distribute a copy of this License along with the -Library. - - 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 Library or any portion -of it, thus forming a work based on the Library, and copy and +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) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices + a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - + 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 Library, +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 Library, the distribution of the whole must be on the terms of +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. +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 Library. +collective works based on the Program. -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of +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 opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you 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. - - If distribution of 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 satisfies the requirement to -distribute the source code, even though third parties are not + 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. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be 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. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library 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. + 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. - 9. You are not required to accept this License, since you have not + 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 Library or its derivative works. These actions are +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 Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and +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 Library or works based on it. +the Program or works based on it. - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further + 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 with +You are not responsible for enforcing compliance by third parties to this License. - - 11. If, as a consequence of a court judgment or allegation of patent + + 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 Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by +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 Library. +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. +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 +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 @@ -401,58 +225,116 @@ This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library 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. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser 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 Library -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 Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -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. + 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 - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "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 -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. 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 LIBRARY 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 -LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. + 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. + + + Copyright (C) + + 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. + + , 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 -Nru facter-1.3.8/debian/changelog facter-1.5.6/debian/changelog --- facter-1.3.8/debian/changelog 2011-12-30 09:01:07.000000000 +0000 +++ facter-1.5.6/debian/changelog 2011-12-30 09:01:07.000000000 +0000 @@ -1,3 +1,108 @@ +facter (1.5.6-2ubuntu2.3~hardy1~ppa1) hardy; urgency=low + + * No-change backport to hardy + + -- Micah Gersten Fri, 30 Dec 2011 02:49:28 -0600 + +facter (1.5.6-2ubuntu2.3) lucid-proposed; urgency=low + + * lib/facter/ec2.rb: Rescue condition in can_connect() when timeout() + actually has a chance to timeout. (LP: #885998) + + -- Adam Gandelman Mon, 07 Nov 2011 10:18:18 -0800 + +facter (1.5.6-2ubuntu2.2) lucid-proposed; urgency=low + + * lib/facter/ec2.rb: Properly handle ip+port when testing connectivity + of ec2 metadata service.(LP: #732953) + * lib/facter/util/collection.rb: Backported fix from upstream commit + 2255abee7bdb9b6478ca228546e3d275dbac0ec3. Reload all facts if the + requested fact is not found. Ensures consistency after facts + have been cleared. (LP: #876130) + + -- Adam Gandelman Tue, 25 Oct 2011 10:28:17 -0700 + +facter (1.5.6-2ubuntu2.1) lucid-proposed; urgency=low + + * Cherry-picked KVM detection for 'virtual' fact from upstream commit + 62b6773a63bb96273fbc. (LP: #708080). + + -- Oliver Brakmann Wed, 26 Jan 2011 21:36:23 +0100 + +facter (1.5.6-2ubuntu2) lucid; urgency=low + + * Dropped ruby-pkg-tools, and libsetup-ruby1.8, and cdbs, use what + we had in karmic. Since we dont want ruby-pkg-tools in main. + (LP: #408402) + + -- Chuck Short Fri, 26 Mar 2010 08:34:25 -0400 + +facter (1.5.6-2ubuntu1) lucid; urgency=low + + * Merge from debian testing, remaining changes: + - Use bind9-host9 only. + + -- Chuck Short Fri, 06 Nov 2009 00:52:19 +0000 + +facter (1.5.6-2) unstable; urgency=low + + * Added depends possibility on libopenssl-ruby1.9 + * Switch from install.rb to using the standardized Debian ruby CDBS + classes to use setup.rb. This stops the munging of the shebang + to a specific ruby version, as facter works with both 1.8 and 1.9 + * Install facter library dependencies in ruby version neutral + directory: /usr/lib/ruby/vendor_ruby + * Add depends on libsetup-ruby1.8, ruby-pkg-tools and cdbs + + -- Micah Anderson Tue, 30 Jun 2009 00:21:23 -0400 + +facter (1.5.6-1) unstable; urgency=low + + * New upsream release + * Add myself to uploaders + * Bumped Standards-Version (no changes) + * Added versioned build-depends on debhelper 5 + + -- Micah Anderson Mon, 29 Jun 2009 22:53:18 -0400 + +facter (1.5.4-1ubuntu1) karmic; urgency=low + + * Use bind9-host9 only. + + -- Chuck Short Mon, 03 Aug 2009 09:51:59 -0400 + +facter (1.5.4-1) unstable; urgency=low + + [ Nigel Kersten ] + * New upstream release + * Switch maintainer to pkg-puppet-devel list + * Modify uploaders + * Update watch file regexp to exclude release canditate tarballs + * Use upstream install.rb script to build rather than copying manually + + [ Andrew Pollock ] + * debian/control: add libopenssl-ruby to build dependencies + * debian/control: bump Standards-Version (no changes) + * debian/compat: increase to 5 + * debian/control: add pciutils and ${misc:Depends} to dependencies + + -- Andrew Pollock Mon, 13 Apr 2009 15:20:21 -0700 + +facter (1.5.1-0.1) unstable; urgency=low + + * Non-maintainer upload + * New upstream release to fix zombie problem (Closes: #497363) + + -- Micah Anderson Wed, 03 Sep 2008 09:06:56 -0400 + +facter (1.5-0.1) unstable; urgency=low + + * Non-maintainer upload. + * New upstream release (Closes: #492430) + * Upgraded standards version to 3.8.0 (no changes) + + -- Micah Anderson Sat, 26 Jul 2008 07:46:56 -0400 + facter (1.3.8-1) unstable; urgency=low * New upstream release. @@ -34,3 +139,4 @@ * Initial release. (Closes: #364976) -- Matthew Palmer Wed, 24 May 2006 09:40:54 +1000 + diff -Nru facter-1.3.8/debian/compat facter-1.5.6/debian/compat --- facter-1.3.8/debian/compat 2011-12-30 09:01:07.000000000 +0000 +++ facter-1.5.6/debian/compat 2011-12-30 09:01:07.000000000 +0000 @@ -1 +1 @@ -4 +5 diff -Nru facter-1.3.8/debian/control facter-1.5.6/debian/control --- facter-1.3.8/debian/control 2011-12-30 09:01:07.000000000 +0000 +++ facter-1.5.6/debian/control 2011-12-30 09:01:07.000000000 +0000 @@ -1,14 +1,15 @@ Source: facter Section: admin Priority: optional -Maintainer: Jamie Wilkinson -Uploaders: Jamie Wilkinson , Matthew Palmer -Build-Depends: debhelper (>= 4.0.0), ruby (>= 1.8) -Standards-Version: 3.6.2 +Maintainer: Ubuntu MOTU Developers +XSBC-Original-Maintainer: Puppet Package Maintainers +Uploaders: Andrew Pollock , Nigel Kersten , Micah Anderson +Build-Depends: debhelper (>= 5.0.0), ruby (>= 1.8), libopenssl-ruby +Standards-Version: 3.8.2 Package: facter Architecture: all -Depends: ruby (>= 1.8), net-tools, host | bind9-host +Depends: ruby (>= 1.8), net-tools, bind9-host, pciutils, libopenssl-ruby1.8 | libopenssl-ruby1.9, ${misc:Depends} Description: a library for retrieving facts from operating systems A cross-platform Ruby library for retrieving facts from operating systems. Supports multiple resolution mechanisms, any of which can be restricted to diff -Nru facter-1.3.8/debian/dirs facter-1.5.6/debian/dirs --- facter-1.3.8/debian/dirs 2011-12-30 09:01:07.000000000 +0000 +++ facter-1.5.6/debian/dirs 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -usr/bin -usr/lib/ruby/1.8 diff -Nru facter-1.3.8/debian/rules facter-1.5.6/debian/rules --- facter-1.3.8/debian/rules 2011-12-30 09:01:07.000000000 +0000 +++ facter-1.5.6/debian/rules 2011-12-30 09:01:07.000000000 +0000 @@ -45,9 +45,10 @@ dh_clean -k dh_installdirs - # Add here commands to install the package into debian/facter. - cp bin/facter $(CURDIR)/debian/facter/usr/bin - cp -a lib/facter lib/facter.rb $(CURDIR)/debian/facter/usr/lib/ruby/1.8 + $(CURDIR)/install.rb --destdir=$(CURDIR)/debian/facter/ \ + --bindir=/usr/bin \ + --sbindir=/usr/sbin \ + --sitelibdir=/usr/lib/ruby/1.8 # Build architecture-dependent files here. binary-arch: build install diff -Nru facter-1.3.8/debian/watch facter-1.5.6/debian/watch --- facter-1.3.8/debian/watch 2011-12-30 09:01:07.000000000 +0000 +++ facter-1.5.6/debian/watch 2011-12-30 09:01:07.000000000 +0000 @@ -1,2 +1,2 @@ version=3 -http://reductivelabs.com/downloads/facter/facter-([0-9]+\..*)\.tgz +http://reductivelabs.com/downloads/facter/facter-([0-9]+\.[0-9]+\.[0-9]+)\.tgz diff -Nru facter-1.3.8/install.rb facter-1.5.6/install.rb --- facter-1.3.8/install.rb 2007-09-24 06:57:18.000000000 +0000 +++ facter-1.5.6/install.rb 2009-05-18 22:19:03.000000000 +0000 @@ -30,194 +30,329 @@ # 5) Install all library files ending in .rb from lib/ into Ruby's # site_lib/version directory. # -# $Id: install.rb,v 1.6 2004/08/08 20:33:09 austin Exp $ #++ require 'rbconfig' require 'find' require 'fileutils' +require 'ftools' # apparently on some system ftools doesn't get loaded require 'optparse' require 'ostruct' -InstallOptions = OpenStruct.new - -$loadedrdoc = false - begin require 'rdoc/rdoc' - $loadedrdoc = true -rescue LoadError => detail - $stderr.puts "Could not load rdoc/rdoc: %s" % detail - InstallOptions.rdoc = false + $haverdoc = true +rescue LoadError + puts "Missing rdoc; skipping documentation" + $haverdoc = false end +begin + if $haverdoc + rst2man = %x{which rst2man.py} + $haveman = true + else + $haveman = false + end +rescue + puts "Missing rst2man; skipping man page creation" + $haveman = false +end + +PREREQS = %w{openssl xmlrpc/client xmlrpc/server cgi} + +InstallOptions = OpenStruct.new def glob(list) - g = list.map { |i| Dir.glob(i) } - g.flatten! - g.compact! - g.reject! { |e| e =~ /CVS/ } - g + g = list.map { |i| Dir.glob(i) } + g.flatten! + g.compact! + g.reject! { |e| e =~ /\.svn/ } + g end - # Set these values to what you want installed. -#bins = glob(%w{bin/**/*}).reject { |e| e =~ /\.(bat|cmd)$/ } -bins = ["bin/facter"] -rdoc = glob(%w{bin/**/* lib/**/*.rb README CHANGELOG INSTALL}).reject { |e| e=~ /\.(bat|cmd)$/ } -ri = glob(%w(bin/**/* lib/**/*.rb)).reject { |e| e=~ /\.(bat|cmd)$/ } -libs = glob(%w{lib/**/*.rb}) +# Set these values to what you want installed. +sbins = glob(%w{sbin/*}) +bins = glob(%w{bin/*}) +rdoc = glob(%w{bin/* sbin/* lib/**/*.rb README README-library CHANGELOG TODO Install}).reject { |e| e=~ /\.(bat|cmd)$/ } +ri = glob(%w(bin/*.rb sbin/* lib/**/*.rb)).reject { |e| e=~ /\.(bat|cmd)$/ } +man = glob(%w{man/man8/*}) +libs = glob(%w{lib/**/*.rb lib/**/*.py}) tests = glob(%w{tests/**/*.rb}) -def do_bins(bins, target, strip = 'bin/') - bins.each do |bf| - obf = bf.gsub(/#{strip}/, '') - install_binfile(bf, obf, target) - end +def do_bins(bins, target, strip = 's?bin/') + 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) - #if File.respond_to?(:makedirs) - FileUtils.makedirs(op) - #else - # recmkdir(op) - #end - File.chmod(0755, op) - FileUtils.install(lf, olf, :mode => 0755, :verbose => 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 +end + +# Verify that all of the prereqs are installed +def check_prereqs + PREREQS.each { |pre| + begin + require pre + rescue LoadError + puts "Could not load %s; cannot install" % pre + exit -1 + end + } end ## # Prepare the file installation. # def prepare_installation - InstallOptions.rdoc = true - if RUBY_PLATFORM == "i386-mswin32" - InstallOptions.ri = false - else - InstallOptions.ri = true - 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-]tests', 'Prevents the execution of unit tests.', 'Default on.') do |ontest| - InstallOptions.tests = ontest - 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 - - bds = [".", ENV['TMP'], ENV['TEMP'], "/tmp"] - - version = [Config::CONFIG["MAJOR"], Config::CONFIG["MINOR"]].join(".") - ld = File.join(Config::CONFIG["libdir"], "ruby", version) - - sd = Config::CONFIG["sitelibdir"] - if sd.nil? - sd = $:.find { |x| x =~ /site_ruby/ } - if sd.nil? - sd = File.join(ld, "site_ruby") - elsif sd !~ Regexp.quote(version) - sd = File.join(sd, version) - end - end - - if (destdir = ENV['DESTDIR']) - bd = "#{destdir}#{Config::CONFIG['bindir']}" - sd = "#{destdir}#{sd}" - bds << bd - - FileUtils.makedirs(bd) - FileUtils.makedirs(sd) - else - bd = Config::CONFIG['bindir'] - bds << Config::CONFIG['bindir'] - end - - InstallOptions.bin_dirs = bds.compact - InstallOptions.site_dir = sd - InstallOptions.bin_dir = bd - InstallOptions.lib_dir = ld - - unless $loadedrdoc - InstallOptions.rdoc = false - InstallOptions.ri = false - end + # 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 + 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 + 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 + + 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 + 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 end ## # Build the rdoc documentation. Also, try to build the RI documentation. # def build_rdoc(files) - r = RDoc::RDoc.new - r.document(["--main", "README", "--title", "Facter -- A Fact Collecter", - "--line-numbers"] + files) - -rescue RDoc::RDocError => e - $stderr.puts e.message -rescue Exception => e - $stderr.puts "Couldn't build RDoc documentation\n#{e.message}" + return unless $haverdoc + begin + r = RDoc::RDoc.new + r.document(["--main", "README", "--title", + "Puppet -- Site Configuration Management", "--line-numbers"] + files) + rescue RDoc::RDocError => e + $stderr.puts e.message + rescue Exception => e + $stderr.puts "Couldn't build RDoc documentation\n#{e.message}" + end end def build_ri(files) - ri = RDoc::RDoc.new - ri.document(["--ri-site", "--merge"] + files) -rescue RDoc::RDocError => e - $stderr.puts e.message -rescue Exception => e - $stderr.puts e.class - $stderr.puts "Couldn't build Ri documentation\n#{e.message}" + return unless $haverdoc + begin + ri = RDoc::RDoc.new + #ri.document(["--ri-site", "--merge"] + files) + ri.document(["--ri-site"] + files) + rescue RDoc::RDocError => e + $stderr.puts e.message + rescue Exception => e + $stderr.puts "Couldn't build Ri documentation\n#{e.message}" + $stderr.puts "Continuing with install..." + end end -def run_tests(test_list) - begin - require 'test/unit/ui/console/testrunner' - require 'test/unit' - - unless defined? Test::Unit::TestCase - raise LoadError, "Could not find unit test library" +def build_man(bins) + return unless $haveman + begin + # Locate rst2man + rst2man = %x{which rst2man.py} + rst2man.chomp! + # Create puppet.conf.8 man page + %x{bin/puppetdoc --reference configuration > ./puppet.conf.rst} + %x{#{rst2man} ./puppet.conf.rst ./man/man8/puppet.conf.8} + File.unlink("./puppet.conf.rst") + + # 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") end - $:.unshift "lib" - test_list.each do |test| + rescue SystemCallError + $stderr.puts "Couldn't build man pages: " + $! + $stderr.puts "Continuing with install..." + end +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 + 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 + 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 ## @@ -226,54 +361,57 @@ # (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.bin_dirs.each do |t| - if File.directory?(t) and File.writable_real?(t) - tmp_dir = t - break - 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}" - op.write ip.read - end - end - - # We don't want bat files on darwin - if Config::CONFIG["target_os"] =~ /win/io and Config::CONFIG["target_os"] !~ /darwin/ - 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}.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.gsub(%r{/}) { "\\" }).gsub!('', 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.unlink(tmp_file2) - installed_wrapper = true - end - end - FileUtils.install(tmp_file, File.join(target, op_file), :mode => 0755, :verbose => true) - File.unlink(tmp_file) + tmp_dir = nil + InstallOptions.tmp_dirs.each do |t| + if File.directory?(t) and File.writable?(t) + tmp_dir = t + break + 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() + end + end + + 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}.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.gsub(%r{/}) { "\\" }).gsub!('', 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.unlink(tmp_file2) + installed_wrapper = true + end + end + FileUtils.install(tmp_file, File.join(target, op_file), :mode => 0755, :verbose => true) + File.unlink(tmp_file) end CMD_WRAPPER = <<-EOS @@ -287,17 +425,14 @@ :done EOS +check_prereqs prepare_installation run_tests(tests) if InstallOptions.tests #build_rdoc(rdoc) if InstallOptions.rdoc #build_ri(ri) if InstallOptions.ri -bd = nil -#if (destdir = ENV['DESTDIR']) -# bd = "#{destdir}#{Config::CONFIG['bindir']}" -#else -# bd = "#{Config::CONFIG['bindir']}" -#end - +#build_man(bins) if InstallOptions.man +do_bins(sbins, InstallOptions.sbin_dir) do_bins(bins, InstallOptions.bin_dir) do_libs(libs) +do_man(man) diff -Nru facter-1.3.8/lib/facter/architecture.rb facter-1.5.6/lib/facter/architecture.rb --- facter-1.3.8/lib/facter/architecture.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/architecture.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,25 @@ +Facter.add(:architecture) do + confine :kernel => :linux + setcode do + model = Facter.value(:hardwaremodel) + case model + # most linuxen use "x86_64" + 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 + end +end diff -Nru facter-1.3.8/lib/facter/Cfkey.rb facter-1.5.6/lib/facter/Cfkey.rb --- facter-1.3.8/lib/facter/Cfkey.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/Cfkey.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,42 @@ +## Cfkey.rb +## Facts related to cfengine +## +## 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 (version 2 of the License) +## 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 +## + +Facter.add(:Cfkey) do + setcode do + value = nil + ["/usr/local/etc/cfkey.pub", + "/etc/cfkey.pub", + "/var/cfng/keys/localhost.pub", + "/var/cfengine/ppkeys/localhost.pub", + "/var/lib/cfengine/ppkeys/localhost.pub", + "/var/lib/cfengine2/ppkeys/localhost.pub" + ].each do |file| + if FileTest.file?(file) + File.open(file) { |openfile| + value = openfile.readlines.reject { |line| + line =~ /PUBLIC KEY/ + }.collect { |line| + line.chomp + }.join("") + } + end + if value + break + end + end + + value + end +end diff -Nru facter-1.3.8/lib/facter/debianversion.rb facter-1.5.6/lib/facter/debianversion.rb --- facter-1.3.8/lib/facter/debianversion.rb 2011-12-30 09:01:07.000000000 +0000 +++ facter-1.5.6/lib/facter/debianversion.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,27 +0,0 @@ -# -# This scriptlet loads the releasename for the local Debianverison -# - -require 'thread' - -unless defined? DEBIAN_RELEASES - DEBIAN_RELEASES = { - '3.0' => 'woody', - '3.1' => 'sarge', - '4.0' => 'etch', - 'testing/unstable' => 'lenny' - } -end - -if Facter.operatingsystem == "Debian" - Thread::exclusive do - File.readlines("/etc/debian_version").each do |l| - Facter.add("Debianversion") do - setcode do - DEBIAN_RELEASES[l.strip] - end - end - end - end -end - diff -Nru facter-1.3.8/lib/facter/domain.rb facter-1.5.6/lib/facter/domain.rb --- facter-1.3.8/lib/facter/domain.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/domain.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,47 @@ +Facter.add(:domain) do + setcode do + # Get the domain from various sources; the order of these + # steps is important + + Facter.value(:hostname) + next $domain if defined? $domain and ! $domain.nil? + + domain = Facter::Util::Resolution.exec('dnsdomainname') + next domain if domain =~ /.+\..+/ + + domain = Facter::Util::Resolution.exec('domainname') + next domain if domain =~ /.+\..+/ + + if FileTest.exists?("/etc/resolv.conf") + domain = nil + search = nil + File.open("/etc/resolv.conf") { |file| + file.each { |line| + if line =~ /domain\s+(\S+)/ + domain = $1 + elsif line =~ /search\s+(\S+)/ + search = $1 + end + } + } + next domain if domain + next search if search + end + nil + end +end + +Facter.add(:domain) do + confine :kernel => :windows + setcode do + require 'win32ole' + domain = "" + wmi = WIN32OLE.connect("winmgmts://") + query = "select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True" + wmi.ExecQuery(query).each { |nic| + domain = nic.DNSDomain + break + } + domain + end +end diff -Nru facter-1.3.8/lib/facter/ec2.rb facter-1.5.6/lib/facter/ec2.rb --- facter-1.3.8/lib/facter/ec2.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/ec2.rb 2011-12-30 09:01:07.000000000 +0000 @@ -0,0 +1,38 @@ +# 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) + url = "http://#{ip}:#{port}" + Timeout::timeout(wait_sec) {open(url)} + return true + rescue Timeout::Error + return false + 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 -Nru facter-1.3.8/lib/facter/facterversion.rb facter-1.5.6/lib/facter/facterversion.rb --- facter-1.3.8/lib/facter/facterversion.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/facterversion.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,3 @@ +Facter.add(:facterversion) do + setcode { Facter::FACTERVERSION.to_s } +end diff -Nru facter-1.3.8/lib/facter/fqdn.rb facter-1.5.6/lib/facter/fqdn.rb --- facter-1.3.8/lib/facter/fqdn.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/fqdn.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,11 @@ +Facter.add(:fqdn) do + setcode do + host = Facter.value(:hostname) + domain = Facter.value(:domain) + if host and domain + [host, domain].join(".") + else + nil + end + end +end diff -Nru facter-1.3.8/lib/facter/hardwareisa.rb facter-1.5.6/lib/facter/hardwareisa.rb --- facter-1.3.8/lib/facter/hardwareisa.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/hardwareisa.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +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 OEL OVS} +end diff -Nru facter-1.3.8/lib/facter/hardwaremodel.rb facter-1.5.6/lib/facter/hardwaremodel.rb --- facter-1.3.8/lib/facter/hardwaremodel.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/hardwaremodel.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,21 @@ +Facter.add(:hardwaremodel) do + setcode 'uname -m' +end + +Facter.add(:hardwaremodel) do + confine :operatingsystem => :aix + setcode do + model = Facter::Util::Resolution.exec('lsattr -El sys0 -a modelname') + if model =~ /modelname\s(\S+)\s/ + $1 + end + end +end + +Facter.add(:hardwaremodel) do + confine :operatingsystem => :windows + setcode do + require 'rbconfig' + Config::CONFIG['host_cpu'] + end +end diff -Nru facter-1.3.8/lib/facter/hostname.rb facter-1.5.6/lib/facter/hostname.rb --- facter-1.3.8/lib/facter/hostname.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/hostname.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,25 @@ +Facter.add(:hostname, :ldapname => "cn") do + setcode do + hostname = nil + name = Facter::Util::Resolution.exec('hostname') or nil + if name + if name =~ /^([\w-]+)\.(.+)$/ + hostname = $1 + # the Domain class uses this + $domain = $2 + else + hostname = name + end + hostname + else + nil + end + end +end + +Facter.add(:hostname) do + confine :kernel => :darwin, :kernelrelease => "R7" + setcode do + %x{/usr/sbin/scutil --get LocalHostName} + end +end diff -Nru facter-1.3.8/lib/facter/id.rb facter-1.5.6/lib/facter/id.rb --- facter-1.3.8/lib/facter/id.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/id.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,15 @@ +Facter.add(:id) do + confine :operatingsystem => %w{Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX OEL OVS} + setcode "whoami" +end + +Facter.add(:id) do + confine :operatingsystem => %w{Solaris} + setcode do + if %x{id} =~ /^uid=\d+\((\S+)\)/ + $1 + else + nil + end + end +end diff -Nru facter-1.3.8/lib/facter/interfaces.rb facter-1.5.6/lib/facter/interfaces.rb --- facter-1.3.8/lib/facter/interfaces.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/interfaces.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,32 @@ +# interfaces.rb +# Try to get additional Facts about the machine's network interfaces +# +# Original concept Copyright (C) 2007 psychedelys +# Update and *BSD support (C) 2007 James Turnbull +# + +require 'facter/util/ip' + +# Note that most of this only works on a fixed list of platforms; notably, Darwin +# is missing. + +Facter.add(:interfaces) do + confine :kernel => Facter::Util::IP.supported_platforms + setcode do + Facter::Util::IP.get_interfaces.collect { |iface| Facter::Util::IP.alphafy(iface) }.join(",") + end +end + +Facter::Util::IP.get_interfaces.each do |interface| + + # Make a fact for each detail of each interface. Yay. + # There's no point in confining these facts, since we wouldn't be able to create + # them if we weren't running on a supported platform. + %w{ipaddress macaddress netmask}.each do |label| + Facter.add(label + "_" + Facter::Util::IP.alphafy(interface)) do + setcode do + Facter::Util::IP.get_interface_value(interface, label) + end + end + end +end diff -Nru facter-1.3.8/lib/facter/ipaddress.rb facter-1.5.6/lib/facter/ipaddress.rb --- facter-1.3.8/lib/facter/ipaddress.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/ipaddress.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,170 @@ +Facter.add(:ipaddress) do + confine :kernel => :linux + setcode do + ip = nil + output = %x{/sbin/ifconfig} + + output.split(/^\S/).each { |str| + if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /127\./ + ip = tmp + break + end + end + } + + ip + end +end + +Facter.add(:ipaddress) do + confine :kernel => %w{FreeBSD OpenBSD solaris} + setcode do + ip = nil + output = %x{/sbin/ifconfig} + + output.split(/^\S/).each { |str| + if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /127\./ + ip = tmp + break + end + end + } + + ip + end +end + +Facter.add(:ipaddress) do + confine :kernel => %w{NetBSD} + setcode do + ip = nil + output = %x{/sbin/ifconfig -a} + + output.split(/^\S/).each { |str| + if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /127\./ + ip = tmp + break + end + end + } + + ip + end +end + +Facter.add(:ipaddress) do + confine :kernel => %w{darwin} + setcode do + ip = nil + iface = "" + output = %x{/usr/sbin/netstat -rn} + if output =~ /^default\s*\S*\s*\S*\s*\S*\s*\S*\s*(\S*).*/ + iface = $1 + else + warn "Could not find a default route. Using first non-loopback interface" + end + if(iface != "") + output = %x{/sbin/ifconfig #{iface}} + else + output = %x{/sbin/ifconfig} + end + + output.split(/^\S/).each { |str| + if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /127\./ + ip = tmp + break + end + end + } + + ip + end +end + +Facter.add(:ipaddress) do + confine :kernel => %w{AIX} + setcode do + ip = nil + output = %x{/usr/sbin/ifconfig -a} + + output.split(/^\S/).each { |str| + if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /127\./ + ip = tmp + break + end + end + } + + ip + end +end + +Facter.add(:ipaddress) do + confine :kernel => %w{windows} + setcode do + ip = nil + output = %x{ipconfig} + + output.split(/^\S/).each { |str| + if str =~ /IP Address.*: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /127\./ + ip = tmp + break + end + end + } + 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 -Nru facter-1.3.8/lib/facter/iphostnumber.rb facter-1.5.6/lib/facter/iphostnumber.rb --- facter-1.3.8/lib/facter/iphostnumber.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/iphostnumber.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,18 @@ +Facter.add(:iphostnumber) do + confine :kernel => :darwin, :kernelrelease => "R6" + setcode do + %x{/usr/sbin/scutil --get LocalHostName} + end +end +Facter.add(:iphostnumber) do + confine :kernel => :darwin, :kernelrelease => "R6" + setcode do + ether = nil + output = %x{/sbin/ifconfig} + + output =~ /HWaddr (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ + ether = $1 + + ether + end +end diff -Nru facter-1.3.8/lib/facter/ipmess.rb facter-1.5.6/lib/facter/ipmess.rb --- facter-1.3.8/lib/facter/ipmess.rb 2007-09-24 07:00:05.000000000 +0000 +++ facter-1.5.6/lib/facter/ipmess.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,85 +0,0 @@ -# -# ipmess.rb -# Try to get additional Facts about the machine's network interfaces on Linux -# -# Original concept Copyright (C) 2007 psychedelys -# Update and *BSD support (C) 2007 James Turnbull -# -# 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 (version 2 of the License) -# 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 -# - -if Facter.kernel == "Linux" - - output = %x{/sbin/ifconfig -a} - int = nil - output.scan(/^(\w+)(\d+)/) { |str| - output_int = %x{/sbin/ifconfig #{str}} - int = "#{str}" - tmp1 = nil - tmp2 = nil - test = {} - output_int.each { |s| - int = "#{str}" - tmp1 = $1 if s =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp2 = $1 if s =~ /(?:ether|HWaddr) (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/ - if tmp1 != nil && tmp2 != nil && int != "lo" - test["ipaddress_" + int] = tmp1 - test["macaddress_" + int] = tmp2 - int = nil - tmp1 = nil - tmp2 = nil - end - } - test.each{|name,fact| - Facter.add(name) do - confine :kernel => :linux - setcode do - fact - end - end - } - } -end - -if Facter.kernel == "FreeBSD" || Facter.kernel == "OpenBSD" || Facter.kernel == "NetBSD" - - output = %x{/sbin/ifconfig -a} - int = nil - output.scan(/^(\w+)(\d+):/) { |str| - output_int = %x{/sbin/ifconfig #{str}} - int = "#{str}" - tmp1 = nil - tmp2 = nil - test = {} - output_int.each { |s| - int = "#{str}" - tmp1 = $1 if s =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp2 = $1 if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ - if tmp1 != nil && tmp2 != nil && int != "lo" - test["ipaddress_" + int] = tmp1 - test["macaddress_" + int] = tmp2 - int = nil - tmp1 = nil - tmp2 = nil - end - } - test.each{|name,fact| - Facter.add(name) do - confine :kernel => :linux - setcode do - fact - end - end - } - } -end - diff -Nru facter-1.3.8/lib/facter/kernelmajversion.rb facter-1.5.6/lib/facter/kernelmajversion.rb --- facter-1.3.8/lib/facter/kernelmajversion.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/kernelmajversion.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,5 @@ +Facter.add("kernelmajversion") do + setcode do + Facter.value(:kernelversion).split('.')[0..1].join('.') + end +end diff -Nru facter-1.3.8/lib/facter/kernel.rb facter-1.5.6/lib/facter/kernel.rb --- facter-1.3.8/lib/facter/kernel.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/kernel.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,9 @@ +Facter.add(:kernel) do + setcode do + require 'rbconfig' + case Config::CONFIG['host_os'] + when /mswin/i; 'windows' + else Facter::Util::Resolution.exec("uname -s") + end + end +end diff -Nru facter-1.3.8/lib/facter/kernelrelease.rb facter-1.5.6/lib/facter/kernelrelease.rb --- facter-1.3.8/lib/facter/kernelrelease.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/kernelrelease.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,23 @@ +Facter.add(:kernelrelease) do + setcode 'uname -r' +end + +Facter.add(:kernelrelease) do + confine :kernel => :aix + setcode 'oslevel -s' +end + +Facter.add(:kernelrelease) do + confine :kernel => %{windows} + setcode do + require 'win32ole' + version = "" + connection_string = "winmgmts://./root/cimv2" + wmi = WIN32OLE.connect(connection_string) + wmi.ExecQuery("SELECT Version from Win32_OperatingSystem").each do |ole| + version = "#{ole.Version}" + break + end + version + end +end diff -Nru facter-1.3.8/lib/facter/kernelversion.rb facter-1.5.6/lib/facter/kernelversion.rb --- facter-1.3.8/lib/facter/kernelversion.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/kernelversion.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,10 @@ +Facter.add("kernelversion") do + setcode do + Facter['kernelrelease'].value.split('-')[0] + end +end + +Facter.add("kernelversion") do + confine :kernel => :sunos + setcode 'uname -v' +end diff -Nru facter-1.3.8/lib/facter/lsbmajdistrelease.rb facter-1.5.6/lib/facter/lsbmajdistrelease.rb --- facter-1.3.8/lib/facter/lsbmajdistrelease.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/lsbmajdistrelease.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,15 @@ +# lsbmajdistrelease.rb +# +require 'facter' + +Facter.add("lsbmajdistrelease") do + 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 + else + result=Facter.value(:lsbdistrelease) + end + result + end +end diff -Nru facter-1.3.8/lib/facter/lsb.rb facter-1.5.6/lib/facter/lsb.rb --- facter-1.3.8/lib/facter/lsb.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/lsb.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,38 @@ +## lsb.rb +## Facts related to Linux Standard Base (LSB) +## +## 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 (version 2 of the License) +## 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 +## + +{ "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 + setcode do + unless defined?(@@lsbdata) and defined?(@@lsbtime) and (Time.now.to_i - @@lsbtime.to_i < 5) + type = nil + @@lsbtime = Time.now + @@lsbdata = Facter::Util::Resolution.exec('lsb_release -a 2>/dev/null') + end + + if pattern.match(@@lsbdata) + $1 + else + nil + end + end + end +end diff -Nru facter-1.3.8/lib/facter/macaddress.rb facter-1.5.6/lib/facter/macaddress.rb --- facter-1.3.8/lib/facter/macaddress.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/macaddress.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,79 @@ +Facter.add(:macaddress) do + 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_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] + end +end + +Facter.add(:macaddress) do + confine :operatingsystem => %w{FreeBSD OpenBSD} + setcode do + ether = [] + output = %x{/sbin/ifconfig} + 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 + end + ether[0] + end +end + +Facter.add(:macaddress) do + confine :kernel => :darwin + setcode do + ether = nil + output = %x{/sbin/ifconfig} + + output.split(/^\S/).each do |str| + if str =~ /10baseT/ # we're wired + str =~ /ether (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ + ether = $1 + end + end + + ether + end +end + +Facter.add(:macaddress) do + confine :kernel => %w{AIX} + setcode do + ether = [] + ip = nil + output = %x{/usr/sbin/ifconfig -a} + output.each_line do |str| + if str =~ /([a-z]+\d+): flags=/ + devname = $1 + unless devname =~ /lo0/ + output2 = %x{/usr/bin/entstat #{devname}} + 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 + end + end + end + end + ether[0] + end +end + +Facter.add(:macaddress) do + confine :kernel => %w(windows) + setcode do + ether = [] + output = %x{ipconfig /all} + 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 + end + ether[0] + end +end diff -Nru facter-1.3.8/lib/facter/macosx.rb facter-1.5.6/lib/facter/macosx.rb --- facter-1.3.8/lib/facter/macosx.rb 2007-09-24 06:57:51.000000000 +0000 +++ facter-1.5.6/lib/facter/macosx.rb 2009-05-18 22:19:03.000000000 +0000 @@ -10,11 +10,11 @@ # as published by the Free Software Foundation (version 2 of the License) # 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 +# 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 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA # Jeff McCune # There's a lot more information coming out of system_profiler -xml @@ -22,63 +22,33 @@ # at this point in time. # In particular, Installed Software might be an interesting addition. -module Facter::Macosx - require 'thread' - require 'facter/util/plist' - - # JJM I'd really like to dynamically generate these methods - # by looking at the _name key of the _items dict for each _dataType - - def self.hardware_overview - # JJM Perhaps we should cache the XML data in a "class" level object. - top_level_plist = Plist::parse_xml %x{/usr/sbin/system_profiler -xml SPHardwareDataType} - system_hardware = top_level_plist[0]['_items'][0] - system_hardware.delete '_name' - system_hardware - end - - # SPSoftwareDataType - def self.os_overview - top_level_plist = Plist::parse_xml %x{/usr/sbin/system_profiler -xml SPSoftwareDataType} - os_stuff = top_level_plist[0]['_items'][0] - os_stuff.delete '_name' - os_stuff - end - - def self.sw_vers - ver = Hash.new - [ "productName", "productVersion", "buildVersion" ].each do |option| - ver["macosx_#{option}"] = %x{sw_vers -#{option}}.strip - end - ver - end -end +require 'facter/util/macosx' -if Facter.kernel == "Darwin" - Facter::Macosx.hardware_overview.each do |fact, value| - Facter.add("sp_#{fact}") do - confine :kernel => :darwin - setcode do - value - end +if Facter.value(:kernel) == "Darwin" + Facter::Util::Macosx.hardware_overview.each do |fact, value| + Facter.add("sp_#{fact}") do + confine :kernel => :darwin + setcode do + value.to_s + end + end end - end - Facter::Macosx.os_overview.each do |fact, value| - Facter.add("sp_#{fact}") do - confine :kernel => :darwin - setcode do - value - end + Facter::Util::Macosx.os_overview.each do |fact, value| + Facter.add("sp_#{fact}") do + confine :kernel => :darwin + setcode do + value.to_s + end + end end - end - Facter::Macosx.sw_vers.each do |fact, value| - Facter.add(fact) do - confine :kernel => :darwin - setcode do - value - end + Facter::Util::Macosx.sw_vers.each do |fact, value| + Facter.add(fact) do + confine :kernel => :darwin + setcode do + value + end + end end - end end diff -Nru facter-1.3.8/lib/facter/manufacturer.rb facter-1.5.6/lib/facter/manufacturer.rb --- facter-1.3.8/lib/facter/manufacturer.rb 2007-09-24 06:57:51.000000000 +0000 +++ facter-1.5.6/lib/facter/manufacturer.rb 2009-05-18 22:19:03.000000000 +0000 @@ -1,48 +1,19 @@ -# Info about the manufacturer -# - -module Facter::Manufacturer - def self.dmi_find_system_info(name) - return nil unless FileTest.exists?("/usr/sbin/dmidecode") +# manufacturer.rb +# Facts related to hardware manufacturer +# +# - # Do not run the command more than every five seconds. - unless defined?(@data) and defined?(@time) and (Time.now.to_i - @time.to_i < 5) - @data = {} - type = nil - @time = Time.now - # It's *much* easier to just parse the whole darn file than - # to just match a chunk of it. - %x{/usr/sbin/dmidecode 2>/dev/null}.split("\n").each do |line| - case line - when /^(\S.+)$/ - type = $1.chomp - @data[type] ||= {} - when /^\s+(\S.+): (\S.*)$/ - unless type - next - end - @data[type][$1] = $2 - end - end - end +require 'facter/util/manufacturer' - if data = @data["System Information"] - data[name] - else - nil - end - end -end - -# Add the facts to Facter +query = { + '[Ss]ystem [Ii]nformation' => [ + { 'Manufacturer:' => 'manufacturer' }, + { 'Product(?: Name)?:' => 'productname' }, + { 'Serial Number:' => 'serialnumber' } + ], + '(Chassis Information|system enclosure or chassis)' => [ + { '(?:Chassis )?Type:' => 'type' } + ] +} -{:SerialNumber => "Serial Number", - :Manufacturer => "Manufacturer", - :ProductName=> "Product Name"}.each do |fact, name| - Facter.add(fact) do - confine :kernel => :linux - setcode do - Facter::Manufacturer.dmi_find_system_info(name) - end - end -end +Facter::Manufacturer.dmi_find_system_info(query) diff -Nru facter-1.3.8/lib/facter/memory.rb facter-1.5.6/lib/facter/memory.rb --- facter-1.3.8/lib/facter/memory.rb 2007-09-24 06:57:51.000000000 +0000 +++ facter-1.5.6/lib/facter/memory.rb 2009-05-18 22:19:03.000000000 +0000 @@ -1,68 +1,46 @@ -# # memory.rb # Additional Facts for memory/swap usage # # Copyright (C) 2006 Mooter Media Ltd # Author: Matthew Palmer # -# 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 (version 2 of the License) -# 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 - -module Facter::Memory - require 'thread' +# +require 'facter/util/memory' - def self.meminfo_number(tag) - memsize = "" - Thread::exclusive do - size, scale = [0, ""] - File.readlines("/proc/meminfo").each do |l| - size, scale = [$1.to_f, $2] if l =~ /^#{tag}:\s+(\d+)\s+(\S+)/ - # MemoryFree == memfree + cached + buffers - # (assume scales are all the same as memfree) - if tag == "MemFree" && - l =~ /^(?:Buffers|Cached):\s+(\d+)\s+(?:\S+)/ - size += $1.to_f - end - end - memsize = scale_number(size, scale) +{ :MemorySize => "MemTotal", + :MemoryFree => "MemFree", + :SwapSize => "SwapTotal", + :SwapFree => "SwapFree" +}.each do |fact, name| + Facter.add(fact) do + confine :kernel => :linux + setcode do + Facter::Memory.meminfo_number(name) end - - memsize end +end - def self.scale_number(size, multiplier) - suffixes = ['', 'kB', 'MB', 'GB', 'TB'] - - s = suffixes.shift - while s != multiplier - s = suffixes.shift +if Facter.value(:kernel) == "AIX" + swap = Facter::Util::Resolution.exec('swap -l') + swapfree, swaptotal = 0, 0 + swap.each do |dev| + if dev =~ /^\/\S+\s.*\s+(\S+)MB\s+(\S+)MB/ + swaptotal += $1.to_i + swapfree += $2.to_i end + end - while size > 1024.0 - size /= 1024.0 - s = suffixes.shift + Facter.add("SwapSize") do + confine :kernel => :aix + setcode do + Facter::Memory.scale_number(swaptotal.to_f,"MB") end - - return "%.2f %s" % [size, s] end -end -{:MemorySize => "MemTotal", - :MemoryFree => "MemFree", - :SwapSize => "SwapTotal", - :SwapFree => "SwapFree"}.each do |fact, name| - Facter.add(fact) do - confine :kernel => :linux + Facter.add("SwapFree") do + confine :kernel => :aix setcode do - Facter::Memory.meminfo_number(name) + Facter::Memory.scale_number(swapfree.to_f,"MB") end end end diff -Nru facter-1.3.8/lib/facter/netmask.rb facter-1.5.6/lib/facter/netmask.rb --- facter-1.3.8/lib/facter/netmask.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/netmask.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,17 @@ +# netmask.rb +# Find the netmask of the primary ipaddress +# Copyright (C) 2007 David Schmitt +# Copyright (C) 2007 Mark 'phips' Phillips +# +# idea and originial source by Mark 'phips' Phillips +# + +require 'facter/util/netmask' + +Facter.add("netmask") do + confine :kernel => [ :sunos, :linux ] + setcode do + Facter::NetMask.get_netmask + end +end + diff -Nru facter-1.3.8/lib/facter/network.rb facter-1.5.6/lib/facter/network.rb --- facter-1.3.8/lib/facter/network.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/network.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +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 + end +end diff -Nru facter-1.3.8/lib/facter/operatingsystem.rb facter-1.5.6/lib/facter/operatingsystem.rb --- facter-1.3.8/lib/facter/operatingsystem.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/operatingsystem.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,58 @@ +require 'facter/lsb' + +Facter.add(:operatingsystem) do + confine :kernel => :sunos + setcode do "Solaris" end +end + +Facter.add(:operatingsystem) do + confine :kernel => :linux + setcode do + if Facter.value(:lsbdistid) == "Ubuntu" + "Ubuntu" + elsif FileTest.exists?("/etc/debian_version") + "Debian" + elsif FileTest.exists?("/etc/gentoo-release") + "Gentoo" + elsif FileTest.exists?("/etc/fedora-release") + "Fedora" + elsif FileTest.exists?("/etc/mandriva-release") + "Mandriva" + elsif FileTest.exists?("/etc/mandrake-release") + "Mandrake" + elsif FileTest.exists?("/etc/arch-release") + "Archlinux" + elsif FileTest.exists?("/etc/enterprise-release") + 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 + "CentOS" + else + "RedHat" + end + elsif FileTest.exists?("/etc/SuSE-release") + txt = File.read("/etc/SuSE-release") + if txt =~ /^SUSE LINUX Enterprise Server/i + "SLES" + elsif txt =~ /^SUSE LINUX Enterprise Desktop/i + "SLED" + elsif txt =~ /^openSUSE/i + "OpenSuSE" + else + "SuSE" + end + end + end +end + +Facter.add(:operatingsystem) do + # Default to just returning the kernel as the operating system + setcode do Facter[:kernel].value end +end diff -Nru facter-1.3.8/lib/facter/operatingsystemrelease.rb facter-1.5.6/lib/facter/operatingsystemrelease.rb --- facter-1.3.8/lib/facter/operatingsystemrelease.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/operatingsystemrelease.rb 2009-05-22 13:30:22.000000000 +0000 @@ -0,0 +1,104 @@ +Facter.add(:operatingsystemrelease) do + confine :operatingsystem => :fedora + setcode do + File::open("/etc/fedora-release", "r") do |f| + line = f.readline.chomp + if line =~ /\(Rawhide\)$/ + "Rawhide" + elsif line =~ /release (\d+)/ + $1 + end + end + end +end + +Facter.add(:operatingsystemrelease) do + confine :operatingsystem => %w{RedHat} + setcode do + File::open("/etc/redhat-release", "r") do |f| + line = f.readline.chomp + if line =~ /\(Rawhide\)$/ + "Rawhide" + elsif line =~ /release (\d+)/ + $1 + end + end + end +end + +Facter.add(:operatingsystemrelease) do + confine :operatingsystem => :oel + setcode do + File::open("/etc/enterprise-release", "r") do |f| + line = f.readline.chomp + if line =~ /release (\d+)/ + $1 + end + end + end +end + +Facter.add(:operatingsystemrelease) do + confine :operatingsystem => :ovs + setcode do + File::open("/etc/ovs-release", "r") do |f| + line = f.readline.chomp + if line =~ /release (\d+)/ + $1 + end + end + end +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/ + release = Facter::Util::Resolution.exec('rpm -q --qf \'%{VERSION}.%{RELEASE}\' centos-release | cut -d. -f1,2') + else + release = centos_release + end + end +end + +Facter.add(:operatingsystemrelease) do + confine :operatingsystem => %w{Debian} + setcode do + release = Facter::Util::Resolution.exec('cat /etc/debian_version') + end +end + +Facter.add(:operatingsystemrelease) do + confine :operatingsystem => %w{Ubuntu} + setcode do + release = Facter::Util::Resolution.exec('cat /etc/issue') + if release =~ /Ubuntu (\d+.\d+)/ + $1 + end + end +end + +Facter.add(:operatingsystemrelease) do + 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 + else + releaseminor = "0" + end + releasemajor + "." + releaseminor + else + "unknown" + end + end +end + +Facter.add(:operatingsystemrelease) do + setcode do Facter[:kernelrelease].value end +end diff -Nru facter-1.3.8/lib/facter/physicalprocessorcount.rb facter-1.5.6/lib/facter/physicalprocessorcount.rb --- facter-1.3.8/lib/facter/physicalprocessorcount.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/physicalprocessorcount.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,7 @@ +Facter.add("physicalprocessorcount") do + confine :kernel => :linux + + setcode do + ppcount = Facter::Util::Resolution.exec('grep "physical id" /proc/cpuinfo|cut -d: -f 2|sort -u|wc -l') + end +end diff -Nru facter-1.3.8/lib/facter/processor.rb facter-1.5.6/lib/facter/processor.rb --- facter-1.3.8/lib/facter/processor.rb 2007-09-24 06:57:51.000000000 +0000 +++ facter-1.5.6/lib/facter/processor.rb 2009-05-18 22:19:03.000000000 +0000 @@ -1,26 +1,13 @@ -# # processor.rb # Additional Facts about the machine's CPUs # # Copyright (C) 2006 Mooter Media Ltd # Author: Matthew Palmer # -# -# 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 (version 2 of the License) -# 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 -# require 'thread' -if Facter.kernel == "Linux" +if Facter.value(:kernel) == "Linux" processor_num = -1 processor_list = [] Thread::exclusive do @@ -50,3 +37,38 @@ end end end + +if Facter.value(:kernel) == "AIX" + processor_num = -1 + processor_list = {} + Thread::exclusive do + procs = Facter::Util::Resolution.exec('lsdev -Cc processor') + procs.each do |proc| + if proc =~ /^proc(\d+)/ + processor_num = $1.to_i + # Not retrieving the frequency since AIX 4.3.3 doesn't support the + # attribute and some people still use the OS. + proctype = Facter::Util::Resolution.exec('lsattr -El proc0 -a type') + if proctype =~ /^type\s+(\S+)\s+/ + processor_list["processor#{processor_num}"] = $1 + end + end + end + end + + Facter.add("ProcessorCount") do + confine :kernel => :aix + setcode do + processor_list.length.to_s + end + end + + processor_list.each do |proc, desc| + Facter.add(proc) do + confine :kernel => :aix + setcode do + desc + end + end + end +end diff -Nru facter-1.3.8/lib/facter/ps.rb facter-1.5.6/lib/facter/ps.rb --- facter-1.3.8/lib/facter/ps.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/ps.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,8 @@ +Facter.add(:ps) do + setcode do 'ps -ef' end +end + +Facter.add(:ps) do + confine :operatingsystem => %w{FreeBSD NetBSD OpenBSD Darwin} + setcode do 'ps auxwww' end +end diff -Nru facter-1.3.8/lib/facter/puppetversion.rb facter-1.5.6/lib/facter/puppetversion.rb --- facter-1.3.8/lib/facter/puppetversion.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/puppetversion.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,10 @@ +Facter.add(:puppetversion) do + setcode do + begin + require 'puppet' + Puppet::PUPPETVERSION.to_s + rescue LoadError + nil + end + end +end diff -Nru facter-1.3.8/lib/facter/rubysitedir.rb facter-1.5.6/lib/facter/rubysitedir.rb --- facter-1.3.8/lib/facter/rubysitedir.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/rubysitedir.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,8 @@ +Facter.add :rubysitedir do + setcode do + version = RUBY_VERSION.to_s.sub(/\.\d+$/, '') + $:.find do |dir| + dir =~ /#{File.join("site_ruby", version)}$/ + end + end +end diff -Nru facter-1.3.8/lib/facter/rubyversion.rb facter-1.5.6/lib/facter/rubyversion.rb --- facter-1.3.8/lib/facter/rubyversion.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/rubyversion.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,3 @@ +Facter.add(:rubyversion) do + setcode { RUBY_VERSION.to_s } +end diff -Nru facter-1.3.8/lib/facter/selinux.rb facter-1.5.6/lib/facter/selinux.rb --- facter-1.3.8/lib/facter/selinux.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/selinux.rb 2009-05-18 22:19:03.000000000 +0000 @@ -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 -Nru facter-1.3.8/lib/facter/ssh.rb facter-1.5.6/lib/facter/ssh.rb --- facter-1.3.8/lib/facter/ssh.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/ssh.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,33 @@ +## ssh.rb +## Facts related to SSH +## +## 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 (version 2 of the License) +## 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 +## + +["/etc/ssh","/usr/local/etc/ssh","/etc","/usr/local/etc"].each do |dir| + {"SSHDSAKey" => "ssh_host_dsa_key.pub", "SSHRSAKey" => "ssh_host_rsa_key.pub"}.each do |name,file| + Facter.add(name) do + setcode do + value = nil + filepath = File.join(dir,file) + if FileTest.file?(filepath) + begin + File.open(filepath) { |f| value = f.read.chomp.split(/\s+/)[1] } + rescue + value = nil + end + end + value + end # end of proc + end # end of add + end # end of hash each +end # end of dir each diff -Nru facter-1.3.8/lib/facter/timezone.rb facter-1.5.6/lib/facter/timezone.rb --- facter-1.3.8/lib/facter/timezone.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/timezone.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,5 @@ +Facter.add("timezone") do + setcode do + Time.new.zone + end +end diff -Nru facter-1.3.8/lib/facter/uniqueid.rb facter-1.5.6/lib/facter/uniqueid.rb --- facter-1.3.8/lib/facter/uniqueid.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/uniqueid.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,4 @@ +Facter.add(:uniqueid) do + setcode 'hostid', '/bin/sh' + confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX OEL OVS} +end diff -Nru facter-1.3.8/lib/facter/uptime.rb facter-1.5.6/lib/facter/uptime.rb --- facter-1.3.8/lib/facter/uptime.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/uptime.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,20 @@ +require 'facter/util/uptime' + +Facter.add(:uptime) do + confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX} + setcode do + Facter::Util::Uptime.get_uptime_simple + end +end + +if FileTest.exists?("/proc/uptime") + uptime = Facter::Util::Uptime.get_uptime + + %w{days hours seconds}.each do |label| + Facter.add("uptime_" + label) do + setcode do + Facter::Util::Uptime.get_uptime_period(uptime, label) + end + end + end +end diff -Nru facter-1.3.8/lib/facter/util/collection.rb facter-1.5.6/lib/facter/util/collection.rb --- facter-1.3.8/lib/facter/util/collection.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/util/collection.rb 2011-12-30 09:01:07.000000000 +0000 @@ -0,0 +1,130 @@ +require 'facter' +require 'facter/util/fact' +require 'facter/util/loader' + +# Manage which facts exist and how we access them. Largely just a wrapper +# around a hash of facts. +class Facter::Util::Collection + # Return a fact object by name. If you use this, you still have to call + # 'value' on it to retrieve the actual value. + def [](name) + value(name) + end + + # Add a resolution mechanism for a named fact. This does not distinguish + # between adding a new fact and adding a new way to resolve a fact. + def add(name, options = {}, &block) + name = canonize(name) + + unless fact = @facts[name] + fact = Facter::Util::Fact.new(name) + + @facts[name] = fact + end + + # Set any fact-appropriate options. + options.each do |opt, value| + method = opt.to_s + "=" + if fact.respond_to?(method) + fact.send(method, value) + options.delete(opt) + end + end + + if block + resolve = fact.add(&block) + # Set any resolve-appropriate options + options.each do |opt, value| + method = opt.to_s + "=" + if resolve.respond_to?(method) + resolve.send(method, value) + options.delete(opt) + end + end + end + + unless options.empty? + raise ArgumentError, "Invalid facter option(s) %s" % options.keys.collect { |k| k.to_s }.join(",") + end + + return fact + end + + include Enumerable + + # Iterate across all of the facts. + def each + @facts.each do |name, fact| + value = fact.value + unless value.nil? + yield name.to_s, value + end + end + end + + # Return a fact by name. + def fact(name) + name = canonize(name) + + # Try to load the fact if necessary + loader.load(name) unless @facts[name] + + # Try HARDER + loader.load_all unless @facts[name] + + @facts[name] + end + + # Flush all cached values. + def flush + @facts.each { |name, fact| fact.flush } + end + + def initialize + @facts = Hash.new + end + + # Return a list of all of the facts. + def list + return @facts.keys + end + + # Load all known facts. + def load_all + loader.load_all + end + + # The thing that loads facts if we don't have them. + def loader + unless defined?(@loader) + @loader = Facter::Util::Loader.new + end + @loader + end + + # Return a hash of all of our facts. + def to_hash + @facts.inject({}) do |h, ary| + value = ary[1].value + if ! value.nil? + # For backwards compatibility, convert the fact name to a string. + h[ary[0].to_s] = value + end + h + end + end + + def value(name) + if fact = fact(name) + fact.value + end + end + + private + + # Provide a consistent means of getting the exact same fact name + # every time. + def canonize(name) + name.to_s.downcase.to_sym + end +end diff -Nru facter-1.3.8/lib/facter/util/confine.rb facter-1.5.6/lib/facter/util/confine.rb --- facter-1.3.8/lib/facter/util/confine.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/util/confine.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,41 @@ +# 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 + @values = values + end + + def to_s + return "'%s' '%s'" % [@fact, @values.join(",")] + end + + # Evaluate the fact, returning true or false. + def true? + unless fact = Facter[@fact] + Facter.debug "No fact for %s" % @fact + return false + end + value = convert(fact.value) + + return false if value.nil? + + @values.each do |v| + v = convert(v) + next unless v.class == value.class + return true if value == v + end + return false + end +end diff -Nru facter-1.3.8/lib/facter/util/fact.rb facter-1.5.6/lib/facter/util/fact.rb --- facter-1.3.8/lib/facter/util/fact.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/util/fact.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,122 @@ +require 'facter' +require 'facter/util/resolution' + +class Facter::Util::Fact + TIMEOUT = 5 + + attr_accessor :name, :ldapname + + # Create a new fact, with no resolution mechanisms. + def initialize(name, options = {}) + @name = name.to_s.downcase.intern + + # LAK:NOTE: This is slow for many options, but generally we won't have any and at + # worst we'll have one. If we add more, this should be made more efficient. + options.each do |name, value| + case name + when :ldapname; self.ldapname = value + else + raise ArgumentError, "Invalid fact option '%s'" % name + end + end + + @ldapname ||= @name.to_s + + @resolves = [] + @searching = false + + @value = nil + end + + # Add a new resolution mechanism. This requires a block, which will then + # be evaluated in the context of the new mechanism. + def add(&block) + raise ArgumentError, "You must pass a block to Fact.add" unless block_given? + + resolve = Facter::Util::Resolution.new(@name) + + resolve.instance_eval(&block) + + @resolves << resolve + + # Immediately sort the resolutions, so that we always have + # a sorted list for looking up values. + # We always want to look them up in the order of number of + # confines, so the most restricted resolution always wins. + @resolves.sort! { |a, b| b.length <=> a.length } + + return resolve + end + + # Flush any cached values. + def flush + @value = nil + @suitable = nil + end + + # Return the value for a given fact. Searches through all of the mechanisms + # and returns either the first value or nil. + def value + return @value if @value + + if @resolves.length == 0 + Facter.debug "No resolves for %s" % @name + return nil + end + + searching do + @value = nil + + foundsuits = false + @value = @resolves.inject(nil) { |result, resolve| + next unless resolve.suitable? + foundsuits = true + + tmp = resolve.value + + break tmp unless tmp.nil? or tmp == "" + } + + unless foundsuits + Facter.debug "Found no suitable resolves of %s for %s" % [@resolves.length, @name] + end + end + + if @value.nil? + # nothing + Facter.debug("value for %s is still nil" % @name) + return nil + else + return @value + end + end + + private + + # Are we in the midst of a search? + def searching? + @searching + end + + # Lock our searching process, so we never ge stuck in recursion. + def searching + if searching? + Facter.debug "Caught recursion on %s" % @name + + # return a cached value if we've got it + if @value + return @value + else + return nil + end + end + + # If we've gotten this far, we're not already searching, so go ahead and do so. + @searching = true + begin + yield + ensure + @searching = false + end + end +end diff -Nru facter-1.3.8/lib/facter/util/ip.rb facter-1.5.6/lib/facter/util/ip.rb --- facter-1.3.8/lib/facter/util/ip.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/util/ip.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,152 @@ +# A base module for collecting IP-related +# information from all kinds of platforms. +module Facter::Util::IP + # A map of all the different regexes that work for + # 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]+)/ + }, + :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 => { + :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})/ + } + } + + # Convert an interface name into purely alpha characters. + def self.alphafy(interface) + interface.gsub(/[:.]/, '_') + end + + def self.convert_from_hex?(kernel) + kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin] + kernels_to_convert.include?(kernel) + end + + def self.supported_platforms + REGEX_MAP.inject([]) do |result, tmp| + key, map = tmp + if map[:aliases] + result += map[:aliases] + else + result << key + end + result + end + end + + def self.get_interfaces + return [] unless output = Facter::Util::IP.get_all_interface_output() + + # 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 + case Facter.value(:kernel) + when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin' + output = %x{/sbin/ifconfig -a} + when 'SunOS' + output = %x{/usr/sbin/ifconfig -a} + end + output + end + + def self.get_single_interface_output(interface) + output = "" + case Facter.value(:kernel) + when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin' + output = %x{/sbin/ifconfig #{interface}} + when 'SunOS' + output = %x{/usr/sbin/ifconfig #{interface}} + end + output + end + + def self.get_bonding_master(interface) + if Facter.value(:kernel) != 'Linux' + return nil + end + # We need ip instead of ifconfig because it will show us + # the bonding master device. + if not FileTest.executable?("/sbin/ip") + return nil + end + regex = /SLAVE[,>].* (bond[0-9]+)/ + ethbond = regex.match(%x{/sbin/ip link show #{interface}}) + if ethbond + device = ethbond[1] + else + device = nil + end + device + end + + + def self.get_interface_value(interface, label) + tmp1 = [] + + kernel = Facter.value(:kernel).downcase.to_sym + + # If it's not directly in the map or aliased in the map, then we don't know how to deal with it. + unless map = REGEX_MAP[kernel] || REGEX_MAP.values.find { |tmp| tmp[:aliases] and tmp[:aliases].include?(kernel) } + return [] + end + + # Pull the correct regex out of the map. + regex = map[label.to_sym] + + # Linux changes the MAC address reported via ifconfig when an ethernet interface + # becomes a slave of a bonding device to the master MAC address. + # We have to dig a bit to get the original/real MAC address of the interface. + bonddev = get_bonding_master(interface) + if label == 'macaddress' and bonddev + bondinfo = IO.readlines("/proc/net/bonding/#{bonddev}") + hwaddrre = /^Slave Interface: #{interface}\n[^\n].+?\nPermanent HW addr: (([0-9a-fA-F]{2}:?)*)$/m + value = hwaddrre.match(bondinfo.to_s)[1].upcase + else + output_int = get_single_interface_output(interface) + + if interface != /^lo[0:]?\d?/ + output_int.each_line do |s| + if s =~ regex + value = $1 + if label == 'netmask' && convert_from_hex?(kernel) + value = value.scan(/../).collect do |byte| byte.to_i(16) end.join('.') + end + tmp1.push(value) + end + end + end + + if tmp1 + value = tmp1.shift + end + end + end + + def self.get_network_value(interface) + require 'ipaddr' + + ipaddress = get_interface_value(interface, "ipaddress") + netmask = get_interface_value(interface, "netmask") + + if ipaddress && netmask + ip = IPAddr.new(ipaddress, Socket::AF_INET) + subnet = IPAddr.new(netmask, Socket::AF_INET) + network = ip.mask(subnet.to_s).to_s + end + end +end diff -Nru facter-1.3.8/lib/facter/util/loader.rb facter-1.5.6/lib/facter/util/loader.rb --- facter-1.3.8/lib/facter/util/loader.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/util/loader.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,96 @@ +require 'facter' + +# Load facts on demand. +class Facter::Util::Loader + # Load all resolutions for a single fact. + def load(fact) + # Now load from the search path + shortname = fact.to_s.downcase + load_env(shortname) + + filename = shortname + ".rb" + search_path.each do |dir| + # Load individual files + file = File.join(dir, filename) + + load_file(file) if FileTest.exist?(file) + + # And load any directories matching the name + factdir = File.join(dir, shortname) + load_dir(factdir) if FileTest.directory?(factdir) + end + end + + # Load all facts from all directories. + def load_all + return if defined?(@loaded_all) + + load_env + + search_path.each do |dir| + next unless FileTest.directory?(dir) + + Dir.entries(dir).each do |file| + path = File.join(dir, file) + if File.directory?(path) + load_dir(path) + elsif file =~ /\.rb$/ + load_file(File.join(dir, file)) + end + end + end + + @loaded_all = true + end + + # The list of directories we're going to search through for facts. + def search_path + result = [] + result += $LOAD_PATH.collect { |d| File.join(d, "facter") } + if ENV.include?("FACTERLIB") + result += ENV["FACTERLIB"].split(":") + end + + # This allows others to register additional paths we should search. + result += Facter.search_path + + result + end + + private + + def load_dir(dir) + return if dir =~ /\/\.+$/ or dir =~ /\/util$/ or dir =~ /\/lib$/ + + Dir.entries(dir).find_all { |f| f =~ /\.rb$/ }.each do |file| + load_file(File.join(dir, file)) + end + end + + def load_file(file) + # We have to specify Kernel.load, because we have a load method. + Kernel.load(file) + end + + # Load facts from the environment. If no name is provided, + # all will be loaded. + def load_env(fact = nil) + # Load from the environment, if possible + ENV.each do |name, value| + # Skip anything that doesn't match our regex. + next unless name =~ /^facter_?(\w+)$/i + env_name = $1 + + # If a fact name was specified, skip anything that doesn't + # match it. + next if fact and env_name != fact + + Facter.add($1) do + setcode { value } + end + + # Short-cut, if we are only looking for one value. + break if fact + end + end +end diff -Nru facter-1.3.8/lib/facter/util/macosx.rb facter-1.5.6/lib/facter/util/macosx.rb --- facter-1.3.8/lib/facter/util/macosx.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/util/macosx.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,68 @@ +## macosx.rb +## Support methods for Apple OSX facts +## +## Copyright (C) 2007 Jeff McCune +## Author: Jeff McCune +## +## 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 (version 2 of the License) +## 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 +## + +module Facter::Util::Macosx + require 'thread' + require 'facter/util/plist' + require 'facter/util/resolution' + + # JJM I'd really like to dynamically generate these methods + # by looking at the _name key of the _items dict for each _dataType + + def self.profiler_xml(data_field) + Facter::Util::Resolution.exec("/usr/sbin/system_profiler -xml #{data_field}") + end + + def self.intern_xml(xml) + return nil unless xml + Plist::parse_xml(xml) + end + + # Return an xml result, modified as we need it. + def self.profiler_data(data_field) + begin + return nil unless parsed_xml = intern_xml(profiler_xml(data_field)) + return nil unless data = parsed_xml[0]['_items'][0] + data.delete '_name' + data + rescue + return nil + end + end + + def self.hardware_overview + profiler_data("SPHardwareDataType") + end + + def self.os_overview + profiler_data("SPSoftwareDataType") + end + + def self.sw_vers + ver = Hash.new + [ "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 -Nru facter-1.3.8/lib/facter/util/manufacturer.rb facter-1.5.6/lib/facter/util/manufacturer.rb --- facter-1.3.8/lib/facter/util/manufacturer.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/util/manufacturer.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,46 @@ +# mamufacturer.rb +# 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") + + 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 -Nru facter-1.3.8/lib/facter/util/memory.rb facter-1.5.6/lib/facter/util/memory.rb --- facter-1.3.8/lib/facter/util/memory.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/util/memory.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,54 @@ +## memory.rb +## Support module for memory related facts +## +## 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 (version 2 of the License) +## 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 +## + +module Facter::Memory + require 'thread' + + def self.meminfo_number(tag) + memsize = "" + Thread::exclusive do + size, scale = [0, ""] + File.readlines("/proc/meminfo").each do |l| + size, scale = [$1.to_f, $2] if l =~ /^#{tag}:\s+(\d+)\s+(\S+)/ + # MemoryFree == memfree + cached + buffers + # (assume scales are all the same as memfree) + if tag == "MemFree" && + l =~ /^(?:Buffers|Cached):\s+(\d+)\s+(?:\S+)/ + size += $1.to_f + end + end + memsize = scale_number(size, scale) + end + + memsize + end + + def self.scale_number(size, multiplier) + suffixes = ['', 'kB', 'MB', 'GB', 'TB'] + + s = suffixes.shift + while s != multiplier + s = suffixes.shift + end + + while size > 1024.0 + size /= 1024.0 + s = suffixes.shift + end + + return "%.2f %s" % [size, s] + end +end + diff -Nru facter-1.3.8/lib/facter/util/netmask.rb facter-1.5.6/lib/facter/util/netmask.rb --- facter-1.3.8/lib/facter/util/netmask.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/util/netmask.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,34 @@ +module Facter::NetMask + def self.get_netmask + netmask = nil; + ipregex = %r{(\d{1,3}\.){3}\d{1,3}} + + ops = nil + case Facter.value(:kernel) + when 'Linux' + ops = { + :ifconfig => '/sbin/ifconfig', + :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x, + :munge => nil, + } + when 'SunOS' + ops = { + :ifconfig => '/usr/sbin/ifconfig -a', + :regex => %r{\s+ inet\s+? #{Facter.ipaddress} \+? mask (\w{8})}x, + :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') } + } + end + + %x{#{ops[:ifconfig]}}.split(/\n/).collect do |line| + matches = line.match(ops[:regex]) + if !matches.nil? + if ops[:munge].nil? + netmask = matches[1] + else + netmask = ops[:munge].call(matches[1]) + end + end + end + netmask + end +end diff -Nru facter-1.3.8/lib/facter/util/plist/generator.rb facter-1.5.6/lib/facter/util/plist/generator.rb --- facter-1.3.8/lib/facter/util/plist/generator.rb 2007-09-24 06:57:51.000000000 +0000 +++ facter-1.5.6/lib/facter/util/plist/generator.rb 2009-05-18 22:19:03.000000000 +0000 @@ -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: - # - # * Plist::Emit.dump(obj) - # * obj.to_plist - # * This requires that you mixin the Plist::Emit 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 and containers (respectively). - # * +IO+ (and its descendants) and +StringIO+ objects are read from and their contents placed in a element. - # * User classes may implement +to_plist_node+ to dictate how they should be serialized; otherwise the object will be passed to Marshal.dump and the result placed in a 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 Plist::Emit.dump with +self+. - def to_plist(envelope = true) - return Plist::Emit.dump(self, envelope) - end - - # Helper method for injecting into classes. Calls Plist::Emit.save_plist 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. + # * Plist::Emit.dump(obj) + # * obj.to_plist + # * This requires that you mixin the Plist::Emit module, which is already done for +Array+ and +Hash+. # - # +IO+ and +StringIO+ objects are encoded and placed in elements; other objects are Marshal.dump'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 and containers (respectively). + # * +IO+ (and its descendants) and +StringIO+ objects are read from and their contents placed in a element. + # * User classes may implement +to_plist_node+ to dictate how they should be serialized; otherwise the object will be passed to Marshal.dump and the result placed in a 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 Plist::Emit.dump 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 Plist::Emit.save_plist 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 elements; other objects are Marshal.dump'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 << "\n" - else - output << tag('array') { - element.collect {|e| plist_node(e)} - } - end - when Hash - if element.empty? - output << "\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 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 + # 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 - def self.comment(content) - return "\n" - 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 << "\n" + else + output << tag('array') { + element.collect {|e| plist_node(e)} + } + end + when Hash + if element.empty? + output << "\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 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 - def self.tag(type, contents = '', &block) - out = nil + return output + end - if block_given? - out = IndentedString.new - out << "<#{type}>" - out.raise_indent - - out << block.call - - out.lower_indent - out << "" - else - out = "<#{type}>#{contents.to_s}\n" - end + def self.comment(content) + return "\n" + end - return out.to_s - end + def self.tag(type, contents = '', &block) + out = nil - def self.wrap(contents) - output = '' + if block_given? + out = IndentedString.new + out << "<#{type}>" + out.raise_indent + + out << block.call + + out.lower_indent + out << "" + else + out = "<#{type}>#{contents.to_s}\n" + end - output << '' + "\n" - output << '' + "\n" - output << '' + "\n" + return out.to_s + end - output << contents + def self.wrap(contents) + output = '' - output << '' + "\n" + output << '' + "\n" + output << '' + "\n" + output << '' + "\n" - return output - end + output << contents - 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 + output << '' + "\n" - # it already has a newline, don't add another - @contents << "\n" unless val =~ /\n$/ + return output + end + + 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$/ + 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 -Nru facter-1.3.8/lib/facter/util/plist/parser.rb facter-1.5.6/lib/facter/util/plist/parser.rb --- facter-1.3.8/lib/facter/util/plist/parser.rb 2007-09-24 06:57:51.000000000 +0000 +++ facter-1.5.6/lib/facter/util/plist/parser.rb 2009-05-18 22:19:03.000000000 +0000 @@ -21,207 +21,206 @@ # 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@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 - end - + 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 + end - def tag_start(name, attributes) - @open.push PTag::mappings[name].new - end - def text( contents ) - @open.last.text = contents if @open.last - end + def tag_start(name, attributes) + @open.push PTag::mappings[name].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 + def text( contents ) + @open.last.text = contents if @open.last + end - class StreamParser - def initialize( filename_or_xml, listener ) - @filename_or_xml = filename_or_xml - @listener = listener + def tag_end(name) + last = @open.pop + if @open.empty? + @result = last.to_ruby + else + @open.last.children.push last + end + end end - TEXT = /([^<]+)/ - XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/um - DOCTYPE_PATTERN = /\s*)/um - COMMENT_START = /\A/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 + class StreamParser + def initialize( filename_or_xml, listener ) + @filename_or_xml = filename_or_xml + @listener = listener 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" + TEXT = /([^<]+)/ + XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/um + DOCTYPE_PATTERN = /\s*)/um + COMMENT_START = /\A/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 end - end - class PTag - @@mappings = { } - def PTag::mappings - @@mappings - end + class PTag + @@mappings = { } + def PTag::mappings + @@mappings + end - def PTag::inherited( sub_class ) - key = sub_class.to_s.downcase - key.gsub!(/^plist::/, '' ) - key.gsub!(/^p/, '') unless key == "plist" + 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 + @@mappings[key] = sub_class + end - attr_accessor :text, :children - def initialize - @children = Array.new - 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}" + 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 + dict end - end - - dict 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 -Nru facter-1.3.8/lib/facter/util/plist.rb facter-1.5.6/lib/facter/util/plist.rb --- facter-1.3.8/lib/facter/util/plist.rb 2007-09-24 06:57:51.000000000 +0000 +++ facter-1.5.6/lib/facter/util/plist.rb 2009-05-18 22:19:03.000000000 +0000 @@ -18,7 +18,7 @@ require 'facter/util/plist/parser' module Plist - VERSION = '3.0.0' + VERSION = '3.0.0' end # $Id: plist.rb 1781 2006-10-16 01:01:35Z luke $ diff -Nru facter-1.3.8/lib/facter/util/resolution.rb facter-1.5.6/lib/facter/util/resolution.rb --- facter-1.3.8/lib/facter/util/resolution.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/util/resolution.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,138 @@ +# An actual fact resolution mechanism. These are largely just chunks of +# code, with optional confinements restricting the mechanisms to only working on +# specific systems. Note that the confinements are always ANDed, so any +# confinements specified must all be true for the resolution to be +# suitable. +require 'facter/util/confine' + +require 'timeout' +require 'rbconfig' + +class Facter::Util::Resolution + attr_accessor :interpreter, :code, :name, :timeout + + def self.have_which + if ! defined?(@have_which) or @have_which.nil? + if Config::CONFIG['host_os'] =~ /mswin/ + @have_which = false + else + %x{which which >/dev/null 2>&1} + @have_which = ($? == 0) + end + end + @have_which + end + + # Execute a chunk of code. + def self.exec(code, interpreter = "/bin/sh") + raise ArgumentError, "non-sh interpreters are not currently supported" unless interpreter == "/bin/sh" + binary = code.split(/\s+/).shift + + if have_which + path = nil + if binary !~ /^\// + path = %x{which #{binary} 2>/dev/null}.chomp + # we don't have the binary necessary + return nil if path == "" or path.match(/Command not found\./) + else + path = binary + end + + return nil unless FileTest.exists?(path) + end + + out = nil + begin + out = %x{#{code}}.chomp + rescue => detail + $stderr.puts detail + return nil + end + if out == "" + return nil + else + return out + end + end + + # Add a new confine to the resolution mechanism. + def confine(confines) + confines.each do |fact, values| + @confines.push Facter::Util::Confine.new(fact, *values) + end + end + + # Create a new resolution mechanism. + def initialize(name) + @name = name + @confines = [] + @value = nil + @timeout = 0 + end + + # Return the number of confines. + def length + @confines.length + end + + # We need this as a getter for 'timeout', because some versions + # of ruby seem to already have a 'timeout' method and we can't + # seem to override the instance methods, somehow. + def limit + @timeout + end + + # Set our code for returning a value. + def setcode(string = nil, interp = nil, &block) + if string + @code = string + @interpreter = interp || "/bin/sh" + else + unless block_given? + raise ArgumentError, "You must pass either code or a block" + end + @code = block + end + end + + # Is this resolution mechanism suitable on the system in question? + def suitable? + unless defined? @suitable + @suitable = ! @confines.detect { |confine| ! confine.true? } + end + + return @suitable + end + + def to_s + return self.value() + end + + # How we get a value for our resolution mechanism. + def value + result = nil + begin + Timeout.timeout(limit) do + if @code.is_a?(Proc) + result = @code.call() + else + result = Facter::Util::Resolution.exec(@code,@interpreter) + end + end + rescue Timeout::Error => detail + warn "Timed out seeking value for %s" % self.name + + # This call avoids zombies -- basically, create a thread that will + # dezombify all of the child processes that we're ignoring because + # of the timeout. + Thread.new { Process.waitall } + return nil + rescue => details + warn "Could not retrieve %s: %s" % [self.name, details] + return nil + end + + return nil if result == "" + return result + end +end diff -Nru facter-1.3.8/lib/facter/util/uptime.rb facter-1.5.6/lib/facter/util/uptime.rb --- facter-1.3.8/lib/facter/util/uptime.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/util/uptime.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,32 @@ +# 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 + end + + def self.get_uptime + 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 + when 'hours' + value = seconds / 3600 + when 'seconds' + seconds + end + end +end diff -Nru facter-1.3.8/lib/facter/util/values.rb facter-1.5.6/lib/facter/util/values.rb --- facter-1.3.8/lib/facter/util/values.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/util/values.rb 2009-05-18 22:19:03.000000000 +0000 @@ -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 -Nru facter-1.3.8/lib/facter/virtual.rb facter-1.5.6/lib/facter/virtual.rb --- facter-1.3.8/lib/facter/virtual.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/lib/facter/virtual.rb 2011-12-30 09:01:07.000000000 +0000 @@ -0,0 +1,102 @@ +Facter.add("virtual") do + confine :kernel => %w{Linux FreeBSD OpenBSD SunOS} + + result = "physical" + + setcode do + 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/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" + end + end + + if FileTest.exists?("/proc/cpuinfo") + txt = File.read("/proc/cpuinfo") + if txt =~ /QEMU Virtual CPU/ + result = "kvm" + end + end + + if result == "physical" + 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 + output = Facter::Util::Resolution.exec('dmidecode') + if not output.nil? + output.each_line do |pd| + result = "vmware" if pd =~ /VMware|Parallels/ + end + else + output = Facter::Util::Resolution.exec('prtdiag') + if not output.nil? + output.each_line do |pd| + result = "vmware" if pd =~ /VMware|Parallels/ + end + end + end + end + end + + # VMware server 1.0.3 rpm places vmware-vmx in this place, other versions or platforms may not. + if FileTest.exists?("/usr/lib/vmware/bin/vmware-vmx") + result = "vmware_server" + end + + result + end +end + +Facter.add("is_virtual") do + confine :kernel => %w{Linux FreeBSD OpenBSD SunOS} + + setcode do + case Facter.value(:virtual) + when "xenu", "openvzve", "vmware", "kvm" + true + else + false + end + end +end diff -Nru facter-1.3.8/lib/facter.rb facter-1.5.6/lib/facter.rb --- facter-1.3.8/lib/facter.rb 2007-09-24 07:01:37.000000000 +0000 +++ facter-1.5.6/lib/facter.rb 2009-06-04 22:08:10.000000000 +0000 @@ -1,56 +1,62 @@ #-- # Copyright 2006 Luke Kanies -# +# # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. -# +# # This library 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 # Lesser General Public License for more details. -# +# # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# +# #-- -class Facter +module Facter + # This is just so the other classes have the constant. + module Util; end + + require 'facter/util/fact' + require 'facter/util/collection' + include Comparable include Enumerable - FACTERVERSION = '1.3.8' - # = 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 Facter as a hash: # == Example # require 'facter' # puts Facter['operatingsystem'] # + # Set LANG to force i18n to C + # + ENV['LANG'] = 'C' - @@facts = Hash.new { |hash, key| - key = key.to_s.downcase.intern - if hash.include?(key) - hash[key] - else - nil - end - } GREEN = "" RESET = "" @@debug = 0 - attr_accessor :name, :searching, :ldapname + # module methods - # module methods + def self.collection + unless defined?(@collection) and @collection + @collection = Facter::Util::Collection.new + end + @collection + end # Return the version of the library. def self.version @@ -70,41 +76,41 @@ # Return a fact object by name. If you use this, you still have to call # 'value' on it to retrieve the actual value. def self.[](name) - @@facts[name] + collection.fact(name) end - # Add a resolution mechanism for a named fact. This does not distinguish - # between adding a new fact and adding a new way to resolve a fact. - def self.add(name, &block) - fact = nil - - unless fact = @@facts[name] - fact = Facter.new(name) + class << self + [:fact, :flush, :list, :value].each do |method| + define_method(method) do |*args| + collection.send(method, *args) + end end - unless block - return fact + [:list, :to_hash].each do |method| + define_method(method) do |*args| + collection.load_all + collection.send(method, *args) + end end + end - fact.add(&block) - return fact + # Add a resolution mechanism for a named fact. This does not distinguish + # between adding a new fact and adding a new way to resolve a fact. + def self.add(name, options = {}, &block) + collection.add(name, options, &block) end - class << self - include Enumerable - # Iterate across all of the facts. - def each - @@facts.each { |name,fact| - if fact.suitable? - value = fact.value - unless value.nil? - yield name.to_s, fact.value - end - end - } + def self.each + # Make sure all facts are loaded. + collection.load_all + + collection.each do |*args| + yield(*args) end + end + class << self # Allow users to call fact names directly on the Facter class, # either retrieving the value or comparing it to an existing value. def method_missing(name, *args) @@ -114,7 +120,7 @@ name = name.to_s.sub(/\?$/,'') end - if fact = @@facts[name] + if fact = @collection.fact(name) if question value = fact.value.downcase args.each do |arg| @@ -130,7 +136,7 @@ end else # Else, fail like a normal missing method. - return super + raise NoMethodError, "Could not find fact '%s'" % name end end end @@ -141,19 +147,19 @@ 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 - when Fixnum: + when TrueClass; @@debug = 1 + when FalseClass; @@debug = 0 + when Fixnum if bit > 0 @@debug = 1 else @@debug = 0 end - when String: + when String; if bit.downcase == 'off' @@debug = 0 else @@ -162,982 +168,30 @@ else @@debug = 0 end - else - @@debug = 0 - end - end - - # Flush all cached values. - def self.flush - @@facts.each { |name, fact| fact.flush } - end - - # Return a list of all of the facts. - def self.list - return @@facts.keys - end - - # Remove them all. - def self.reset - @@facts.clear - end - - # Return a hash of all of our facts. - def self.to_hash(*tags) - @@facts.inject({}) do |h, ary| - if ary[1].suitable? and (tags.empty? or ary[1].tagged?(*tags)) - value = ary[1].value - if value - # For backwards compatibility, convert the fact name to a string. - h[ary[0].to_s] = value - end - end - h - end - end - - def self.value(name) - if fact = @@facts[name] - fact.value - else - nil - end - end - - # Compare one value to another. - def <=>(other) - return self.value <=> other - end - - # Are we the same? Used for case statements. - def ===(value) - self.value == value - end - - # Create a new fact, with no resolution mechanisms. - def initialize(name) - @name = name.to_s.downcase.intern - if @@facts.include?(@name) - raise ArgumentError, "A fact named %s already exists" % @name else - @@facts[@name] = self - end - - @resolves = [] - @tags = [] - @searching = false - - @value = nil - - @ldapname = name.to_s - end - - # Add a new resolution mechanism. This requires a block, which will then - # be evaluated in the context of the new mechanism. - def add(&block) - unless block_given? - raise ArgumentError, "You must pass a block to Fact.add" - end - - resolve = Resolution.new(@name) - - resolve.fact = self - - resolve.instance_eval(&block) - - # skip resolves that will never be suitable for us - unless resolve.suitable? - return - end - - # insert resolves in order of number of confinements - inserted = false - @resolves.each_with_index { |r,index| - if resolve.length > r.length - @resolves.insert(index,resolve) - inserted = true - break - end - } - - unless inserted - @resolves.push resolve - end - end - - # Return a count of resolution mechanisms available. - def count - return @resolves.length - end - - # Iterate across all of the fact resolution mechanisms and yield each in - # turn. These are inserted in order of most confinements. - def each - @resolves.each { |r| yield r } - end - - # Flush any cached values. - def flush - @value = nil - @suitable = nil - end - - # Is this fact suitable for finding answers on this host? This is used - # to throw away any initially unsuitable mechanisms. - def suitable? - if @resolves.length == 0 - return false + @@debug = 0 end - - unless defined? @suitable or (defined? @suitable and @suitable.nil?) - @suitable = false - @resolves.each { |resolve| - if resolve.suitable? - @suitable = true - break - end - } - end - - return @suitable end - # Add one ore more tags - def tag(*tags) - tags.each do |t| - t = t.to_s.downcase.intern - @tags << t unless @tags.include?(t) - end - end - - # Is our fact tagged with all of the specified tags? - def tagged?(*tags) - tags.each do |t| - unless @tags.include? t.to_s.downcase.intern - return false - end - end - - return true - end - - def tags - @tags.dup - end - - # Return the value for a given fact. Searches through all of the mechanisms - # and returns either the first value or nil. - def value - unless @value - # make sure we don't get stuck in recursive dependency loops - if @searching - Facter.debug "Caught recursion on %s" % @name - - # return a cached value if we've got it - if @value - return @value - else - return nil - end - end - @value = nil - foundsuits = false - - if @resolves.length == 0 - Facter.debug "No resolves for %s" % @name - return nil - end - - @searching = true - @resolves.each { |resolve| - #Facter.debug "Searching resolves for %s" % @name - if resolve.suitable? - @value = resolve.value - foundsuits = true - end - unless @value.nil? or @value == "" - break - end - } - @searching = false - - unless foundsuits - Facter.debug "Found no suitable resolves of %s for %s" % - [@resolves.length,@name] - end - end - - if @value.nil? - # nothing - Facter.debug("value for %s is still nil" % @name) - return nil - else - return @value - end + # Remove them all. + def self.reset + @collection = nil end - # An actual fact resolution mechanism. These are largely just chunks of - # code, with optional confinements restricting the mechanisms to only working on - # specific systems. Note that the confinements are always ANDed, so any - # confinements specified must all be true for the resolution to be - # suitable. - class Resolution - attr_accessor :interpreter, :code, :name, :fact - - def Resolution.have_which - if @have_which.nil? - %x{which which 2>/dev/null} - @have_which = ($? == 0) - end - @have_which - end - - # Execute a chunk of code. - def Resolution.exec(code, interpreter = "/bin/sh") - if interpreter == "/bin/sh" - binary = code.split(/\s+/).shift - - if have_which - path = nil - if binary !~ /^\// - path = %x{which #{binary} 2>/dev/null}.chomp - if path == "" - # we don't have the binary necessary - return nil - end - else - path = binary - end - - unless FileTest.exists?(path) - # our binary does not exist - return nil - end - end - - out = nil - begin - out = %x{#{code}}.chomp - rescue => detail - $stderr.puts detail - return nil - end - if out == "" - return nil - else - return out - end - else - raise ArgumentError, - "non-sh interpreters are not currently supported" - end - end - - # Add a new confine to the resolution mechanism. - def confine(*args) - if args[0].is_a? Hash - args[0].each do |fact, values| - @confines.push Confine.new(fact,*values) - end - else - fact = args.shift - @confines.push Confine.new(fact,*args) - end - end - - # Create a new resolution mechanism. - def initialize(name) - @name = name - @confines = [] - @value = nil - end - - # Return the number of confines. - def length - @confines.length - end - - # Set our code for returning a value. - def setcode(string = nil, interp = nil, &block) - if string - @code = string - @interpreter = interp || "/bin/sh" - else - unless block_given? - raise ArgumentError, "You must pass either code or a block" - end - @code = block - end - end - - # Set the name by which this parameter is known in LDAP. The default - # is just the fact name. - def setldapname(name) - @fact.ldapname = name.to_s - end - - # Is this resolution mechanism suitable on the system in question? - def suitable? - unless defined? @suitable - @suitable = true - if @confines.length == 0 - return true - end - @confines.each { |confine| - unless confine.true? - @suitable = false - end - } - end - - return @suitable - end - - # Set tags on our parent fact. - def tag(*values) - @fact.tag(*values) - end - - def to_s - return self.value() - end - - # How we get a value for our resolution mechanism. - def value - value = nil - - if @code.is_a?(Proc) - value = @code.call() - else - unless defined? @interpreter - @interpreter = "/bin/sh" - end - if @code.nil? - $stderr.puts "Code for %s is nil" % @name - else - value = Resolution.exec(@code,@interpreter) - end - end - - if value == "" - value = nil - end - - return value - end - + # Load all of the default facts, and then everything from disk. + def self.loadfacts + collection.load_all end - # A restricting tag for fact resolution mechanisms. The tag must be true - # for the resolution mechanism to be suitable. - class Confine - attr_accessor :fact, :op, :value - - # Add the tag. Requires the fact name, an operator, and the value - # we're comparing to. - def initialize(fact, *values) - 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 - end - - def to_s - return "'%s' '%s'" % [@fact, @values.join(",")] - end - - # Evaluate the fact, returning true or false. - def true? - fact = nil - unless fact = Facter[@fact] - Facter.debug "No fact for %s" % @fact - return false - end - value = fact.value - - if value.nil? - return false - end - - retval = @values.find { |v| - if value.downcase == v.downcase - break true - end - } - - if retval - retval = true - else - retval = false - end + @search_path = [] - return retval || false - end + # Register a directory to search through. + def self.search(*dirs) + @search_path += dirs end - # Load all of the default facts - def self.loadfacts - Facter.add(:facterversion) do - setcode { FACTERVERSION.to_s } - end - - Facter.add(:rubyversion) do - setcode { RUBY_VERSION.to_s } - end - - Facter.add(:puppetversion) do - setcode { - begin - require 'puppet' - Puppet::PUPPETVERSION.to_s - rescue LoadError - nil - end - } - end - - Facter.add :rubysitedir do - setcode do - version = RUBY_VERSION.to_s.sub(/\.\d+$/, '') - $:.find do |dir| - dir =~ /#{File.join("site_ruby", version)}$/ - end - end - end - - Facter.add(:kernel) do - setcode 'uname -s' - end - - Facter.add(:kernelrelease) do - setcode 'uname -r' - end - - { "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 - setcode do - unless defined?(@@lsbdata) and defined?(@@lsbtime) and (Time.now.to_i - @@lsbtime.to_i < 5) - type = nil - @@lsbtime = Time.now - @@lsbdata = Resolution.exec('lsb_release -a 2>/dev/null') - end - if pattern.match(@@lsbdata) - $1 - else - nil - end - end - end - end - - Facter.add(:operatingsystem) do - confine :kernel => :sunos - setcode do "Solaris" end - end - - Facter.add(:operatingsystem) do - confine :kernel => :linux - setcode do - if FileTest.exists?("/etc/debian_version") - "Debian" - elsif FileTest.exists?("/etc/gentoo-release") - "Gentoo" - elsif FileTest.exists?("/etc/fedora-release") - "Fedora" - elsif FileTest.exists?("/etc/mandriva-release") - "Mandriva" - elsif FileTest.exists?("/etc/redhat-release") - txt = File.read("/etc/redhat-release") - if txt =~ /centos/i - "CentOS" - else - "RedHat" - end - elsif FileTest.exists?("/etc/SuSE-release") - "SuSE" - end - end - end - - Facter.add(:operatingsystem) do - # Default to just returning the kernel as the operating system - setcode do Facter[:kernel].value end - end - - Facter.add(:operatingsystemrelease) do - confine :operatingsystem => :fedora - setcode do - File::open("/etc/fedora-release", "r") do |f| - line = f.readline.chomp - if line =~ /\(Rawhide\)$/ - "Rawhide" - elsif line =~ /release (\d+)/ - $1 - end - end - end - end - - Facter.add(:operatingsystemrelease) do - confine :operatingsystem => :redhat - setcode do - File::open("/etc/redhat-release", "r") do |f| - line = f.readline.chomp - if line =~ /\(Rawhide\)$/ - "Rawhide" - elsif line =~ /release (\d+)/ - $1 - end - end - end - end - - Facter.add(:operatingsystemrelease) do - setcode do Facter[:kernelrelease].value end - end - - Facter.add(:hardwaremodel) do - setcode 'uname -m' - end - - Facter.add(:architecture) do - confine :kernel => :linux - setcode do - model = Facter.hardwaremodel - case model - # most linuxen use "x86_64" - when 'x86_64': - Facter.operatingsystem == "Debian" ? "amd64" : model; - when /(i[3456]86|pentium)/: "i386" - else - model - end - end - end - - Facter.add(:Cfkey) do - setcode do - value = nil - ["/usr/local/etc/cfkey.pub", - "/etc/cfkey.pub", - "/var/cfng/keys/localhost.pub", - "/var/cfengine/ppkeys/localhost.pub", - "/var/lib/cfengine/ppkeys/localhost.pub", - "/var/lib/cfengine2/ppkeys/localhost.pub" - ].each { |file| - if FileTest.file?(file) - File.open(file) { |openfile| - value = openfile.readlines.reject { |line| - line =~ /PUBLIC KEY/ - }.collect { |line| - line.chomp - }.join("") - } - end - if value - break - end - } - - value - end - end - - Facter.add(:domain) do - setcode do - # First force the hostname to be checked - Facter.hostname - - # Now check to see if it set the domain - if defined? $domain and ! $domain.nil? - $domain - else - nil - end - end - end - # Look for the DNS domain name command first. - Facter.add(:domain) do - setcode do - domain = Resolution.exec('dnsdomainname') or nil - # make sure it's a real domain - if domain and domain =~ /.+\..+/ - domain - else - nil - end - end - end - Facter.add(:domain) do - setcode do - domain = Resolution.exec('domainname') or nil - # make sure it's a real domain - if domain and domain =~ /.+\..+/ - domain - else - nil - end - end - end - Facter.add(:domain) do - setcode do - value = nil - if FileTest.exists?("/etc/resolv.conf") - File.open("/etc/resolv.conf") { |file| - # is the domain set? - file.each { |line| - if line =~ /domain\s+(\S+)/ - value = $1 - break - end - } - } - ! value and File.open("/etc/resolv.conf") { |file| - # is the search path set? - file.each { |line| - if line =~ /search\s+(\S+)/ - value = $1 - break - end - } - } - value - else - nil - end - end - end - Facter.add(:hostname) do - setldapname "cn" - setcode do - hostname = nil - name = Resolution.exec('hostname') or nil - if name - if name =~ /^([\w-]+)\.(.+)$/ - hostname = $1 - # the Domain class uses this - $domain = $2 - else - hostname = name - end - hostname - else - nil - end - end - end - - Facter.add(:fqdn) do - setcode do - host = Facter.value(:hostname) - domain = Facter.value(:domain) - if host and domain - [host, domain].join(".") - else - nil - end - end - end - - Facter.add(:ipaddress) do - setldapname "iphostnumber" - setcode do - require 'resolv' - - begin - if hostname = Facter.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) do - setcode do - if hostname = Facter.hostname - # we need Hostname to exist for this to work - host = nil - if host = Resolution.exec("host #{hostname}") - host = 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 - - ["/etc/ssh","/usr/local/etc/ssh","/etc","/usr/local/etc"].each { |dir| - {"SSHDSAKey" => "ssh_host_dsa_key.pub", - "SSHRSAKey" => "ssh_host_rsa_key.pub"}.each { |name,file| - Facter.add(name) do - setcode do - value = nil - filepath = File.join(dir,file) - if FileTest.file?(filepath) - begin - File.open(filepath) { |f| - value = f.read.chomp.split(/\s+/)[1] - } - rescue - value = nil - end - end - value - end # end of proc - end # end of add - } # end of hash each - } # end of dir each - - Facter.add(:uniqueid) do - setcode 'hostid', '/bin/sh' - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo} - end - - Facter.add(:hardwareisa) do - setcode 'uname -p', '/bin/sh' - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo FreeBSD OpenBSD NetBSD} - end - - Facter.add(:macaddress) do - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo} - setcode do - ether = [] - output = %x{/sbin/ifconfig -a} - output.each {|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})/ - } - ether[0] - end - end - - Facter.add(:macaddress) do - confine :operatingsystem => %w{FreeBSD OpenBSD} - setcode do - ether = [] - output = %x{/sbin/ifconfig} - output.each {|s| - if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ - ether.push($1) - end - } - ether[0] - end - end - - Facter.add(:macaddress) do - confine :kernel => :darwin - setcode do - ether = nil - output = %x{/sbin/ifconfig} - - output.split(/^\S/).each { |str| - if str =~ /10baseT/ # we're wired - str =~ /ether (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ - ether = $1 - end - } - - ether - end - end - - Facter.add(:ipaddress) do - confine :kernel => :linux - setcode do - ip = nil - output = %x{/sbin/ifconfig} - - output.split(/^\S/).each { |str| - if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp = $1 - unless tmp =~ /127\./ - ip = tmp - break - end - end - } - - ip - end - end - Facter.add(:ipaddress) do - confine :kernel => %w{FreeBSD OpenBSD solaris} - setcode do - ip = nil - output = %x{/sbin/ifconfig} - - output.split(/^\S/).each { |str| - if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp = $1 - unless tmp =~ /127\./ - ip = tmp - break - end - end - } - - ip - end - end - Facter.add(:ipaddress) do - confine :kernel => %w{NetBSD} - setcode do - ip = nil - output = %x{/sbin/ifconfig -a} - - output.split(/^\S/).each { |str| - if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp = $1 - unless tmp =~ /127\./ - ip = tmp - break - end - end - } - - ip - end - end - Facter.add(:ipaddress) do - confine :kernel => %w{darwin} - setcode do - ip = nil - iface = "" - output = %x{/usr/sbin/netstat -rn} - if output =~ /^default\s*\S*\s*\S*\s*\S*\s*\S*\s*(\S*).*/ - iface = $1 - else - warn "Could not find a default route. Using first non-loopback interface" - end - if(iface != "") - output = %x{/sbin/ifconfig #{iface}} - else - output = %x{/sbin/ifconfig} - end - - output.split(/^\S/).each { |str| - if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp = $1 - unless tmp =~ /127\./ - ip = tmp - break - end - end - } - - ip - end - end - Facter.add(:hostname) do - confine :kernel => :darwin, :kernelrelease => "R7" - setcode do - %x{/usr/sbin/scutil --get LocalHostName} - end - end - Facter.add(:iphostnumber) do - confine :kernel => :darwin, :kernelrelease => "R6" - setcode do - %x{/usr/sbin/scutil --get LocalHostName} - end - end - Facter.add(:iphostnumber) do - confine :kernel => :darwin, :kernelrelease => "R6" - setcode do - ether = nil - output = %x{/sbin/ifconfig} - - output =~ /HWaddr (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ - ether = $1 - - ether - end - end - - Facter.add(:ps) do - setcode do 'ps -ef' end - end - - Facter.add(:ps) do - confine :operatingsystem => %w{FreeBSD NetBSD OpenBSD Darwin} - setcode do 'ps -auxwww' end - end - - Facter.add(:id) do - #confine :kernel => %w{Solaris Linux} - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo} - setcode "whoami" - end - - locals = [] - - # Now find all our loadable facts - factdirs = [] # All the places to check for facts - - # See if we can find any other facts in the regular Ruby lib - # paths - $:.each do |dir| - fdir = File.join(dir, "facter") - if FileTest.exists?(fdir) and FileTest.directory?(fdir) - factdirs.push(fdir) - end - end - # Also check anything in 'FACTERLIB' - if ENV['FACTERLIB'] - ENV['FACTERLIB'].split(":").each do |fdir| - factdirs.push(fdir) - end - end - factdirs.each do |fdir| - Dir.glob("#{fdir}/*.rb").each do |file| - # Load here, rather than require, because otherwise - # the facts won't get reloaded if someone calls - # "loadfacts". Really only important in testing, but, - # well, it's important in testing. - begin - load file - rescue => detail - warn "Could not load %s: %s" % - [file, detail] - end - end - end - - - # Now try to get facts from the environment - ENV.each do |name, value| - if name =~ /^facter_?(\w+)$/i - Facter.add($1) do - setcode { value } - end - end - end + # Return our registered search directories. + def self.search_path + @search_path.dup end - - Facter.loadfacts end - -# $Id$ diff -Nru facter-1.3.8/LICENSE facter-1.5.6/LICENSE --- facter-1.3.8/LICENSE 2007-09-24 06:57:18.000000000 +0000 +++ facter-1.5.6/LICENSE 2009-05-18 22:19:03.000000000 +0000 @@ -1,17 +1,674 @@ -Facter - Host Fact Detection and Reporting. Copyright (C) 2005 Reductive Labs LLC + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 -Reductive Labs can be contacted at: info@reductivelabs.com + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. -This program and entire repository 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 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 + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. 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 +them 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 prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. 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. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey 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; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If 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 convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU 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 that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + 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. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +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. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + 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 +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 3 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, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program 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, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU 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 Lesser General +Public License instead of this License. But first, please read +. diff -Nru facter-1.3.8/Rakefile facter-1.5.6/Rakefile --- facter-1.3.8/Rakefile 2007-09-24 06:59:19.000000000 +0000 +++ facter-1.5.6/Rakefile 2009-06-04 22:08:10.000000000 +0000 @@ -1,46 +1,108 @@ # Rakefile for facter -begin - require 'rake/reductive' -rescue LoadError - $stderr.puts "You must have the Reductive build library in your RUBYLIB." - exit(14) -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/**/*.rb', - 'test/**/*.rb', - 'doc/**/*', - 'etc/*' - ] - - #p.epmhosts = %w{culain} - #p.rpmhost = "fedora1" - #p.sunpkghost = "sol10b" -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" -end - -if project.has?(:epm) - project.mkepmtask do |task| - task.bins = FileList.new("bin/facter") - task.rubylibs = FileList.new('lib/**/*') +$: << 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@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 + +Rake::PackageTask.new("facter", Facter::FACTERVERSION) do |pkg| + pkg.package_dir = 'pkg' + pkg.need_tar_gz = true + pkg.package_files = FILES.to_a +end + +Rake::GemPackageTask.new(spec) do |pkg| +end + +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 + +desc "Prep CI RSpec tests" +task :ci_prep do + require 'rubygems' + 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 + raise "Patches already exist matching '00*.patch'; clean up first" + end + + unless %x{git status} =~ /On branch (.+)/ + raise "Could not get branch from 'git status'" + end + branch = $1 + + unless branch =~ %r{^([^\/]+)/([^\/]+)/([^\/]+)$} + raise "Branch name does not follow // model; cannot autodetect parent branch" + end + + type, parent, name = $1, $2, $3 + + # Create all of the patches + sh "git format-patch -C -M -s -n --subject-prefix='PATCH/facter' #{parent}..HEAD" + + # And then mail them out. + + # If we've got more than one patch, add --compose + if Dir.glob("00*.patch").length > 1 + compose = "--compose" + else + compose = "" end + + # Now send the mail. + sh "git send-email #{compose} --no-signed-off-by-cc --suppress-from --to puppet-dev@googlegroups.com 00*.patch" + + # Finally, clean up the patches + sh "rm 00*.patch" end -# $Id$ diff -Nru facter-1.3.8/README facter-1.5.6/README --- facter-1.3.8/README 2007-09-24 06:57:18.000000000 +0000 +++ facter-1.5.6/README 2009-05-18 22:19:03.000000000 +0000 @@ -3,8 +3,6 @@ like the output of 'uname', public ssh and cfengine keys, the number of processors, etc. -It currently cannot collect very much information, but it is architected to be -both OS and OS version specific. +See bin/facter for an example of the interface. -See bin/facter or http://reductivelabs.com/project/enhost for an example of the -interface. +See http://reductivelabs.com/projects/facter/ for more details. diff -Nru facter-1.3.8/README.rst facter-1.5.6/README.rst --- facter-1.3.8/README.rst 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/README.rst 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,26 @@ +Facter +====== + +This package is largely meant to be a library for collecting facts about your +system. These facts are mostly strings (i.e., not numbers), and are things +like the output of ``uname``, public ssh and cfengine keys, the number of +processors, etc. + +See ``bin/facter`` for an example of the interface. + +Running Facter +++++++++++++++ + +Run the ``facter`` binary on the command for a full list of facts supported on your host. + +Adding your own facts ++++++++++++++++++++++ + +See the `Adding Facts`_ wiki page for details of how to add your own custom facts to Facter. + +Further Information ++++++++++++++++++++ + +See http://reductivelabs.com/projects/facter/ for more details. + +.. _Adding Facts: http://reductivelabs.com/trac/puppet/wiki/AddingFacts diff -Nru facter-1.3.8/spec/integration/facter.rb facter-1.5.6/spec/integration/facter.rb --- facter-1.3.8/spec/integration/facter.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/integration/facter.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../spec_helper' + +describe Facter do + before do + Facter.reset + end + + after do + Facter.reset + end + + it "should create a new collection if one does not exist" do + Facter.reset + coll = mock('coll') + Facter::Util::Collection.stubs(:new).returns coll + Facter.collection.should equal(coll) + Facter.reset + end + + it "should remove the collection when reset" do + old = Facter.collection + Facter.reset + Facter.collection.should_not equal(old) + end +end diff -Nru facter-1.3.8/spec/Rakefile facter-1.5.6/spec/Rakefile --- facter-1.3.8/spec/Rakefile 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/Rakefile 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,18 @@ +require File.join(File.dirname(__FILE__), "spec_helper.rb") +require 'rake' +require 'spec/rake/spectask' + +basedir = File.dirname(__FILE__) +puppetlibdir = File.join(basedir, "../lib") +puppettestlibdir = File.join(basedir, "../test/lib") +speclibdir = File.join(basedir, "lib") + +libs = [puppetlibdir, puppettestlibdir, speclibdir] +desc "Run all specs" +Spec::Rake::SpecTask.new('all') do |t| + t.spec_files = FileList['integration/**/*.rb', 'unit/**/*.rb'] + t.libs = libs + t.spec_opts = ['--options', 'spec.opts'] +end + +task :default => [:all] diff -Nru facter-1.3.8/spec/spec_helper.rb facter-1.5.6/spec/spec_helper.rb --- facter-1.3.8/spec/spec_helper.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/spec_helper.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,16 @@ +dir = File.expand_path(File.dirname(__FILE__)) + +$LOAD_PATH.unshift("#{dir}/") +$LOAD_PATH.unshift("#{dir}/../lib") + +require 'rubygems' +require 'mocha' +require 'spec' +require 'facter' + +# load any monkey-patches +Dir["#{dir}/monkey_patches/*.rb"].map { |file| require file } + +Spec::Runner.configure do |config| + config.mock_with :mocha +end diff -Nru facter-1.3.8/spec/spec.opts facter-1.5.6/spec/spec.opts --- facter-1.3.8/spec/spec.opts 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/spec.opts 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,3 @@ +--colour +--loadby +mtime diff -Nru facter-1.3.8/spec/unit/data/6.0-STABLE_FreeBSD_ifconfig facter-1.5.6/spec/unit/data/6.0-STABLE_FreeBSD_ifconfig --- facter-1.3.8/spec/unit/data/6.0-STABLE_FreeBSD_ifconfig 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/data/6.0-STABLE_FreeBSD_ifconfig 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,12 @@ +fxp0: flags=8843 mtu 1500 + options=b + inet x.x.58.26 netmask 0xfffffff8 broadcast x.x.58.31 + inet x.x.58.27 netmask 0xffffffff broadcast x.x.58.27 + inet x.x.58.28 netmask 0xffffffff broadcast x.x.58.28 + inet x.x.58.29 netmask 0xffffffff broadcast x.x.58.29 + inet x.x.58.30 netmask 0xffffffff broadcast x.x.58.30 + ether 00:0e:0c:68:67:7c + media: Ethernet autoselect (100baseTX ) + status: active +lo0: flags=8049 mtu 16384 + inet 127.0.0.1 netmask 0xff000000 \ No newline at end of file diff -Nru facter-1.3.8/spec/unit/data/darwin_ifconfig_all_with_multiple_interfaces facter-1.5.6/spec/unit/data/darwin_ifconfig_all_with_multiple_interfaces --- facter-1.3.8/spec/unit/data/darwin_ifconfig_all_with_multiple_interfaces 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/data/darwin_ifconfig_all_with_multiple_interfaces 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,10 @@ +lo0: flags=8049 mtu 16384 + inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 + inet 127.0.0.1 netmask 0xff000000 + inet6 ::1 prefixlen 128 +en0: flags=8863 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 -Nru facter-1.3.8/spec/unit/data/darwin_ifconfig_single_interface facter-1.5.6/spec/unit/data/darwin_ifconfig_single_interface --- facter-1.3.8/spec/unit/data/darwin_ifconfig_single_interface 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/data/darwin_ifconfig_single_interface 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,6 @@ +en1: flags=8863 mtu 1500 + inet6 fe80::21c:b3ff:febe:81c9%en1 prefixlen 64 scopeid 0x6 + inet 10.0.0.101 netmask 0xffffff00 broadcast 10.0.0.255 + ether 00:1c:b3:be:81:c9 + media: autoselect status: active + supported media: autoselect diff -Nru facter-1.3.8/spec/unit/data/linux_ifconfig_all_with_single_interface facter-1.5.6/spec/unit/data/linux_ifconfig_all_with_single_interface --- facter-1.3.8/spec/unit/data/linux_ifconfig_all_with_single_interface 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/data/linux_ifconfig_all_with_single_interface 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,18 @@ +eth0 Link encap:Ethernet HWaddr 00:0c:29:52:15:e9 + inet addr:172.16.15.133 Bcast:172.16.15.255 Mask:255.255.255.0 + inet6 addr: fe80::20c:29ff:fe52:15e9/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:173 errors:173 dropped:0 overruns:0 frame:0 + TX packets:208 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:40970 (40.0 KB) TX bytes:24760 (24.1 KB) + Interrupt:16 Base address:0x2024 + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:16436 Metric:1 + RX packets:1630 errors:0 dropped:0 overruns:0 frame:0 + TX packets:1630 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:81500 (79.5 KB) TX bytes:81500 (79.5 KB) \ No newline at end of file diff -Nru facter-1.3.8/spec/unit/data/Mac_OS_X_10.5.5_ifconfig facter-1.5.6/spec/unit/data/Mac_OS_X_10.5.5_ifconfig --- facter-1.3.8/spec/unit/data/Mac_OS_X_10.5.5_ifconfig 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/data/Mac_OS_X_10.5.5_ifconfig 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,26 @@ +lo0: flags=8049 mtu 16384 + inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 + inet 127.0.0.1 netmask 0xff000000 + inet6 ::1 prefixlen 128 +gif0: flags=8010 mtu 1280 +stf0: flags=0<> mtu 1280 +en0: flags=8863 mtu 1500 + ether 00:1b:63:ae:02:66 + media: autoselect status: inactive + supported media: autoselect 10baseT/UTP 10baseT/UTP 10baseT/UTP 10baseT/UTP 100baseTX 100baseTX 100baseTX 100baseTX 1000baseT 1000baseT 1000baseT none +fw0: flags=8863 mtu 4078 + lladdr 00:1e:52:ff:fe:31:1a:80 + media: autoselect status: inactive + supported media: autoselect +en1: flags=8863 mtu 1500 + inet6 fe80::21e:52ff:fe70:d7b6%en1 prefixlen 64 scopeid 0x6 + inet 192.168.0.4 netmask 0xffffff00 broadcast 192.168.0.255 + ether 00:1e:52:70:d7:b6 + media: autoselect status: active + supported media: autoselect +vmnet8: flags=8863 mtu 1500 + inet 172.16.15.1 netmask 0xffffff00 broadcast 172.16.15.255 + ether 00:50:56:c0:00:08 +vmnet1: flags=8863 mtu 1500 + inet 192.168.89.1 netmask 0xffffff00 broadcast 192.168.89.255 + ether 00:50:56:c0:00:01 diff -Nru facter-1.3.8/spec/unit/data/solaris_ifconfig_single_interface facter-1.5.6/spec/unit/data/solaris_ifconfig_single_interface --- facter-1.3.8/spec/unit/data/solaris_ifconfig_single_interface 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/data/solaris_ifconfig_single_interface 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,3 @@ +e1000g0: flags=201004843 mtu 1500 index 2 + inet 172.16.15.138 netmask ffffff00 broadcast 172.16.15.255 + ether 0:c:29:c1:70:2a \ No newline at end of file diff -Nru facter-1.3.8/spec/unit/facter.rb facter-1.5.6/spec/unit/facter.rb --- facter-1.3.8/spec/unit/facter.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/facter.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,134 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../spec_helper' + +describe Facter do + + it "should have a version" do + Facter.version.should =~ /^[0-9]+(\.[0-9]+)*$/ + end + + it "should have a method for returning its collection" do + Facter.should respond_to(:collection) + end + + it "should cache the collection" do + Facter.collection.should equal(Facter.collection) + end + + it "should delegate the :flush method to the collection" do + Facter.collection.expects(:flush) + Facter.flush + end + + it "should delegate the :fact method to the collection" do + Facter.collection.expects(:fact) + Facter.fact + end + + it "should delegate the :list method to the collection" do + Facter.collection.expects(:list) + Facter.list + end + + it "should load all facts when listing" do + Facter.collection.expects(:load_all) + Facter.collection.stubs(:list) + Facter.list + end + + it "should delegate the :to_hash method to the collection" do + Facter.collection.expects(:to_hash) + Facter.to_hash + end + + it "should load all facts when calling :to_hash" do + Facter.collection.expects(:load_all) + Facter.collection.stubs(:to_hash) + Facter.to_hash + end + + it "should delegate the :value method to the collection" do + Facter.collection.expects(:value) + Facter.value + end + + it "should delegate the :each method to the collection" do + Facter.collection.expects(:each) + Facter.each + end + + it "should load all facts when calling :each" do + Facter.collection.expects(:load_all) + Facter.collection.stubs(:each) + Facter.each + end + + it "should yield to the block when using :each" do + Facter.collection.stubs(:load_all) + Facter.collection.stubs(:each).yields "foo" + result = [] + Facter.each { |f| result << f } + result.should == %w{foo} + end + + describe "when provided code as a string" do + it "should execute the code in the shell" do + Facter.add("shell_testing") do + setcode "echo yup" + end + + Facter["shell_testing"].value.should == "yup" + end + end + + describe "when passed code as a block" do + it "should execute the provided block" do + Facter.add("block_testing") { setcode { "foo" } } + + Facter["block_testing"].value.should == "foo" + end + end + + describe Facter[:hostname] do + it "should have its ldapname set to 'cn'" do + Facter[:hostname].ldapname.should == "cn" + end + end + + describe Facter[:ipaddress] do + it "should have its ldapname set to 'iphostnumber'" do + Facter[:ipaddress].ldapname.should == "iphostnumber" + end + end + + # #33 Make sure we only get one mac address + it "should only return one mac address" do + Facter.value(:macaddress).should_not be_include(" ") + end + + it "should have a method for registering directories to search" do + Facter.should respond_to(:search) + end + + it "should have a method for returning the registered search directories" do + Facter.should respond_to(:search_path) + end + + describe "when registering directories to search" do + after { Facter.instance_variable_set("@search_path", []) } + + it "should allow registration of a directory" do + Facter.search "/my/dir" + end + + it "should allow registration of multiple directories" do + Facter.search "/my/dir", "/other/dir" + end + + it "should return all registered directories when asked" do + Facter.search "/my/dir", "/other/dir" + Facter.search_path.should == %w{/my/dir /other/dir} + end + end +end diff -Nru facter-1.3.8/spec/unit/interfaces.rb facter-1.5.6/spec/unit/interfaces.rb --- facter-1.3.8/spec/unit/interfaces.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/interfaces.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,19 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../spec_helper' + +require 'facter' + +describe "Per Interface IP facts" do + before do + Facter.loadfacts + end + + it "should replace the ':' in an interface list with '_'" do + # So we look supported + Facter.fact(:kernel).stubs(:value).returns("SunOS") + + Facter::Util::IP.expects(:get_interfaces).returns %w{eth0:1 eth1:2} + Facter.fact(:interfaces).value.should == %{eth0_1,eth1_2} + end +end diff -Nru facter-1.3.8/spec/unit/operatingsystem.rb facter-1.5.6/spec/unit/operatingsystem.rb --- facter-1.3.8/spec/unit/operatingsystem.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/operatingsystem.rb 2009-05-18 22:19:03.000000000 +0000 @@ -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 -Nru facter-1.3.8/spec/unit/selinux.rb facter-1.5.6/spec/unit/selinux.rb --- facter-1.3.8/spec/unit/selinux.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/selinux.rb 2009-05-18 22:19:03.000000000 +0000 @@ -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 -Nru facter-1.3.8/spec/unit/util/collection.rb facter-1.5.6/spec/unit/util/collection.rb --- facter-1.3.8/spec/unit/util/collection.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/util/collection.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,255 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'facter/util/collection' + +describe Facter::Util::Collection do + it "should have a method for adding facts" do + Facter::Util::Collection.new.should respond_to(:add) + end + + it "should have a method for returning a loader" do + Facter::Util::Collection.new.should respond_to(:loader) + end + + it "should use an instance of the Loader class as its loader" do + Facter::Util::Collection.new.loader.should be_instance_of(Facter::Util::Loader) + end + + it "should cache its loader" do + coll = Facter::Util::Collection.new + coll.loader.should equal(coll.loader) + end + + it "should have a method for loading all facts" do + Facter::Util::Collection.new.should respond_to(:load_all) + end + + it "should delegate its load_all method to its loader" do + coll = Facter::Util::Collection.new + coll.loader.expects(:load_all) + coll.load_all + end + + describe "when adding facts" do + before do + @coll = Facter::Util::Collection.new + end + + it "should create a new fact if no fact with the same name already exists" do + fact = mock 'fact' + Facter::Util::Fact.expects(:new).with { |name, *args| name == :myname }.returns fact + + @coll.add(:myname) + end + + it "should accept options" do + @coll.add(:myname, :ldapname => "whatever") { } + end + + it "should set any appropriate options on the fact instances" do + # Use a real fact instance, because we're using respond_to? + fact = Facter::Util::Fact.new(:myname) + fact.expects(:ldapname=).with("testing") + Facter::Util::Fact.expects(:new).with(:myname).returns fact + + @coll.add(:myname, :ldapname => "testing") + end + + it "should set appropriate options on the resolution instance" do + fact = Facter::Util::Fact.new(:myname) + Facter::Util::Fact.expects(:new).with(:myname).returns fact + + resolve = Facter::Util::Resolution.new(:myname) {} + fact.expects(:add).returns resolve + + @coll.add(:myname, :timeout => "myval") {} + end + + it "should not pass fact-specific options to resolutions" do + fact = Facter::Util::Fact.new(:myname) + Facter::Util::Fact.expects(:new).with(:myname).returns fact + + resolve = Facter::Util::Resolution.new(:myname) {} + fact.expects(:add).returns resolve + + fact.expects(:ldapname=).with("foo") + resolve.expects(:timeout=).with("myval") + + @coll.add(:myname, :timeout => "myval", :ldapname => "foo") {} + end + + it "should fail if invalid options are provided" do + lambda { @coll.add(:myname, :foo => :bar) }.should raise_error(ArgumentError) + end + + describe "and a block is provided" do + it "should use the block to add a resolution to the fact" do + fact = mock 'fact' + Facter::Util::Fact.expects(:new).returns fact + + fact.expects(:add) + + @coll.add(:myname) {} + end + end + end + + it "should have a method for retrieving facts by name" do + Facter::Util::Collection.new.should respond_to(:fact) + end + + describe "when retrieving facts" do + before do + @coll = Facter::Util::Collection.new + + @fact = @coll.add("YayNess") + end + + it "should return the fact instance specified by the name" do + @coll.fact("YayNess").should equal(@fact) + end + + it "should be case-insensitive" do + @coll.fact("yayness").should equal(@fact) + end + + it "should treat strings and symbols equivalently" do + @coll.fact(:yayness).should equal(@fact) + end + + it "should use its loader to try to load the fact if no fact can be found" do + @coll.loader.expects(:load).with(:testing) + @coll.fact("testing") + end + + it "should return nil if it cannot find or load the fact" do + @coll.loader.expects(:load).with(:testing) + @coll.fact("testing").should be_nil + end + end + + it "should have a method for returning a fact's value" do + Facter::Util::Collection.new.should respond_to(:value) + end + + describe "when returning a fact's value" do + before do + @coll = Facter::Util::Collection.new + @fact = @coll.add("YayNess") + + @fact.stubs(:value).returns "result" + end + + it "should use the 'fact' method to retrieve the fact" do + @coll.expects(:fact).with(:yayness).returns @fact + @coll.value(:yayness) + end + + it "should return the result of calling :value on the fact" do + @fact.expects(:value).returns "result" + + @coll.value("YayNess").should == "result" + end + + it "should be case-insensitive" do + @coll.value("yayness").should_not be_nil + end + + it "should treat strings and symbols equivalently" do + @coll.value(:yayness).should_not be_nil + end + end + + it "should return the fact's value when the array index method is used" do + @coll = Facter::Util::Collection.new + @coll.expects(:value).with("myfact").returns "foo" + @coll["myfact"].should == "foo" + end + + it "should have a method for flushing all facts" do + @coll = Facter::Util::Collection.new + @fact = @coll.add("YayNess") + + @fact.expects(:flush) + + @coll.flush + end + + it "should have a method that returns all fact names" do + @coll = Facter::Util::Collection.new + @coll.add(:one) + @coll.add(:two) + + @coll.list.sort { |a,b| a.to_s <=> b.to_s }.should == [:one, :two] + end + + it "should have a method for returning a hash of fact values" do + Facter::Util::Collection.new.should respond_to(:to_hash) + end + + describe "when returning a hash of values" do + before do + @coll = Facter::Util::Collection.new + @fact = @coll.add(:one) + @fact.stubs(:value).returns "me" + end + + it "should return a hash of fact names and values with the fact names as strings" do + @coll.to_hash.should == {"one" => "me"} + end + + it "should not include facts that did not return a value" do + f = @coll.add(:two) + f.stubs(:value).returns nil + @coll.to_hash.should_not be_include(:two) + end + end + + it "should have a method for iterating over all facts" do + Facter::Util::Collection.new.should respond_to(:each) + end + + it "should include Enumerable" do + Facter::Util::Collection.ancestors.should be_include(Enumerable) + end + + describe "when iterating over facts" do + before do + @coll = Facter::Util::Collection.new + @one = @coll.add(:one) + @two = @coll.add(:two) + end + + it "should yield each fact name and the fact value" do + @one.stubs(:value).returns "ONE" + @two.stubs(:value).returns "TWO" + facts = {} + @coll.each do |fact, value| + facts[fact] = value + end + facts.should == {"one" => "ONE", "two" => "TWO"} + end + + it "should convert the fact name to a string" do + @one.stubs(:value).returns "ONE" + @two.stubs(:value).returns "TWO" + facts = {} + @coll.each do |fact, value| + fact.should be_instance_of(String) + end + end + + it "should only yield facts that have values" do + @one.stubs(:value).returns "ONE" + @two.stubs(:value).returns nil + facts = {} + @coll.each do |fact, value| + facts[fact] = value + end + + facts.should_not be_include("two") + end + end +end diff -Nru facter-1.3.8/spec/unit/util/confine.rb facter-1.5.6/spec/unit/util/confine.rb --- facter-1.3.8/spec/unit/util/confine.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/util/confine.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,140 @@ +#!/usr/bin/env ruby + +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 + Facter::Util::Confine.new("yay", true).fact.should == "yay" + end + + it "should accept a value specified individually" do + Facter::Util::Confine.new("yay", "test").values.should == ["test"] + end + + it "should accept multiple values specified at once" do + Facter::Util::Confine.new("yay", "test", "other").values.should == ["test", "other"] + end + + it "should fail if no fact name is provided" do + lambda { Facter::Util::Confine.new(nil, :test) }.should raise_error(ArgumentError) + end + + it "should fail if no values were provided" do + lambda { Facter::Util::Confine.new("yay") }.should raise_error(ArgumentError) + end + + it "should have a method for testing whether it matches" do + Facter::Util::Confine.new("yay", :test).should respond_to(:true?) + end + + describe "when evaluating" do + before do + @confine = Facter::Util::Confine.new("yay", "one", "two", "Four", :xy, true, 1, [3,4]) + @fact = mock 'fact' + Facter.stubs(:[]).returns @fact + end + + it "should return false if the fact does not exist" do + Facter.expects(:[]).with("yay").returns nil + + @confine.true?.should be_false + end + + it "should use the returned fact to get the value" do + Facter.expects(:[]).with("yay").returns @fact + + @fact.expects(:value).returns nil + + @confine.true? + end + + it "should return false if the fact has no value" do + @fact.stubs(:value).returns nil + + @confine.true?.should be_false + end + + it "should return true if any of the provided values matches the fact's value" do + @fact.stubs(:value).returns "two" + + @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 -Nru facter-1.3.8/spec/unit/util/fact.rb facter-1.5.6/spec/unit/util/fact.rb --- facter-1.3.8/spec/unit/util/fact.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/util/fact.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,129 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'facter/util/fact' + +describe Facter::Util::Fact do + it "should require a name" do + lambda { Facter::Util::Fact.new }.should raise_error(ArgumentError) + end + + it "should always downcase the name and convert it to a symbol" do + Facter::Util::Fact.new("YayNess").name.should == :yayness + end + + it "should default to its name converted to a string as its ldapname" do + Facter::Util::Fact.new("YayNess").ldapname.should == "yayness" + end + + it "should allow specifying the ldap name at initialization" do + Facter::Util::Fact.new("YayNess", :ldapname => "fooness").ldapname.should == "fooness" + end + + it "should fail if an unknown option is provided" do + lambda { Facter::Util::Fact.new('yay', :foo => :bar) }.should raise_error(ArgumentError) + end + + it "should have a method for adding resolution mechanisms" do + Facter::Util::Fact.new("yay").should respond_to(:add) + end + + describe "when adding resolution mechanisms" do + before do + @fact = Facter::Util::Fact.new("yay") + + @resolution = mock 'resolution' + @resolution.stub_everything + + end + + it "should fail if no block is given" do + lambda { @fact.add }.should raise_error(ArgumentError) + end + + it "should create a new resolution instance" do + Facter::Util::Resolution.expects(:new).returns @resolution + + @fact.add { } + end + + it "should instance_eval the passed block on the new resolution" do + @resolution.expects(:instance_eval) + + Facter::Util::Resolution.stubs(:new).returns @resolution + + @fact.add { } + end + + it "should re-sort the resolutions by length, so the most restricted resolutions are first" do + r1 = stub 'r1', :length => 1 + r2 = stub 'r2', :length => 2 + r3 = stub 'r3', :length => 0 + Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) + @fact.add { } + @fact.add { } + @fact.add { } + + @fact.instance_variable_get("@resolves").should == [r2, r1, r3] + end + end + + it "should be able to return a value" do + Facter::Util::Fact.new("yay").should respond_to(:value) + end + + describe "when returning a value" do + before do + @fact = Facter::Util::Fact.new("yay") + end + + it "should return nil if there are no resolutions" do + Facter::Util::Fact.new("yay").value.should be_nil + end + + it "should return the first value returned by a resolution" do + r1 = stub 'r1', :length => 2, :value => nil, :suitable? => true + r2 = stub 'r2', :length => 1, :value => "yay", :suitable? => true + r3 = stub 'r3', :length => 0, :value => "foo", :suitable? => true + Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) + @fact.add { } + @fact.add { } + @fact.add { } + + @fact.value.should == "yay" + end + + it "should short-cut returning the value once one is found" do + r1 = stub 'r1', :length => 2, :value => "foo", :suitable? => true + r2 = stub 'r2', :length => 1, :suitable? => true # would fail if 'value' were asked for + Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2) + @fact.add { } + @fact.add { } + + @fact.value + end + + it "should skip unsuitable resolutions" do + r1 = stub 'r1', :length => 2, :suitable? => false # would fail if 'value' were asked for' + r2 = stub 'r2', :length => 1, :value => "yay", :suitable? => true + Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2) + @fact.add { } + @fact.add { } + + @fact.value.should == "yay" + end + + it "should return nil if the value is the empty string" do + r1 = stub 'r1', :suitable? => true, :value => "" + Facter::Util::Resolution.expects(:new).returns r1 + @fact.add { } + + @fact.value.should be_nil + end + end + + it "should have a method for flushing the cached fact" do + Facter::Util::Fact.new(:foo).should respond_to(:flush) + end +end diff -Nru facter-1.3.8/spec/unit/util/ip.rb facter-1.5.6/spec/unit/util/ip.rb --- facter-1.3.8/spec/unit/util/ip.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/util/ip.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,122 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'facter/util/ip' + +describe Facter::Util::IP do + [:freebsd, :linux, :netbsd, :openbsd, :sunos, :darwin].each do |platform| + it "should be supported on #{platform}" do + Facter::Util::IP.supported_platforms.should be_include(platform) + end + end + + it "should return a list of interfaces" do + Facter::Util::IP.should respond_to(:get_interfaces) + end + + it "should return an empty list of interfaces on an unknown kernel" do + Facter.stubs(:value).returns("UnknownKernel") + Facter::Util::IP.get_interfaces().should == [] + end + + it "should return a list with a single interface on Linux with a single interface" do + sample_output_file = File.dirname(__FILE__) + '/../data/linux_ifconfig_all_with_single_interface' + linux_ifconfig = File.new(sample_output_file).read() + Facter::Util::IP.stubs(:get_all_interface_output).returns(linux_ifconfig) + 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) + end + + it "should not return interface information for unsupported platforms" do + Facter.stubs(:value).with(:kernel).returns("bleah") + Facter::Util::IP.get_interface_value("e1000g0", "netmask").should == [] + end + + 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() + + 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", "netmask").should == "255.255.255.0" + end + + 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() + + Facter::Util::IP.expects(:get_single_interface_output).with("fxp0").returns(ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("FreeBSD") + + Facter::Util::IP.get_interface_value("fxp0", "macaddress").should == "00:0e:0c:68:67:7c" + end + + 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() + + Facter::Util::IP.expects(:get_single_interface_output).with("en1").returns(ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("Darwin") + + 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() + + 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", "netmask").should == "255.255.255.0" + end + + it "should return a human readable netmask on Darwin" do + sample_output_file = File.dirname(__FILE__) + "/../data/darwin_ifconfig_single_interface" + + darwin_ifconfig_interface = File.new(sample_output_file).read() + + Facter::Util::IP.expects(:get_single_interface_output).with("en1").returns(darwin_ifconfig_interface) + Facter.stubs(:value).with(:kernel).returns("Darwin") + + Facter::Util::IP.get_interface_value("en1", "netmask").should == "255.255.255.0" + end + + [:freebsd, :netbsd, :openbsd, :sunos, :darwin].each do |platform| + it "should require conversion from hex on #{platform}" do + Facter::Util::IP.convert_from_hex?(platform).should == true + end + end +end diff -Nru facter-1.3.8/spec/unit/util/loader.rb facter-1.5.6/spec/unit/util/loader.rb --- facter-1.3.8/spec/unit/util/loader.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/util/loader.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,219 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'facter/util/loader' + +describe Facter::Util::Loader do + def with_env(values) + old = {} + values.each do |var, value| + if old_val = ENV[var] + old[var] = old_val + end + ENV[var] = value + end + yield + values.each do |var, value| + if old.include?(var) + ENV[var] = old[var] + else + ENV.delete(var) + end + end + end + + it "should have a method for loading individual facts by name" do + Facter::Util::Loader.new.should respond_to(:load) + end + + it "should have a method for loading all facts" do + Facter::Util::Loader.new.should respond_to(:load_all) + end + + it "should have a method for returning directories containing facts" do + Facter::Util::Loader.new.should respond_to(:search_path) + end + + describe "when determining the search path" do + before do + @loader = Facter::Util::Loader.new + @settings = mock 'settings' + @settings.stubs(:value).returns "/eh" + end + + it "should include the facter subdirectory of all paths in ruby LOAD_PATH" do + dirs = $LOAD_PATH.collect { |d| File.join(d, "facter") } + paths = @loader.search_path + + dirs.each do |dir| + paths.should be_include(dir) + end + end + + it "should include all search paths registered with Facter" do + Facter.expects(:search_path).returns %w{/one /two} + paths = @loader.search_path + paths.should be_include("/one") + paths.should be_include("/two") + end + + describe "and the FACTERLIB environment variable is set" do + it "should include all paths in FACTERLIB" do + with_env "FACTERLIB" => "/one/path:/two/path" do + paths = @loader.search_path + %w{/one/path /two/path}.each do |dir| + paths.should be_include(dir) + end + end + end + end + end + + describe "when loading facts" do + before do + @loader = Facter::Util::Loader.new + @loader.stubs(:search_path).returns [] + end + + it "should load values from the matching environment variable if one is present" do + Facter.expects(:add).with("testing") + + with_env "facter_testing" => "yayness" do + @loader.load(:testing) + end + end + + it "should load any files in the search path with names matching the fact name" do + @loader.expects(:search_path).returns %w{/one/dir /two/dir} + FileTest.stubs(:exist?).returns false + FileTest.expects(:exist?).with("/one/dir/testing.rb").returns true + FileTest.expects(:exist?).with("/two/dir/testing.rb").returns true + + Kernel.expects(:load).with("/one/dir/testing.rb") + Kernel.expects(:load).with("/two/dir/testing.rb") + + @loader.load(:testing) + end + + it "should load any ruby files in directories matching the fact name in the search path" do + @loader.expects(:search_path).returns %w{/one/dir} + FileTest.stubs(:exist?).returns false + FileTest.expects(:directory?).with("/one/dir/testing").returns true + + Dir.expects(:entries).with("/one/dir/testing").returns %w{two.rb} + + Kernel.expects(:load).with("/one/dir/testing/two.rb") + + @loader.load(:testing) + end + + it "should not load files that don't end in '.rb'" do + @loader.expects(:search_path).returns %w{/one/dir} + FileTest.stubs(:exist?).returns false + FileTest.expects(:directory?).with("/one/dir/testing").returns true + + Dir.expects(:entries).with("/one/dir/testing").returns %w{one} + + Kernel.expects(:load).never + + @loader.load(:testing) + end + end + + describe "when loading all facts" do + before do + @loader = Facter::Util::Loader.new + @loader.stubs(:search_path).returns [] + + FileTest.stubs(:directory?).returns true + end + + it "should skip directories that do not exist" do + @loader.expects(:search_path).returns %w{/one/dir} + + FileTest.expects(:directory?).with("/one/dir").returns false + + Dir.expects(:entries).with("/one/dir").never + + @loader.load_all + end + + it "should load all files in all search paths" do + @loader.expects(:search_path).returns %w{/one/dir /two/dir} + + Dir.expects(:entries).with("/one/dir").returns %w{a.rb b.rb} + Dir.expects(:entries).with("/two/dir").returns %w{c.rb d.rb} + + %w{/one/dir/a.rb /one/dir/b.rb /two/dir/c.rb /two/dir/d.rb}.each { |f| Kernel.expects(:load).with(f) } + + @loader.load_all + end + + it "should load all files in all subdirectories in all search paths" do + @loader.expects(:search_path).returns %w{/one/dir /two/dir} + + Dir.expects(:entries).with("/one/dir").returns %w{a} + Dir.expects(:entries).with("/two/dir").returns %w{b} + + %w{/one/dir/a /two/dir/b}.each { |f| File.expects(:directory?).with(f).returns true } + + Dir.expects(:entries).with("/one/dir/a").returns %w{c.rb} + Dir.expects(:entries).with("/two/dir/b").returns %w{d.rb} + + %w{/one/dir/a/c.rb /two/dir/b/d.rb}.each { |f| Kernel.expects(:load).with(f) } + + @loader.load_all + end + + it "should not load files in the util subdirectory" do + @loader.expects(:search_path).returns %w{/one/dir} + + Dir.expects(:entries).with("/one/dir").returns %w{util} + + File.expects(:directory?).with("/one/dir/util").returns true + + Dir.expects(:entries).with("/one/dir/util").never + + @loader.load_all + end + + it "should not load files in a lib subdirectory" do + @loader.expects(:search_path).returns %w{/one/dir} + + Dir.expects(:entries).with("/one/dir").returns %w{lib} + + File.expects(:directory?).with("/one/dir/lib").returns true + + Dir.expects(:entries).with("/one/dir/lib").never + + @loader.load_all + end + + it "should not load files in '.' or '..'" do + @loader.expects(:search_path).returns %w{/one/dir} + + Dir.expects(:entries).with("/one/dir").returns %w{. ..} + + File.expects(:entries).with("/one/dir/.").never + File.expects(:entries).with("/one/dir/..").never + + @loader.load_all + end + + it "should load all facts from the environment" do + Facter.expects(:add).with('one') + Facter.expects(:add).with('two') + + with_env "facter_one" => "yayness", "facter_two" => "boo" do + @loader.load_all + end + end + + it "should only load all facts one time" do + @loader.expects(:load_env).once + @loader.load_all + @loader.load_all + end + end +end diff -Nru facter-1.3.8/spec/unit/util/macosx.rb facter-1.5.6/spec/unit/util/macosx.rb --- facter-1.3.8/spec/unit/util/macosx.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/util/macosx.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,47 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'facter/util/macosx' + +describe Facter::Util::Macosx do + it "should be able to retrieve profiler data as xml for a given data field" do + Facter::Util::Resolution.expects(:exec).with("/usr/sbin/system_profiler -xml foo").returns "yay" + Facter::Util::Macosx.profiler_xml("foo").should == "yay" + end + + it "should use PList to convert xml to data structures" do + Plist.expects(:parse_xml).with("foo").returns "bar" + + Facter::Util::Macosx.intern_xml("foo").should == "bar" + end + + describe "when collecting profiler data" do + it "should return the first value in the '_items' hash in the first value of the results of the system_profiler data, with the '_name' field removed, if the profiler returns data" do + @result = [ + '_items' => [ + {'_name' => "foo", "yay" => "bar"} + ] + ] + Facter::Util::Macosx.expects(:profiler_xml).with("foo").returns "eh" + Facter::Util::Macosx.expects(:intern_xml).with("eh").returns @result + Facter::Util::Macosx.profiler_data("foo").should == {"yay" => "bar"} + end + + it "should return nil if an exception is thrown during parsing of xml" do + Facter::Util::Macosx.expects(:profiler_xml).with("foo").returns "eh" + Facter::Util::Macosx.expects(:intern_xml).with("eh").raises "boo!" + Facter::Util::Macosx.profiler_data("foo").should be_nil + end + end + + it "should return the profiler data for 'SPHardwareDataType' as the hardware information" do + Facter::Util::Macosx.expects(:profiler_data).with("SPHardwareDataType").returns "eh" + Facter::Util::Macosx.hardware_overview.should == "eh" + end + + it "should return the profiler data for 'SPSoftwareDataType' as the os information" do + Facter::Util::Macosx.expects(:profiler_data).with("SPSoftwareDataType").returns "eh" + Facter::Util::Macosx.os_overview.should == "eh" + end +end diff -Nru facter-1.3.8/spec/unit/util/resolution.rb facter-1.5.6/spec/unit/util/resolution.rb --- facter-1.3.8/spec/unit/util/resolution.rb 1970-01-01 00:00:00.000000000 +0000 +++ facter-1.5.6/spec/unit/util/resolution.rb 2009-05-18 22:19:03.000000000 +0000 @@ -0,0 +1,215 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'facter/util/resolution' + +describe Facter::Util::Resolution do + it "should require a name" do + lambda { Facter::Util::Resolution.new }.should raise_error(ArgumentError) + end + + it "should have a name" do + Facter::Util::Resolution.new("yay").name.should == "yay" + end + + it "should have a method for setting the code" do + Facter::Util::Resolution.new("yay").should respond_to(:setcode) + end + + it "should support a timeout value" do + Facter::Util::Resolution.new("yay").should respond_to(:timeout=) + end + + it "should default to a timeout of 0 seconds" do + Facter::Util::Resolution.new("yay").limit.should == 0 + end + + it "should provide a 'limit' method that returns the timeout" do + res = Facter::Util::Resolution.new("yay") + res.timeout = "testing" + res.limit.should == "testing" + end + + describe "when setting the code" do + before do + @resolve = Facter::Util::Resolution.new("yay") + end + + it "should default to /bin/sh as the interpreter if a string is provided" do + @resolve.setcode "foo" + @resolve.interpreter.should == "/bin/sh" + end + + it "should set the code to any provided string" do + @resolve.setcode "foo" + @resolve.code.should == "foo" + end + + it "should set the code to any provided block" do + block = lambda { } + @resolve.setcode(&block) + @resolve.code.should equal(block) + end + + it "should prefer the string over a block" do + @resolve.setcode("foo") { } + @resolve.code.should == "foo" + end + + it "should fail if neither a string nor block has been provided" do + lambda { @resolve.setcode }.should raise_error(ArgumentError) + end + end + + it "should be able to return a value" do + Facter::Util::Resolution.new("yay").should respond_to(:value) + end + + describe "when returning the value" do + before do + @resolve = Facter::Util::Resolution.new("yay") + end + + describe "and the code is a string" do + it "should return the result of executing the code with the interpreter" do + @resolve.setcode "/bin/foo" + Facter::Util::Resolution.expects(:exec).with("/bin/foo", "/bin/sh").returns "yup" + + @resolve.value.should == "yup" + end + + it "should return nil if the value is an empty string" do + @resolve.setcode "/bin/foo" + Facter::Util::Resolution.stubs(:exec).returns "" + @resolve.value.should be_nil + end + end + + describe "and the code is a block" do + it "should warn but not fail if the code fails" do + @resolve.setcode { raise "feh" } + @resolve.expects(:warn) + @resolve.value.should be_nil + end + + it "should return the value returned by the block" do + @resolve.setcode { "yayness" } + @resolve.value.should == "yayness" + end + + it "should return nil if the value is an empty string" do + @resolve.setcode { "" } + @resolve.value.should be_nil + end + + it "should use its limit method to determine the timeout, to avoid conflict when a 'timeout' method exists for some other reason" do + @resolve.expects(:timeout).never + @resolve.expects(:limit).returns "foo" + Timeout.expects(:timeout).with("foo") + + @resolve.value + end + + it "should timeout after the provided timeout" do + @resolve.expects(:warn) + @resolve.timeout = 0.1 + @resolve.setcode { sleep 2; raise "This is a test" } + + @resolve.value.should be_nil + end + + it "should waitall to avoid zombies if the timeout is exceeded" do + @resolve.stubs(:warn) + @resolve.timeout = 0.1 + @resolve.setcode { sleep 2; raise "This is a test" } + + Thread.expects(:new).yields + Process.expects(:waitall) + + @resolve.value + end + end + end + + it "should return its value when converted to a string" do + @resolve = Facter::Util::Resolution.new("yay") + @resolve.expects(:value).returns "myval" + @resolve.to_s.should == "myval" + end + + it "should allow the adding of confines" do + Facter::Util::Resolution.new("yay").should respond_to(:confine) + end + + it "should provide a method for returning the number of confines" do + @resolve = Facter::Util::Resolution.new("yay") + @resolve.confine "one" => "foo", "two" => "fee" + @resolve.length.should == 2 + end + + it "should return 0 confines when no confines have been added" do + Facter::Util::Resolution.new("yay").length.should == 0 + end + + it "should have a method for determining if it is suitable" do + Facter::Util::Resolution.new("yay").should respond_to(:suitable?) + end + + describe "when adding confines" do + before do + @resolve = Facter::Util::Resolution.new("yay") + end + + it "should accept a hash of fact names and values" do + lambda { @resolve.confine :one => "two" }.should_not raise_error + end + + it "should create a Util::Confine instance for every argument in the provided hash" do + Facter::Util::Confine.expects(:new).with("one", "foo") + Facter::Util::Confine.expects(:new).with("two", "fee") + + @resolve.confine "one" => "foo", "two" => "fee" + end + + end + + describe "when determining suitability" do + before do + @resolve = Facter::Util::Resolution.new("yay") + end + + it "should always be suitable if no confines have been added" do + @resolve.should be_suitable + end + + it "should be unsuitable if any provided confines return false" do + confine1 = mock 'confine1', :true? => true + confine2 = mock 'confine2', :true? => false + Facter::Util::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2) + @resolve.confine :one => :two, :three => :four + + @resolve.should_not be_suitable + end + + it "should be suitable if all provided confines return true" do + confine1 = mock 'confine1', :true? => true + confine2 = mock 'confine2', :true? => true + Facter::Util::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2) + @resolve.confine :one => :two, :three => :four + + @resolve.should be_suitable + end + end + + it "should have a class method for executing code" do + Facter::Util::Resolution.should respond_to(:exec) + end + + # It's not possible, AFAICT, to mock %x{}, so I can't really test this bit. + describe "when executing code" do + it "should fail if any interpreter other than /bin/sh is requested" do + lambda { Facter::Util::Resolution.exec("/something", "/bin/perl") }.should raise_error(ArgumentError) + end + end +end