Module: Train::Platforms::Detect::Helpers::Linux
- Included in:
- OSCommon
- Defined in:
- lib/train/platforms/detect/helpers/os_linux.rb
Instance Method Summary collapse
- #linux_os_release ⇒ Object
- #lsb_config(content) ⇒ Object
- #lsb_release(content) ⇒ Object
- #parse_os_release_info(raw) ⇒ Object
- #read_linux_lsb ⇒ Object
- #redhatish(path) ⇒ Object
- #redhatish_platform(conf) ⇒ Object
- #redhatish_version(conf) ⇒ Object
Instance Method Details
#linux_os_release ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/train/platforms/detect/helpers/os_linux.rb', line 27 def linux_os_release data = unix_file_contents("/etc/os-release") return if data.nil? os_info = parse_os_release_info(data) cisco_info_file = os_info["CISCO_RELEASE_INFO"] if cisco_info_file os_info.merge!(parse_os_release_info(unix_file_contents(cisco_info_file))) end os_info end |
#lsb_config(content) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/train/platforms/detect/helpers/os_linux.rb', line 53 def lsb_config(content) id = /^DISTRIB_ID=["']?(.+?)["']?$/.match(content) release = /^DISTRIB_RELEASE=["']?(.+?)["']?$/.match(content) codename = /^DISTRIB_CODENAME=["']?(.+?)["']?$/.match(content) { id: id.nil? ? nil : id[1], release: release.nil? ? nil : release[1], codename: codename.nil? ? nil : codename[1], } end |
#lsb_release(content) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/train/platforms/detect/helpers/os_linux.rb', line 64 def lsb_release(content) id = /^Distributor ID:\s+(.+)$/.match(content) release = /^Release:\s+(.+)$/.match(content) codename = /^Codename:\s+(.+)$/.match(content) { id: id.nil? ? nil : id[1], release: release.nil? ? nil : release[1], codename: codename.nil? ? nil : codename[1], } end |
#parse_os_release_info(raw) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/train/platforms/detect/helpers/os_linux.rb', line 40 def parse_os_release_info(raw) return {} if raw.nil? raw.lines.each_with_object({}) do |line, memo| line.strip! next if line.nil? || line.empty? next if line.start_with?("#") key, value = line.split("=", 2) memo[key] = value.gsub(/\A"|"\Z/, "") unless value.nil? || value.empty? end end |
#read_linux_lsb ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/train/platforms/detect/helpers/os_linux.rb', line 75 def read_linux_lsb return @lsb unless @lsb.empty? if !(raw = unix_file_contents("/etc/lsb-release")).nil? @lsb = lsb_config(raw) elsif !(raw = unix_file_contents("/usr/bin/lsb-release")).nil? @lsb = lsb_release(raw) end end |
#redhatish(path) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/train/platforms/detect/helpers/os_linux.rb', line 20 def redhatish(path) if (raw = unix_file_contents(path)) @platform[:release] = redhatish_version(raw) true end end |
#redhatish_platform(conf) ⇒ Object
3 4 5 |
# File 'lib/train/platforms/detect/helpers/os_linux.rb', line 3 def redhatish_platform(conf) conf =~ /^red hat/i ? "redhat" : /(\w+)/i.match(conf)[1].downcase end |
#redhatish_version(conf) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/train/platforms/detect/helpers/os_linux.rb', line 7 def redhatish_version(conf) case conf when /rawhide/i /((\d+) \(Rawhide\))/i.match(conf)[1].downcase when /Amazon Linux/i /([\d\.]+)/.match(conf)[1] when /derived from .*linux|amazon/i /Linux ((\d+|\.)+)/i.match(conf)[1] else /release ([\d\.]+)/.match(conf)[1] end end |