blob: cf2c87bfe578d8c1f06d67b34962d63e50dbb75b (
plain)
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
|
# Packaging using Blastwave's pkg-get program.
Puppet::Type.type(:package).provide :blastwave, :parent => :sun, :source => :sun do
desc "Package management using Blastwave.org's ``pkg-get`` command on Solaris."
pkgget = "pkg-get"
if FileTest.executable?("/opt/csw/bin/pkg-get")
pkgget = "/opt/csw/bin/pkg-get"
end
confine :operatingsystem => :solaris
commands :pkgget => pkgget
def pkgget_with_cat(*args)
withenv(:PAGER => "/usr/bin/cat") { pkgget(*args) }
end
def self.extended(mod)
unless command(:pkgget) != "pkg-get"
raise Puppet::Error,
"The pkg-get command is missing; blastwave packaging unavailable"
end
unless FileTest.exists?("/var/pkg-get/admin")
Puppet.notice "It is highly recommended you create '/var/pkg-get/admin'."
Puppet.notice "See /var/pkg-get/admin-fullauto"
end
end
def self.instances(hash = {})
blastlist(hash).collect do |bhash|
bhash.delete(:avail)
new(bhash)
end
end
# Turn our blastwave listing into a bunch of hashes.
def self.blastlist(hash)
command = ["-c"]
if hash[:justme]
command << hash[:justme]
end
output = pkgget_with_cat command
list = output.split("\n").collect do |line|
next if line =~ /^#/
next if line =~ /^WARNING/
next if line =~ /localrev\s+remoterev/
blastsplit(line)
end.reject { |h| h.nil? }
if hash[:justme]
return list[0]
else
list.reject! { |h|
h[:ensure] == :absent
}
return list
end
end
# Split the different lines into hashes.
def self.blastsplit(line)
if line =~ /\s*(\S+)\s+((\[Not installed\])|(\S+))\s+(\S+)/
hash = {}
hash[:name] = $1
hash[:ensure] = if $2 == "[Not installed]"
:absent
else
$2
end
hash[:avail] = $5
if hash[:avail] == "SAME"
hash[:avail] = hash[:ensure]
end
# Use the name method, so it works with subclasses.
hash[:provider] = self.name
return hash
else
Puppet.warning "Cannot match %s" % line
return nil
end
end
def install
pkgget_with_cat "-f", :install, @resource[:name]
end
# Retrieve the version from the current package file.
def latest
hash = self.class.blastlist(:justme => @resource[:name])
hash[:avail]
end
def query
if hash = self.class.blastlist(:justme => @resource[:name])
hash
else
{:ensure => :absent}
end
end
# Remove the old package, and install the new one
def update
pkgget_with_cat "-f", :upgrade, @resource[:name]
end
def uninstall
pkgget_with_cat "-f", :remove, @resource[:name]
end
end
|