Skip to content

Commit 64a96d9

Browse files
committed
Adding pear provider
1 parent 97d6ccc commit 64a96d9

File tree

3 files changed

+129
-1
lines changed

3 files changed

+129
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.swp

lib/puppet/provider/pear/pear.rb

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
require 'puppet/provider/package'
2+
3+
# PHP PEAR support.
4+
Puppet::Type.type(:package).provide :pear, :parent => Puppet::Provider::Package do
5+
desc "PHP PEAR support. By default uses the installed channels, but you
6+
can specify the path to a pear package via ``source``."
7+
8+
has_feature :versionable
9+
has_feature :upgradeable
10+
11+
case Facter.value(:operatingsystem)
12+
when "Solaris"
13+
commands :pearcmd => "/opt/coolstack/php5/bin/pear"
14+
else
15+
commands :pearcmd => "pear"
16+
end
17+
18+
def self.pearlist(hash)
19+
command = [command(:pearcmd), "list", "-a"]
20+
21+
22+
begin
23+
list = execute(command).collect do |set|
24+
if hash[:justme]
25+
if set =~ /^hash[:justme]/
26+
if pearhash = pearsplit(set)
27+
pearhash[:provider] = :pear
28+
pearhash
29+
else
30+
nil
31+
end
32+
else
33+
nil
34+
end
35+
else
36+
if pearhash = pearsplit(set)
37+
pearhash[:provider] = :pear
38+
pearhash
39+
else
40+
nil
41+
end
42+
end
43+
44+
end.reject { |p| p.nil? }
45+
rescue Puppet::ExecutionFailure => detail
46+
raise Puppet::Error, "Could not list pears: %s" % detail
47+
end
48+
49+
if hash[:justme]
50+
return list.shift
51+
else
52+
return list
53+
end
54+
end
55+
56+
def self.pearsplit(desc)
57+
case desc
58+
when /^INSTALLED/: return nil
59+
when /^=/: return nil
60+
when /^PACKAGE/: return nil
61+
when /^$/: return nil
62+
when /^\(no packages installed\)$/: return nil
63+
when /^(\S+)\s+([.\d]+)\s+\S+\n/
64+
name = $1
65+
version = $2
66+
return {
67+
:name => name,
68+
:ensure => version
69+
}
70+
else
71+
Puppet.warning "Could not match %s" % desc
72+
nil
73+
end
74+
end
75+
76+
def self.instances
77+
pearlist(:local => true).collect do |hash|
78+
new(hash)
79+
end
80+
end
81+
82+
def install(useversion = true)
83+
command = ["upgrade"]
84+
85+
if source = @resource[:source]
86+
command << source
87+
else
88+
if (! @resource.should(:ensure).is_a? Symbol) and useversion
89+
# command << "-f"
90+
command << "#{@resource[:name]}-#{@resource.should(:ensure)}"
91+
else
92+
command << @resource[:name]
93+
end
94+
end
95+
96+
pearcmd(*command)
97+
end
98+
99+
def latest
100+
# This always gets the latest version available.
101+
version = ''
102+
command = [command(:pearcmd), "remote-info", @resource[:name]]
103+
list = execute(command).collect do |set|
104+
if set =~ /^Latest/
105+
version = set.split[1]
106+
end
107+
end
108+
return version
109+
end
110+
111+
def query
112+
self.class.pearlist(:justme => @resource[:name])
113+
end
114+
115+
def uninstall
116+
output = pearcmd "uninstall", @resource[:name]
117+
if output =~ /^uninstall ok/
118+
else
119+
raise Puppet::Error, output
120+
end
121+
end
122+
123+
def update
124+
self.install(false)
125+
end
126+
end

manifests/init.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
# You should have received a copy of the GNU Affero General Public License
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818

19+
# Uses pear provider from http://projects.reductivelabs.com/issues/1823
20+
# http://www.mit.edu/~marthag/puppet/pear.rb
1921
class pear {
2022
# TODO:
21-
# - http://www.mit.edu/~marthag/puppet/pear.rb
2223
# - pecl install uploadprogress
2324
# - file /etc/php5/apache2/conf.d/uploadprogress.ini with content
2425
# extension=uploadprogress.so

0 commit comments

Comments
 (0)