Class: Tpkg::OS::RedHat
Overview
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Tpkg::OS
#arch, create, #fqdn, #native_pkg_to_install_string, #os, #os_name, register_implementation, #sudo_default?, #sys_v_init_links
Constructor Details
#initialize(options = {}) ⇒ RedHat
Returns a new instance of RedHat.
11
12
13
14
15
16
17
18
|
# File 'lib/tpkg/os/redhat.rb', line 11
def initialize(options={})
@yumcmd = options[:yumcmd] || options[:testcmd] || 'yum'
@rpmcmd = options[:rpmcmd] || options[:testcmd] || 'rpm'
@rpmbuildcmd = options[:rpmbuildcmd] || options[:testcmd] || 'rpmbuild'
@quiet = options[:quiet]
super
end
|
Class Method Details
.supported? ⇒ Boolean
5
6
7
8
|
# File 'lib/tpkg/os/redhat.rb', line 5
def self.supported?
Facter.loadfacts
['RedHat', 'CentOS', 'Fedora'].include?(Facter['operatingsystem'].value)
end
|
Instance Method Details
#available_native_packages(pkgname) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
|
# File 'lib/tpkg/os/redhat.rb', line 26
def available_native_packages(pkgname)
native_packages = []
[ {:arg => 'installed', :header => 'Installed', :source => :native_installed},
{:arg => 'available', :header => 'Available', :source => :native_available} ].each do |yum|
cmd = "#{@yumcmd} info #{yum[:arg]} #{pkgname}"
puts "available_native_packages running '#{cmd}'" if @debug
stderr_first_line = nil
Open3.popen3(cmd) do |stdin, stdout, stderr|
stdin.close
read_packages = false
name = version = package_version = nil
stdout.each_line do |line|
if line =~ /#{yum[:header]} Packages/
read_packages = true
elsif read_packages
if line =~ /^Name\s*:\s*(.+)/
name = $1.strip
elsif line =~ /^Arch\s*:\s*(.+)/
arch = $1.strip
elsif line =~ /^Version\s*:\s*(.+)/
version = $1.strip.to_s
elsif line =~ /^Release\s*:\s*(.+)/
package_version = $1.strip.to_s
elsif line =~ /^Repo\s*:\s*(.+)/
repo = $1.strip
elsif line =~ /^\s*$/
pkg = Tpkg.pkg_for_native_package(name, version, package_version, yum[:source])
native_packages << pkg
name = version = package_version = nil
end
end
end
stderr_first_line = stderr.gets
end
if !$?.success?
if stderr_first_line != "Error: No matching Packages to list\n"
raise "available_native_packages error running yum"
end
end
end
native_packages
end
|
#cron_dot_d_directory ⇒ Object
23
24
25
|
# File 'lib/tpkg/os/redhat.rb', line 23
def cron_dot_d_directory
'/etc/cron.d'
end
|
#init_links(installed_path, tpkgfile) ⇒ Object
20
21
22
|
# File 'lib/tpkg/os/redhat.rb', line 20
def init_links(installed_path, tpkgfile)
sys_v_init_links(installed_path, tpkgfile, ['2', '3', '4', '5'], '/etc/rc.d')
end
|
#install_native_package(pkg) ⇒ Object
76
77
78
79
80
81
|
# File 'lib/tpkg/os/redhat.rb', line 76
def install_native_package(pkg)
pkgname = native_pkg_to_install_string(pkg)
cmd = "#{@yumcmd} -y install #{pkgname}"
puts "Running '#{cmd}' to install native package" if @debug
system(cmd)
end
|
#os_version ⇒ Object
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/tpkg/os/redhat.rb', line 116
def os_version
if !@os_version
if Facter['lsbmajdistrelease'] &&
Facter['lsbmajdistrelease'].value &&
!Facter['lsbmajdistrelease'].value.empty?
@os_version = Facter['lsbmajdistrelease'].value
end
end
super
end
|
#remove_native_stub_pkg(pkg) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/tpkg/os/redhat.rb', line 102
def remove_native_stub_pkg(pkg)
native_deps = pkg[:metadata].get_native_deps
return if native_deps.empty?
stub_pkg_name = "stub_for_#{pkg[:metadata][:name]}"
cmd = "#{@yumcmd} -y remove #{stub_pkg_name}"
puts "Running '#{cmd} to remove native dependency stub" if @debug
puts cmd if @debug
system(cmd)
if !$?.success?
warn "Warning: Failed to remove native stub package for #{pkg[:metadata][:name]}" unless @quiet
end
end
|
#stub_native_pkg(pkg) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/tpkg/os/redhat.rb', line 88
def stub_native_pkg(pkg)
native_deps = pkg[:metadata].get_native_deps
return if native_deps.empty?
rpm = create_rpm("stub_for_#{pkg[:metadata][:name]}", native_deps)
return if rpm.nil?
cmd = "#{@rpmcmd} -i #{rpm}"
puts "Running '#{cmd} to install native dependency stub" if @debug
system(cmd)
if !$?.success?
warn "Warning: Failed to install native stub package for #{pkg[:metadata][:name]}" unless @quiet
end
end
|
#upgrade_native_package(pkg) ⇒ Object
82
83
84
85
86
87
|
# File 'lib/tpkg/os/redhat.rb', line 82
def upgrade_native_package(pkg)
pkgname = native_pkg_to_install_string(pkg)
cmd = "#{@yumcmd} -y install #{pkgname}"
puts "Running '#{cmd}' to upgrade native package" if @debug
system(cmd)
end
|