Sha256: 545031d3524233682980039182ce85ec70fe40e08bdb133e52ddc13891f52a68

Contents?: true

Size: 1.42 KB

Versions: 29

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Solaris
      class OsRelease < BaseResolver
        init_resolver

        OS_VERSION_REGEX_PATTERNS = ['Solaris \d+ \d+/\d+ s(\d+)[sx]?_u(\d+)wos_',
                                     'Solaris (\d+)[.](\d+)', 'Solaris (\d+)'].freeze

        class << self
          private

          def post_resolve(fact_name, _options)
            @fact_list.fetch(fact_name) { build_release_facts(fact_name) }
          end

          def build_release_facts(fact_name)
            result = Facter::Util::FileHelper.safe_read('/etc/release', nil)
            return @fact_list[fact_name] = nil if result.nil?

            OS_VERSION_REGEX_PATTERNS.each do |os_version_regex|
              major, minor = search_for_os_version(/#{os_version_regex}/, result)
              next unless major || minor

              @fact_list[:major] = major
              @fact_list[:minor] = minor
              @fact_list[:full] = major == '10' ? major + '_u' + minor : major + '.' + minor
              break
            end
            @fact_list[fact_name]
          end

          def search_for_os_version(regex_pattern, text)
            result = text.match(regex_pattern)
            major, minor = result.captures if result
            minor = regex_pattern == /Solaris (\d+)/ ? '0' : minor
            return [major, minor] if major && minor
          end
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
facter-4.5.2 lib/facter/resolvers/solaris/os_release.rb
facter-4.5.1 lib/facter/resolvers/solaris/os_release.rb
facter-4.5.0 lib/facter/resolvers/solaris/os_release.rb
facter-4.4.3 lib/facter/resolvers/solaris/os_release.rb
facter-4.4.2 lib/facter/resolvers/solaris/os_release.rb
facter-4.4.1 lib/facter/resolvers/solaris/os_release.rb
facter-4.4.0 lib/facter/resolvers/solaris/os_release.rb
facter-4.3.1 lib/facter/resolvers/solaris/os_release.rb
facter-4.3.0 lib/facter/resolvers/solaris/os_release.rb
facter-4.2.14 lib/facter/resolvers/solaris/os_release.rb
facter-4.2.13 lib/facter/resolvers/solaris/os_release.rb
facter-4.2.12 lib/facter/resolvers/solaris/os_release.rb
facter-4.2.11 lib/facter/resolvers/solaris/os_release.rb
facter-4.2.10 lib/facter/resolvers/solaris/os_release.rb
facter-4.2.9 lib/facter/resolvers/solaris/os_release.rb
facter-4.2.8 lib/facter/resolvers/solaris/os_release.rb
facter-4.2.7 lib/facter/resolvers/solaris/os_release.rb
facter-4.2.6 lib/facter/resolvers/solaris/os_release.rb
facter-4.2.5 lib/facter/resolvers/solaris/os_release.rb
facter-4.2.4 lib/facter/resolvers/solaris/os_release.rb