Class: Facter::Operatingsystem::Linux

Inherits:
Base
  • Object
show all
Defined in:
lib/facter/operatingsystem/linux.rb

Direct Known Subclasses

CumulusLinux, OsReleaseLinux

Instance Method Summary collapse

Methods inherited from Base

#get_operatingsystemrelease_hash

Instance Method Details

#collect_lsb_informationObject



228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/facter/operatingsystem/linux.rb', line 228

def collect_lsb_information
  @lsb_data ||= Facter::Core::Execution.exec("lsb_release -cidvr 2>/dev/null")
  @data_hash = {}

  if @lsb_data && @data_hash.empty?
    @lsb_data.split("\n").each do |element|
      lsbvar, value = element.split("\t")
      lsbvar.gsub!(":", "")
      @data_hash["#{lsbvar}"] = value
    end
  end

  @data_hash unless @data_hash.empty?
end

#get_lsb_facts_hashObject



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/facter/operatingsystem/linux.rb', line 196

def get_lsb_facts_hash
  lsb_hash = {}
  if lsbdistcodename = get_lsbdistcodename
    lsb_hash["distcodename"] = lsbdistcodename
  end

  if lsbdistid = get_lsbdistid
    lsb_hash["distid"] = lsbdistid
  end

  if lsbdistdescription = get_lsbdistdescription
    lsb_hash["distdescription"] = lsbdistdescription
  end

  if lsbrelease = get_lsbrelease
    lsb_hash["release"] = lsbrelease
  end

  if lsbdistrelease = get_lsbdistrelease
    lsb_hash["distrelease"] = lsbdistrelease
  end

  if lsbmajdistrelease = get_lsbmajdistrelease
    lsb_hash["majdistrelease"]  = lsbmajdistrelease
  end

  if lsbminordistrelease = get_lsbminordistrelease
    lsb_hash["minordistrelease"]  = lsbminordistrelease
  end
  lsb_hash
end

#get_lsbdistcodenameObject



126
127
128
129
130
# File 'lib/facter/operatingsystem/linux.rb', line 126

def get_lsbdistcodename
  if (lsb_data = collect_lsb_information)
    lsb_data["Codename"]
  end
end

#get_lsbdistdescriptionObject



138
139
140
141
142
# File 'lib/facter/operatingsystem/linux.rb', line 138

def get_lsbdistdescription
  if (lsb_data = collect_lsb_information)
    lsb_data["Description"].sub(/^"(.*)"$/,'\1')
  end
end

#get_lsbdistidObject



132
133
134
135
136
# File 'lib/facter/operatingsystem/linux.rb', line 132

def get_lsbdistid
  if (lsb_data = collect_lsb_information)
    lsb_data["Distributor ID"]
  end
end

#get_lsbdistreleaseObject



150
151
152
153
154
# File 'lib/facter/operatingsystem/linux.rb', line 150

def get_lsbdistrelease
  if (lsb_data = collect_lsb_information)
    lsb_data["Release"]
  end
end

#get_lsbmajdistreleaseObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/facter/operatingsystem/linux.rb', line 156

def get_lsbmajdistrelease
  lsbdistrelease = get_lsbdistrelease
  if get_operatingsystem == "Ubuntu"
    if (lsbreleasemajor = lsbdistrelease.split("."))
      if lsbreleasemajor.length >= 2
        result = "#{lsbreleasemajor[0]}.#{lsbreleasemajor[1]}"
      else
        result = lsbreleasemajor
      end
    end
  else
    if /(\d*)\./i =~ lsbdistrelease
      result = $1
    else
      result = lsbdistrelease
    end
  end
  result
end

#get_lsbminordistreleaseObject



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/facter/operatingsystem/linux.rb', line 176

def get_lsbminordistrelease
  lsbdistrelease = get_lsbdistrelease
  if get_operatingsystem == "Ubuntu"
    mdata = /(\d+).(\d+).(\d+)/i.match(lsbdistrelease)
    if mdata == nil
      result = nil
    else
      result = mdata[3]
    end
  else
    mdata = /(\d+).(\d+)/i.match(lsbdistrelease)
    if mdata == nil
      result = nil
    else
      result = mdata[2]
    end
  end
  result
end

#get_lsbreleaseObject



144
145
146
147
148
# File 'lib/facter/operatingsystem/linux.rb', line 144

