lib/ohai/plugins/linux/platform.rb in ohai-0.3.6 vs lib/ohai/plugins/linux/platform.rb in ohai-0.4.0

- old
+ new

@@ -13,11 +13,18 @@ # 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. # +def get_redhatish_platform(contents) + contents[/^Red Hat/i] ? "redhat" : contents[/(\w+)/i, 1].downcase +end +def get_redhatish_version(contents) + contents[/Rawhide/i] ? contents[/((\d+) \(Rawhide\))/i, 1].downcase : contents[/release ([\d\.]+)/, 1] +end + provides "platform", "platform_version" require_plugin 'linux::lsb' if lsb[:id] @@ -25,19 +32,19 @@ platform_version lsb[:release] elsif File.exists?("/etc/debian_version") platform "debian" platform_version File.read("/etc/debian_version").chomp elsif File.exists?("/etc/redhat-release") - platform "redhat" - File.open("/etc/redhat-release").each do |line| - platform "centos" if line =~ /centos/i - case line - when /\(Rawhide\)/ - platform_version "rawhide" - when /release ([\d\.]+)/ - platform_version $1 - end - end + contents = File.read("/etc/redhat-release").chomp + platform get_redhatish_platform(contents) + platform_version get_redhatish_version(contents) elsif File.exists?('/etc/gentoo-release') platform "gentoo" platform_version IO.read('/etc/gentoo-release').scan(/(\d+|\.+)/).join +elsif File.exists?('/etc/SuSE-release') + platform "suse" + platform_version IO.read('/etc/SuSE-release').scan(/\d+\.\d+/)[0] +elsif File.exists?('/etc/arch-release') + platform "arch" + # no way to determine platform_version in a rolling release distribution + # kernel release will be used - ex. 2.6.32-ARCH end