-
-
Notifications
You must be signed in to change notification settings - Fork 267
/
pear.rb
137 lines (118 loc) · 3.16 KB
/
pear.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
require 'puppet/provider/package'
# PHP PEAR support.
Puppet::Type.type(:package).provide :pear, :parent => Puppet::Provider::Package do
desc "PHP PEAR support. By default uses the installed channels, but you can specify the path to a pear package via ``source``."
has_feature :versionable
has_feature :upgradeable
has_feature :install_options
case Facter.value(:operatingsystem)
when "Solaris"
commands :pearcmd => "/opt/coolstack/php5/bin/pear"
else
commands :pearcmd => "pear"
end
def self.pearlist(hash)
command = [command(:pearcmd), "list", "-a"]
channel = "pear"
begin
list = execute(command).split("\n")
list = list.collect do |set|
if match = /INSTALLED PACKAGES, CHANNEL (.*):/i.match(set)
channel = match[1].downcase
end
if hash[:justme]
if set =~ /^#{hash[:justme]}/
pearhash = pearsplit(set, channel)
pearhash[:provider] = :pear
pearhash
else
nil
end
else
if pearhash = pearsplit(set, channel)
pearhash[:provider] = :pear
pearhash
else
nil
end
end
end.reject { |p| p.nil? }
rescue Puppet::ExecutionFailure => detail
raise Puppet::Error, "Could not list pears: %s" % detail
end
if hash[:justme]
return list.shift
else
return list
end
end
def self.pearsplit(desc, channel)
desc.strip!
case desc
when /^$/ then return nil
when /^INSTALLED/i then return nil
when /no packages installed/i then return nil
when /^=/ then return nil
when /^PACKAGE/i then return nil
when /^(\S+)\s+(\S+)\s+(\S+)\s*$/ then
name = $1
version = $2
state = $3
return {
:name => "#{channel}/#{name}",
:ensure => state == 'stable' ? version : state
}
else
Puppet.debug "Could not match '%s'" % desc
nil
end
end
def self.instances
pearlist(:local => true).collect do |hash|
new(hash)
end
end
def install(useversion = true)
command = ["-D", "auto_discover=1", "upgrade"]
if @resource[:install_options]
command << @resource[:install_options]
else
command << "--alldeps"
end
if source = @resource[:source]
command << source
else
if (! @resource.should(:ensure).is_a? Symbol) and useversion
command << "#{@resource[:name]}-#{@resource.should(:ensure)}"
else
command << @resource[:name]
end
end
pearcmd(*command)
end
def latest
# This always gets the latest version available.
version = ''
command = [command(:pearcmd), "remote-info", @resource[:name]]
list = execute(command).split("\n")
list = list.collect do |set|
if set =~ /^Latest/
version = set.split[1]
end
end
return version
end
def query
self.class.pearlist(:justme => @resource[:name])
end
def uninstall
output = pearcmd "uninstall", @resource[:name]
if output =~ /^uninstall ok/
else
raise Puppet::Error, output
end
end
def update
self.install(false)
end
end