Module: OS::Linux Private

Defined in:
os/linux.rb,
extend/os/linux/cleanup.rb,
extend/os/linux/formula.rb,
extend/os/linux/cli/parser.rb,
extend/os/linux/diagnostic.rb,
extend/os/linux/cask/config.rb,
extend/os/linux/cask/installer.rb,
extend/os/linux/cask/quarantine.rb,
extend/os/linux/simulate_system.rb,
extend/os/linux/development_tools.rb,
extend/os/linux/cask/artifact/moved.rb,
extend/os/linux/dependency_collector.rb,
os/linux/ld.rb,
os/linux/elf.rb,
os/linux/glibc.rb,
os/linux/kernel.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Helper module for querying system information on Linux.

Defined Under Namespace

Modules: CLI, Cask, Cleanup, DependencyCollector, DevelopmentTools, Diagnostic, Elf, Formula, Glibc, Kernel, Ld, SimulateSystem

Class Method Summary collapse

Class Method Details

.languageString?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



81
82
83
# File 'os/linux.rb', line 81

def self.language
  languages.first
end

.languagesArray<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'os/linux.rb', line 63

def self.languages
  return @languages if @languages.present?

  locale_variables = ENV.keys.grep(/^(?:LC_\S+|LANG|LANGUAGE)\Z/).sort
  ctl_ret = Utils.popen_read("localectl", "list-locales")
  if ctl_ret.present?
    list = ctl_ret.scan(/[^ \n"(),]+/)
  elsif locale_variables.present?
    keys = locale_variables.select { |var| ENV.fetch(var) }
    list = keys.map { |key| ENV.fetch(key) }
  else
    list = ["en_US.utf8"]
  end

  @languages = list.map { |item| item.split(".").first.tr("_", "-") }
end

.os_versionString

This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Get the OS version.

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'os/linux.rb', line 22

def self.os_version
  if which("lsb_release")
    lsb_info = Utils.popen_read("lsb_release", "-a")
    description = lsb_info[/^Description:\s*(.*)$/, 1].force_encoding("UTF-8")
    codename = lsb_info[/^Codename:\s*(.*)$/, 1]
    if codename.blank? || (codename == "n/a")
      description
    else
      "#{description} (#{codename})"
    end
  elsif (redhat_release = Pathname.new("/etc/redhat-release")).readable?
    redhat_release.read.chomp
  elsif ::OS_VERSION.present?
    ::OS_VERSION
  else
    "Unknown"
  end
end

.wsl?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


42
43
44
# File 'os/linux.rb', line 42

def self.wsl?
  /-microsoft/i.match?(OS.kernel_version.to_s)
end

.wsl_versionVersion

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'os/linux.rb', line 47

def self.wsl_version
  return Version::NULL unless wsl?

  kernel = OS.kernel_version.to_s
  if Version.new(T.must(kernel[/^([0-9.]*)-.*/, 1])) > Version.new("5.15")
    Version.new("2 (Microsoft Store)")
  elsif kernel.include?("-microsoft")
    Version.new("2")
  elsif kernel.include?("-Microsoft")
    Version.new("1")
  else
    Version::NULL
  end
end