class Facter::Resolvers::OsRelease

Private Class Methods

append_linux_to_os_name() click to toggle source
# File lib/facter/resolvers/os_release.rb, line 111
def append_linux_to_os_name
  os_name = @fact_list[:name]
  @fact_list[:name] = os_name + 'Linux' if os_name.downcase.start_with?('virtuozzo')
end
capitalize_os_name() click to toggle source
# File lib/facter/resolvers/os_release.rb, line 106
def capitalize_os_name
  os_name = @fact_list[:name]
  @fact_list[:name] = os_name.capitalize if os_name.downcase.start_with?('arch', 'manjaro')
end
fill_fact_list(pairs) click to toggle source
# File lib/facter/resolvers/os_release.rb, line 58
def fill_fact_list(pairs)
  result = Hash[*pairs.flatten]
  result.each { |k, v| @fact_list[k.downcase.to_sym] = v }
end
join_os_name() click to toggle source
# File lib/facter/resolvers/os_release.rb, line 94
def join_os_name
  os_name = @fact_list[:name]
  @fact_list[:name] = if os_name.downcase.start_with?('red', 'oracle', 'arch', 'manjaro')
                        os_name = os_name.split(' ')[0..1].join
                        os_name
                      elsif os_name.downcase.end_with?('mariner')
                        os_name.split(' ')[-1].strip
                      else
                        os_name.split(' ')[0].strip
                      end
end
normalize_os_name() click to toggle source
# File lib/facter/resolvers/os_release.rb, line 85
def normalize_os_name
  os_name = @fact_list[:name]
  @fact_list[:name] = if os_name.downcase.start_with?('sles')
                        'SLES'
                      else
                        os_name
                      end
end
post_resolve(fact_name, _options) click to toggle source
# File lib/facter/resolvers/os_release.rb, line 22
def post_resolve(fact_name, _options)
  @fact_list.fetch(fact_name) do
    # If we get here multiple times per run it's probably because
    # someone's asking for a os-release value not present in the file
    # (e.g. VERSION is not a thing on rolling distributions, so this
    # code will always run if the resolver is being asked for :version,
    # because it'll never get cached).
    #
    # Just return early to avoid reparsing the file.
    return unless @fact_list.empty?

    pairs = read_and_parse_os_release_file
    return unless pairs

    fill_fact_list(pairs)

    process_name
    process_version_id
    process_id

    @fact_list[fact_name]
  end
end
process_id() click to toggle source
# File lib/facter/resolvers/os_release.rb, line 69
def process_id
  return unless @fact_list[:id]

  @fact_list[:id] = 'sles' if /sles_sap/i.match?(@fact_list[:id])
  @fact_list[:id] = 'opensuse' if /opensuse/i.match?(@fact_list[:id])
end
process_name() click to toggle source
# File lib/facter/resolvers/os_release.rb, line 76
def process_name
  return unless @fact_list[:name]

  normalize_os_name
  join_os_name
  capitalize_os_name
  append_linux_to_os_name
end
process_version_id() click to toggle source
# File lib/facter/resolvers/os_release.rb, line 63
def process_version_id
  return unless @fact_list[:version_id]

  @fact_list[:version_id] = "#{@fact_list[:version_id]}.0" unless /\./.match?(@fact_list[:version_id])
end
read_and_parse_os_release_file() click to toggle source
# File lib/facter/resolvers/os_release.rb, line 46
def read_and_parse_os_release_file
  content = Facter::Util::FileHelper.safe_readlines('/etc/os-release')
  return nil if content.empty?

  pairs = []
  content.each do |line|
    pairs << line.strip.delete('"').split('=', 2) unless line.start_with?('#')
  end

  pairs
end