def get_lsbrelease
  if (lsb_data = collect_lsb_information)
    lsb_data["LSB Version"]
  end
end

#get_operatingsystemObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/facter/operatingsystem/linux.rb', line 8

def get_operatingsystem
  if Facter.value(:kernel) == "GNU/kFreeBSD"
    "GNU/kFreeBSD"
  elsif lsbdistid = get_lsbdistid
    if lsbdistid == "Ubuntu"
      @operatingsystem ||= "Ubuntu"
    elsif lsbdistid == "LinuxMint"
      @operatingsystem ||= "LinuxMint"
    else
      @operatingsystem ||= get_operatingsystem_with_release_files
    end
  else
    @operatingsystem ||= get_operatingsystem_with_release_files
  end
end

#get_operatingsystemmajorreleaseObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/facter/operatingsystem/linux.rb', line 86

def get_operatingsystemmajorrelease
  if operatingsystemrelease = get_operatingsystemrelease
    if get_operatingsystem == "Ubuntu"
      if (releasemajor = operatingsystemrelease.split("."))
        if releasemajor.length >= 2
          "#{releasemajor[0]}.#{releasemajor[1]}"
        else
          releasemajor[0]
        end
      end
    else
      if (releasemajor = operatingsystemrelease.split(".")[0])
        releasemajor
      end
    end
  end
end

#get_operatingsystemminorreleaseObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/facter/operatingsystem/linux.rb', line 104

def get_operatingsystemminorrelease
  if operatingsystemrelease = get_operatingsystemrelease
    if get_operatingsystem == "Ubuntu"
      if (releaseminor = operatingsystemrelease.split(".")[2])
        releaseminor
      end
    else
      if (releaseminor = operatingsystemrelease.split(".")[1])
        if releaseminor.include? "-"
          releaseminor.split("-")[0]
        else
          releaseminor
        end
      end
    end
  end
end

#get_operatingsystemreleaseObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/facter/operatingsystem/linux.rb', line 47

def get_operatingsystemrelease
  case get_operatingsystem
  when "Alpine"
    get_alpine_release_with_release_file
  when "ALT", "ALT Starter Kit", "ALT Workstation", "ALT Server"
    get_alt_release_with_release_file
  when "Amazon"
    get_amazon_release_with_lsb
  when "AristaEOS"
    get_arista_release_with_release_file
  when "BlueWhite64"
    get_bluewhite_release_with_release_file
  when "CentOS", "RedHat", "Scientific", "SLC", "Ascendos", "CloudLinux", "PSBM",
       "XenServer", "Fedora", "MeeGo", "OracleLinux", "OEL", "oel", "OVS", "ovs",
       "VirtuozzoLinux"
    get_redhatish_release_with_release_file
  when "Debian"
    get_debian_release_with_release_file
  when "LinuxMint"
    get_linux_mint_release_with_release_file
  when "Mageia"
    get_mageia_release_with_release_file
  when "OpenWrt"
    get_openwrt_release_with_release_file
  when "Slackware"
    get_slackware_release_with_release_file
  when "Slamd64"
    get_slamd64_release_with_release_file
 when "SLES", "SLED", "OpenSuSE"
    get_suse_release_with_release_file
  when "Ubuntu"
    get_ubuntu_release_with_release_file
  when "VMwareESX"
    get_vmwareESX_release_with_release_file
  else
    Facter.value(:kernelrelease)
  end
end

#get_osfamilyObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/facter/operatingsystem/linux.rb', line 24

def get_osfamily
  case get_operatingsystem
  when "RedHat", "Fedora", "CentOS", "Scientific", "SLC", "Ascendos",
       "CloudLinux", "PSBM", "OracleLinux", "OVS", "OEL", "Amazon",
       "XenServer", "VirtuozzoLinux"
    "RedHat"
  when "LinuxMint", "Ubuntu", "Debian"
    "Debian"
  when "SLES", "SLED", "OpenSuSE", "SuSE"
    "Suse"
  when "Gentoo"
    "Gentoo"
  when "Archlinux", "Manjarolinux"
    "Archlinux"
  when "Mageia", "Mandriva", "Mandrake"
    "Mandrake"
  when "ALT Linux", "ALT Starter Kit", "ALT Workstation", "ALT Server"
    "ALT"
  else
    Facter.value("kernel")
  end
end

#has_lsb?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/facter/operatingsystem/linux.rb', line 122

def has_lsb?
  true
end