Class: Tpkg::OS::FreeBSD
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Tpkg::OS
#arch, create, #cron_dot_d_directory, #fqdn, #os, #os_name, register_implementation, #remove_native_stub_pkg, #stub_native_pkg, #sudo_default?, #sys_v_init_links
Constructor Details
#initialize(options = {}) ⇒ FreeBSD
Returns a new instance of FreeBSD.
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/tpkg/os/freebsd.rb', line 13
def initialize(options={})
@pkginfocmd = options[:pkginfocmd] || options[:testcmd] || 'pkg_info'
@pkgaddcmd = options[:pkgaddcmd] || options[:testcmd] || 'pkg_add'
@pkgdeletecmd = options[:pkgdeletecmd] || options[:testcmd] || 'pkg_delete'
@packagesite = options[:packagesite] ||
'ftp://ftp.freebsd.org/pub/FreeBSD/ports/<%= arch %>/packages-<%= os_version %>-stable/All/'
super
end
|
Class Method Details
.supported? ⇒ Boolean
7
8
9
10
|
# File 'lib/tpkg/os/freebsd.rb', line 7
def self.supported?
Facter.loadfacts
Facter['operatingsystem'].value == 'FreeBSD'
end
|
Instance Method Details
#available_native_packages(pkgname) ⇒ Object
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
|
# File 'lib/tpkg/os/freebsd.rb', line 42
def available_native_packages(pkgname)
native_packages = []
cmd = "#{@pkginfocmd} -E #{pkgname}-*"
puts "available_native_packages running '#{cmd}'" if @debug
Open3.popen3(cmd) do |stdin, stdout, stderr|
stdin.close
stdout.each_line do |line|
fbversion = line.sub("#{pkgname}-", '').chomp
version, package_version = fbversion.split('_', 2)
native_packages <<
Tpkg.pkg_for_native_package(
pkgname, version, package_version, :native_installed)
end
stderr_first_line = stderr.gets
end
if !$?.success?
if stderr_first_line !~ 'No match'
raise "available_native_packages error running pkg_info"
end
end
native_packages
end
|
#init_links(installed_path, tpkgfile) ⇒ Object
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/tpkg/os/freebsd.rb', line 32
def init_links(installed_path, tpkgfile)
links = []
init_directory = '/usr/local/etc/rc.d'
if tpkgfile[:init][:levels] && tpkgfile[:init][:levels].empty?
else
links << File.join(init_directory, File.basename(installed_path))
end
links
end
|
#install_native_package(pkg) ⇒ Object
83
84
85
86
87
88
|
# File 'lib/tpkg/os/freebsd.rb', line 83
def install_native_package(pkg)
pkgname = native_pkg_to_install_string(pkg)
cmd = "PACKAGESITE=#{packagesite} #{@pkgaddcmd} -r #{pkgname}"
puts "Running '#{cmd}' to install native package" if @debug
system('sh', '-c', cmd)
end
|
#native_pkg_to_install_string(pkg) ⇒ Object
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/tpkg/os/freebsd.rb', line 73
def native_pkg_to_install_string(pkg)
name = pkg[:metadata][:name]
version = pkg[:metadata][:version]
package_version = pkg[:metadata][:package_version]
pkgname = "#{name}-#{version}"
if package_version
pkgname << "_#{package_version}"
end
pkgname
end
|
#os_version ⇒ Object
105
106
107
108
109
110
111
112
|
# File 'lib/tpkg/os/freebsd.rb', line 105
def os_version
if !@os_version
fbver = Facter['operatingsystemrelease'].value
@os_version = fbver.split('.').first
end
super
end
|
#packagesite ⇒ Object
25
26
27
28
29
30
|
# File 'lib/tpkg/os/freebsd.rb', line 25
def packagesite
url = ERB.new(@packagesite).result(binding)
url << '/' if (url[-1] != '/')
url
end
|
#upgrade_native_package(pkg) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/tpkg/os/freebsd.rb', line 89
def upgrade_native_package(pkg)
pkgname = native_pkg_to_install_string(pkg)
deletecmd = "#{@pkgdeletecmd} #{pkgname}"
addcmd = "PACKAGESITE=#{packagesite} #{@pkgaddcmd} -r #{pkgname}"
puts "Running '#{deletecmd}' and '#{addcmd}' to upgrade native package" if @debug
system(deletecmd)
system('sh', '-c', addcmd)
end
|