Sha256: 47d86167055304657ad44bae7ad119560a2bf66b6aef8aca49ce2c9942a8eed9

Contents?: true

Size: 1.64 KB

Versions: 14

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    class SolarisRelease < BaseResolver
      @log = Facter::Log.new(self)
      @semaphore = Mutex.new
      @fact_list ||= {}
      @os_version_regex_patterns = ['Solaris \d+ \d+/\d+ s(\d+)[sx]?_u(\d+)wos_',
                                    'Solaris (\d+)[.](\d+)', 'Solaris (\d+)']
      class << self
        private

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

        def build_release_facts(fact_name)
          result = read_os_release_file
          return unless result

          @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

        def read_os_release_file
          output, status = Open3.capture2('cat /etc/release')
          if !status.to_s.include?('exit 0') || output.empty?
            @log.error('Could not build release fact because of missing or empty file /etc/release')
            return
          end
          output
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
facter-4.0.20 lib/resolvers/solaris/solaris_os_release_resolver.rb
facter-4.0.19 lib/resolvers/solaris/solaris_os_release_resolver.rb
facter-4.0.18 lib/resolvers/solaris/solaris_os_release_resolver.rb
facter-4.0.17 lib/resolvers/solaris/solaris_os_release_resolver.rb
facter-4.0.16 lib/resolvers/solaris/solaris_os_release_resolver.rb
facter-4.0.15 lib/resolvers/solaris/solaris_os_release_resolver.rb
facter-4.0.14 lib/resolvers/solaris/solaris_os_release_resolver.rb
facter-4.0.13 lib/resolvers/solaris/solaris_os_release_resolver.rb
facter-4.0.12 lib/resolvers/solaris/solaris_os_release_resolver.rb
facter-4.0.11 lib/resolvers/solaris/solaris_os_release_resolver.rb
facter-4.0.10.pre lib/resolvers/solaris/solaris_os_release_resolver.rb
facter-4.0.9.pre lib/resolvers/solaris/solaris_os_release_resolver.rb
facter-4.0.8.pre lib/resolvers/solaris/solaris_os_release_resolver.rb
facter-4.0.7.pre lib/resolvers/solaris/solaris_os_release_resolver.rb