4 views
Skip to first unread message

Juerg Walz

unread,
Mar 10, 2011, 2:48:30 AM3/10/11
to puppe...@googlegroups.com
2nd update to pkgutil changes (aka v3): Bug-fix to handle OpenCSW packages where the package "shortname" is not equal to the Solaris package name (eg. "screen" -> Solaris pkg CSWscrn).

--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -80,8 +80,8 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d
end
hash[:avail] = $3

- if justme !~ /^[A-Z]+/
- hash[:name].sub! /^[A-Z]+/, ''
+ if justme
+ hash[:name] = justme
end

if hash[:avail] =~ /^SAME\s*$/

Juerg Walz

unread,
Mar 10, 2011, 2:48:33 AM3/10/11
to puppe...@googlegroups.com, Maciej Blizinski
From: Maciej Blizinski <mac...@opencsw.org>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev
lib/puppet/provider/package/pkgutil.rb | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index cde7482..c2489cc 100755
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -1,4 +1,5 @@
# Packaging using pkgutil from http://pkgutil.wikidot.com/
+# vim:set sw=4 ts=4 sts=4:
Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun do
desc "Package management using ``pkgutil`` command on Solaris."
pkgutil = "pkgutil"
@@ -20,6 +21,7 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d
end
end

+ # It's a class method. Returns a list of instances of this class.
def self.instances(hash = {})
blastlist(hash).collect do |bhash|
bhash.delete(:avail)
@@ -32,6 +34,7 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d
command = ["-c"]

if hash[:justme]
+ command << ["--single"]
command << hash[:justme]
end

@@ -86,7 +89,7 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d
pkgutil "-y", "--install", @resource[:name]
end

- # Retrieve the version from the current package file.
+ # What's the latest version of the package available?
def latest
hash = self.class.blastlist(:justme => @resource[:name])
hash[:avail]
--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:38 AM3/10/11
to puppe...@googlegroups.com, Dominic Cleal
From: Dominic Cleal <dcl...@redhat.com>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev

lib/puppet/provider/package/pkgutil.rb | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index 05d189d..a5f852d 100755
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -50,6 +50,10 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d
next if line =~ /^WARNING/
next if line =~ /localrev\s+remoterev/
next if line =~ /installed\s+catalog/
+ next if line =~ /^Checking integrity / # use_gpg
+ next if line =~ /^gpg: / # gpg verification
+ next if line =~ /^=+> / # catalog fetch
+ next if line =~ /^\d+:\d+:\d+ URL:/ # wget without -q

blastsplit(line)
end.reject { |h| h.nil? }
@@ -118,3 +122,4 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d
pkguti "-y", "-r", @resource[:name]
end
end
+
--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:39 AM3/10/11
to puppe...@googlegroups.com, rgevaert
From: rgevaert <rudy.geva...@ugent.be>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev

lib/puppet/provider/package/pkgutil.rb | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index a5f852d..1d699f3 100755
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -47,9 +47,9 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d

list = output.split("\n").collect do |line|
next if line =~ /^#/
- next if line =~ /^WARNING/
- next if line =~ /localrev\s+remoterev/
- next if line =~ /installed\s+catalog/
+ #next if line =~ /^WARNING/
+ #next if line =~ /localrev\s+remoterev/
+ next if line =~ /installed\s+catalog/ # header of package list


next if line =~ /^Checking integrity / # use_gpg

next if line =~ /^gpg: / # gpg verification

next if line =~ /^=+> / # catalog fetch

--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:34 AM3/10/11
to puppe...@googlegroups.com, Maciej Blizinski
From: Maciej Blizinski <mac...@opencsw.org>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev

lib/puppet/provider/package/pkgutil.rb | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index 39c2302..ec48c94 100644
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -1,6 +1,6 @@
# Packaging using Peter Bonivart's pkgutil program.
Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun do
- desc "Package management using Peter Bonivartg's ``pkgutil`` command on Solaris."
+ desc "Package management using Peter Bonivart's ``pkgutil`` command on Solaris."
pkguti = "pkgutil"
if FileTest.executable?("/opt/csw/bin/pkgutil")
pkguti = "/opt/csw/bin/pkgutil"
--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:41 AM3/10/11
to puppe...@googlegroups.com, Dominic Cleal
From: Dominic Cleal <dcl...@redhat.com>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev
lib/puppet/provider/package/pkgutil.rb | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index 19a62dc..4914aa4 100755
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -51,7 +51,7 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d


next if line =~ /^Checking integrity / # use_gpg
next if line =~ /^gpg: / # gpg verification
next if line =~ /^=+> / # catalog fetch

- next if line =~ /^\d+:\d+:\d+ URL:/ # wget without -q
+ next if line =~ /\d+:\d+:\d+ URL:/ # wget without -q

blastsplit(line)
end.reject { |h| h.nil? }
--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:47 AM3/10/11
to puppe...@googlegroups.com, Dominic Cleal
From: Dominic Cleal <dcl...@redhat.com>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev

spec/unit/provider/package/pkgutil_spec.rb | 132 ++++++++++++++++++++++++++++
1 files changed, 132 insertions(+), 0 deletions(-)
create mode 100755 spec/unit/provider/package/pkgutil_spec.rb

diff --git a/spec/unit/provider/package/pkgutil_spec.rb b/spec/unit/provider/package/pkgutil_spec.rb
new file mode 100755
index 0000000..10cebfe
--- /dev/null
+++ b/spec/unit/provider/package/pkgutil_spec.rb
@@ -0,0 +1,132 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+provider = Puppet::Type.type(:package).provider(:pkgutil)
+
+describe provider do
+ before(:each) do
+ @resource = stub 'resource'
+ @resource = Puppet::Type.type(:package).new(:name => "TESTpkg", :ensure => :present)
+ @provider = provider.new(@resource)
+ end
+
+ it "should have an install method" do
+ @provider.should respond_to(:install)
+ end
+
+ it "should have a latest method" do
+ @provider.should respond_to(:uninstall)
+ end
+
+ it "should have an update method" do
+ @provider.should respond_to(:update)
+ end
+
+ it "should have a latest method" do
+ @provider.should respond_to(:latest)
+ end
+
+ describe "when installing" do
+ it "should use a command without versioned package" do
+ @resource[:ensure] = :latest
+ @provider.expects(:pkguti).with('-y', '-i', 'TESTpkg')
+ @provider.install
+ end
+ end
+
+ describe "when updating" do
+ it "should use a command without versioned package" do
+ @provider.expects(:pkguti).with('-y', '-i', 'TESTpkg')
+ @provider.update
+ end
+ end
+
+ describe "when uninstalling" do
+ it "should call the remove operation" do
+ @provider.expects(:pkguti).with('-y', '-r', 'TESTpkg')
+ @provider.uninstall
+ end
+ end
+
+ describe "when getting latest version" do
+ it "should return TESTpkg's version string" do
+ fake_data = "
+CSWsvn 1.4.5,REV=2007.11.18 SAME
+TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20
+CSWemacs notinst 22.1"
+ provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data
+ @provider.latest.should == "1.4.5,REV=2007.11.20"
+ end
+
+ it "should handle TESTpkg's 'SAME' version string" do
+ fake_data = "
+CSWsvn 1.4.5,REV=2007.11.18 SAME
+TESTpkg 1.4.5,REV=2007.11.18 SAME
+CSWemacs notinst 22.1"
+ provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data
+ @provider.latest.should == "1.4.5,REV=2007.11.18"
+ end
+
+ it "should handle a non-existent package" do
+ fake_data = "CSWsvn 1.4.5,REV=2007.11.18 SAME"
+ provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data
+ @provider.latest.should == nil
+ end
+
+ it "should warn on unknown pkgutil noise" do
+ provider.expects(:pkguti).returns("testingnoise")
+ Puppet.expects(:warning)
+ provider.expects(:new).never
+ provider.instances.should == []
+ end
+
+ it "should ignore pkgutil noise/headers to find TESTpkg" do
+ fake_data = "# stuff
+=> Fetching new catalog and descriptions (http://mirror.opencsw.org/opencsw/unstable/i386/5.11) if available ...
+2011-02-19 23:05:46 URL:http://mirror.opencsw.org/opencsw/unstable/i386/5.11/catalog [534635/534635] -> \"/var/opt/csw/pkgutil/catalog.mirror.opencsw.org_opencsw_unstable_i386_5.11.tmp\" [1]
+Checking integrity of /var/opt/csw/pkgutil/catalog.mirror.opencsw.org_opencsw_unstable_i386_5.11 with gpg.
+gpg: Signature made February 17, 2011 05:27:53 PM GMT using DSA key ID E12E9D2F
+gpg: Good signature from \"Distribution Manager <d...@blastwave.org>\"
+==> 2770 packages loaded from /var/opt/csw/pkgutil/catalog.mirror.opencsw.org_opencsw_unstable_i386_5.11
+package installed catalog
+TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20
+testingnoise
+testing noise again"
+ provider.expects(:pkguti).returns fake_data
+ @provider.latest.should == "1.4.5,REV=2007.11.20"
+ end
+ end
+
+ describe "when querying current version" do
+ it "should return TESTpkg's version string" do
+ fake_data = "TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20"
+ provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data
+ @provider.query[:ensure].should == "1.4.5,REV=2007.11.18"
+ end
+
+ it "should handle a package that isn't installed" do
+ fake_data = "TESTpkg notinst 1.4.5,REV=2007.11.20"
+ provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data
+ @provider.query[:ensure].should == :absent
+ end
+
+ it "should handle a non-existent package" do
+ fake_data = "CSWsvn 1.4.5,REV=2007.11.18 SAME"
+ provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data
+ @provider.query[:ensure].should == :absent
+ end
+ end
+
+ describe "when querying current instances" do
+ it "should return TESTpkg's version string" do
+ fake_data = "TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20"
+ provider.expects(:pkguti).with(['-c']).returns fake_data
+
+ testpkg = mock 'pkg1'
+ provider.expects(:new).with(:ensure => "1.4.5,REV=2007.11.18", :name => "TESTpkg", :provider => :pkgutil).returns testpkg
+ provider.instances.should == [testpkg]
+ end
+ end
+
+end
--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:50 AM3/10/11
to puppe...@googlegroups.com

Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev
lib/puppet/provider/package/pkgutil.rb | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index 4a87932..3a23796 100755


--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -80,8 +80,8 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d
end
hash[:avail] = $3

- if justme !~ /^[A-Z]+/
- hash[:name].sub! /^[A-Z]+/, ''
+ if justme
+ hash[:name] = justme
end

if hash[:avail] =~ /^SAME\s*$/

--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:40 AM3/10/11
to puppe...@googlegroups.com, rgevaert
From: rgevaert <rudy+...@webworm.org>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev

lib/puppet/provider/package/pkgutil.rb | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index 1d699f3..19a62dc 100755
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -47,8 +47,6 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d



list = output.split("\n").collect do |line|
next if line =~ /^#/

- #next if line =~ /^WARNING/
- #next if line =~ /localrev\s+remoterev/


next if line =~ /installed\s+catalog/ # header of package list

next if line =~ /^Checking integrity / # use_gpg
next if line =~ /^gpg: / # gpg verification

--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:48 AM3/10/11
to puppe...@googlegroups.com
Several enhancements and bug-fixes for the pkgutil package
provider:

- handle "Not in catalog"
- fix "SAME" version detection
- allow short package name (w/o CSW) to match
(-> no need to specify a different package name for different
operating systems, ex. "ruby")
- use the "-u" command line switch for updates

Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev

lib/puppet/provider/package/pkgutil.rb | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index f0900dc..0e2056b 100755
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -51,12 +51,12 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d


next if line =~ /^=+> / # catalog fetch

next if line =~ /\d+:\d+:\d+ URL:/ # wget without -q

- pkgsplit(line)
+ pkgsplit(line, hash[:justme])
end.reject { |h| h.nil? }

if hash[:justme]
# Ensure we picked up the package line, not any pkgutil noise.
- list.reject! { |h| h[:name] != hash[:justme] }
+ list.reject! { |h| h[:name] !~ /#{hash[:justme]}$/ }
return list[-1]
else
list.reject! { |h| h[:ensure] == :absent }
@@ -66,8 +66,11 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d
end

# Split the different lines into hashes.
- def self.pkgsplit(line)
- if line =~ /\s*(\S+)\s+(\S+)\s+(.*)/
+ def self.pkgsplit(line, justme)
+ if line == "Not in catalog"
+ Puppet.warning "Package not in pkgutil catalog: %s" % justme
+ return nil
+ elsif line =~ /\s*(\S+)\s+(\S+)\s+(.*)/
hash = {}
hash[:name] = $1
hash[:ensure] = if $2 == "notinst"
@@ -77,7 +80,7 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d


end
hash[:avail] = $3

- if hash[:avail] == "SAME"
+ if hash[:avail] =~ /^SAME\s*$/
hash[:avail] = hash[:ensure]
end

@@ -110,7 +113,7 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d
end

def update
- pkguti "-y", "-i", @resource[:name]
+ pkguti "-y", "-u", @resource[:name]
end

def uninstall
--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:31 AM3/10/11
to puppe...@googlegroups.com, James Turnbull
From: James Turnbull <ja...@lovedthanlost.net>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev

lib/puppet/provider/package/pkgutil.rb | 117 ++++++++++++++++++++++++++++++++
1 files changed, 117 insertions(+), 0 deletions(-)
create mode 100644 lib/puppet/provider/package/pkgutil.rb

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
new file mode 100644
index 0000000..39c2302
--- /dev/null
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -0,0 +1,117 @@
+# Packaging using Peter Bonivart's pkgutil program.
+Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun do
+ desc "Package management using Peter Bonivartg's ``pkgutil`` command on Solaris."
+ pkguti = "pkgutil"
+ if FileTest.executable?("/opt/csw/bin/pkgutil")
+ pkguti = "/opt/csw/bin/pkgutil"
+ end
+
+ confine :operatingsystem => :solaris
+
+ commands :pkguti => pkguti
+
+ # This is so stupid, but then, so is blastwave.
+ ENV["PAGER"] = "/usr/bin/cat"
+
+ def self.extended(mod)
+ unless command(:pkguti) != "pkgutil"
+ raise Puppet::Error,
+ "The pkgutil command is missing; pkgutil 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 = pkguti command
+
+ list = output.split("\n").collect do |line|
+ next if line =~ /^#/
+ next if line =~ /^WARNING/
+ next if line =~ /localrev\s+remoterev/
+ next if line =~ /installed\s+catalog/
+
+ 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
+ pkguti "-y", "-i", @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
+ pkguti "-y", "-i", @resource[:name]
+ end
+
+ def uninstall
+ pkguti "-y", "-r", @resource[:name]
+ end
+end
--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:32 AM3/10/11
to puppe...@googlegroups.com, Maciej Blizinski
From: Maciej Blizinski <mac...@opencsw.org>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev

lib/puppet/provider/package/pkgutil.rb | 111 ++++++++++++++++++++++++++++++++
1 files changed, 111 insertions(+), 0 deletions(-)
create mode 100755 lib/puppet/provider/package/pkgutil.rb

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
new file mode 100755
index 0000000..cde7482
--- /dev/null
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -0,0 +1,111 @@
+# Packaging using pkgutil from http://pkgutil.wikidot.com/


+Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun do

+ desc "Package management using ``pkgutil`` command on Solaris."
+ pkgutil = "pkgutil"


+ if FileTest.executable?("/opt/csw/bin/pkgutil")

+ pkgutil = "/opt/csw/bin/pkgutil"


+ end
+
+ confine :operatingsystem => :solaris
+

+ commands :pkgutil => pkgutil
+
+ # This is so stupid, but then, so is Solaris.


+ ENV["PAGER"] = "/usr/bin/cat"
+
+ def self.extended(mod)

+ unless command(:pkgutil) != "pkgutil"


+ raise Puppet::Error,
+ "The pkgutil command is missing; pkgutil packaging unavailable"
+ end

+ end
+
+ def self.instances(hash = {})
+ blastlist(hash).collect do |bhash|
+ bhash.delete(:avail)
+ new(bhash)
+ end
+ end
+

+ # Turn our pkgutil listing into a bunch of hashes.


+ def self.blastlist(hash)
+ command = ["-c"]
+
+ if hash[:justme]
+ command << hash[:justme]
+ end
+

+ output = pkgutil command


+
+ list = output.split("\n").collect do |line|
+ next if line =~ /^#/
+ next if line =~ /^WARNING/
+ next if line =~ /localrev\s+remoterev/
+

+ pkgutil "-y", "--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

+ pkgutil "-y", "--upgrade", @resource[:name]


+ end
+
+ def uninstall

+ pkgutil "-y", "--remove", @resource[:name]

Juerg Walz

unread,
Mar 10, 2011, 2:48:37 AM3/10/11
to puppe...@googlegroups.com, Dominic Cleal
From: Dominic Cleal <dcl...@redhat.com>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev

lib/puppet/provider/package/pkgutil.rb | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index b8ad548..05d189d 100755
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -67,15 +67,15 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d



# Split the different lines into hashes.

def self.blastsplit(line)
- if line =~ /\s*(\S+)\s+((\[Not installed\])|(\S+))\s+(\S+)/
+ if line =~ /\s*(\S+)\s+(\S+)\s+(.*)/


hash = {}
hash[:name] = $1

- hash[:ensure] = if $2 == "[Not installed]"
+ hash[:ensure] = if $2 == "notinst"
:absent
else
$2
end
- hash[:avail] = $5
+ hash[:avail] = $3



if hash[:avail] == "SAME"

hash[:avail] = hash[:ensure]

--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:42 AM3/10/11
to puppe...@googlegroups.com, Dominic Cleal
From: Dominic Cleal <dcl...@redhat.com>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev

lib/puppet/provider/package/pkgutil.rb | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index 4914aa4..b80cf74 100755
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -53,11 +53,17 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d


next if line =~ /^=+> / # catalog fetch
next if line =~ /\d+:\d+:\d+ URL:/ # wget without -q

- blastsplit(line)
+ parsed = blastsplit(line)
+
+ # When finding one package, ensure we picked up the package line
+ # itself, not any pkgutil noise.
+ next if hash[:justme] and parsed[:name] != hash[:justme]
+
+ parsed


end.reject { |h| h.nil? }

if hash[:justme]

- return list[0]
+ return list[-1]


else
list.reject! { |h|
h[:ensure] == :absent

--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:43 AM3/10/11
to puppe...@googlegroups.com, Dominic Cleal
From: Dominic Cleal <dcl...@redhat.com>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev

lib/puppet/provider/package/pkgutil.rb | 212 ++++++++++++++++----------------
1 files changed, 106 insertions(+), 106 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index b80cf74..4e2c0d9 100755
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -1,129 +1,129 @@


# Packaging using Peter Bonivart's pkgutil program.

Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun do
- desc "Package management using Peter Bonivart's ``pkgutil`` command on Solaris."
- pkguti = "pkgutil"
- if FileTest.executable?("/opt/csw/bin/pkgutil")
- pkguti = "/opt/csw/bin/pkgutil"
- end
+ desc "Package management using Peter Bonivart's ``pkgutil`` command on Solaris."
+ pkguti = "pkgutil"


+ if FileTest.executable?("/opt/csw/bin/pkgutil")

+ pkguti = "/opt/csw/bin/pkgutil"
+ end

- confine :operatingsystem => :solaris
+ confine :operatingsystem => :solaris

- commands :pkguti => pkguti
+ commands :pkguti => pkguti

- # This is so stupid, but then, so is blastwave.
- ENV["PAGER"] = "/usr/bin/cat"
+ # This is so stupid, but then, so is blastwave.


+ ENV["PAGER"] = "/usr/bin/cat"

- def self.extended(mod)
- unless command(:pkguti) != "pkgutil"
- raise Puppet::Error,
- "The pkgutil command is missing; pkgutil packaging unavailable"
- end
+ def self.extended(mod)
+ unless command(:pkguti) != "pkgutil"


+ raise Puppet::Error,
+ "The pkgutil command is missing; pkgutil packaging unavailable"
+ end

- unless FileTest.exists?("/var/opt/csw/pkgutil/admin")
- Puppet.notice "It is highly recommended you create '/var/opt/csw/pkgutil/admin'."
- Puppet.notice "See /var/opt/csw/pkgutil"
- end
+ unless FileTest.exists?("/var/opt/csw/pkgutil/admin")
+ Puppet.notice "It is highly recommended you create '/var/opt/csw/pkgutil/admin'."
+ Puppet.notice "See /var/opt/csw/pkgutil"
end
+ end

- def self.instances(hash = {})
- blastlist(hash).collect do |bhash|
- bhash.delete(:avail)
- new(bhash)
- 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]
- # The --single option speeds up the execution, because it queries
- # the package managament system for one package only.
- command << ["--single"]
- command << hash[:justme]
- end
-
- output = pkguti command
-
- list = output.split("\n").collect do |line|
- next if line =~ /^#/
- next if line =~ /installed\s+catalog/ # header of package list
- next if line =~ /^Checking integrity / # use_gpg
- next if line =~ /^gpg: / # gpg verification
- next if line =~ /^=+> / # catalog fetch
- next if line =~ /\d+:\d+:\d+ URL:/ # wget without -q
-
- parsed = blastsplit(line)
-
- # When finding one package, ensure we picked up the package line
- # itself, not any pkgutil noise.
- next if hash[:justme] and parsed[:name] != hash[:justme]
-
- parsed
- end.reject { |h| h.nil? }
-
- if hash[:justme]
- return list[-1]
- else
- list.reject! { |h|
- h[:ensure] == :absent
- }
- return list
- end
+ # Turn our blastwave listing into a bunch of hashes.


+ def self.blastlist(hash)
+ command = ["-c"]

+ if hash[:justme]
+ # The --single option speeds up the execution, because it queries
+ # the package managament system for one package only.
+ command << ["--single"]
+ command << hash[:justme]
end

- # Split the different lines into hashes.
- def self.blastsplit(line)
- if line =~ /\s*(\S+)\s+(\S+)\s+(.*)/
- hash = {}
- hash[:name] = $1
- hash[:ensure] = if $2 == "notinst"
- :absent
- else
- $2
- end
- hash[:avail] = $3
-
- 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


+ output = pkguti command

- def install
- pkguti "-y", "-i", @resource[:name]
- end


+ list = output.split("\n").collect do |line|
+ next if line =~ /^#/

+ next if line =~ /installed\s+catalog/ # header of package list
+ next if line =~ /^Checking integrity / # use_gpg
+ next if line =~ /^gpg: / # gpg verification
+ next if line =~ /^=+> / # catalog fetch
+ next if line =~ /\d+:\d+:\d+ URL:/ # wget without -q

- # Retrieve the version from the current package file.
- def latest
- hash = self.class.blastlist(:justme => @resource[:name])
- hash[:avail]
- end
+ parsed = blastsplit(line)

- def query
- if hash = self.class.blastlist(:justme => @resource[:name])
- hash
- else
- {:ensure => :absent}
- end
- end


+ # When finding one package, ensure we picked up the package line
+ # itself, not any pkgutil noise.
+ next if hash[:justme] and parsed[:name] != hash[:justme]
+
+ parsed

+ end.reject { |h| h.nil? }

- # Remove the old package, and install the new one
- def update
- pkguti "-y", "-i", @resource[:name]
+ if hash[:justme]
+ return list[-1]


+ else
+ list.reject! { |h|
+ h[:ensure] == :absent
+ }
+ return list

end

- def uninstall
- pkguti "-y", "-r", @resource[:name]
+ end
+
+ # Split the different lines into hashes.
+ def self.blastsplit(line)


+ if line =~ /\s*(\S+)\s+(\S+)\s+(.*)/

+ hash = {}
+ hash[:name] = $1

+ hash[:ensure] = if $2 == "notinst"

+ :absent
+ else
+ $2
+ end

+ hash[:avail] = $3

+
+ 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

+ pkguti "-y", "-i", @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

+ pkguti "-y", "-i", @resource[:name]


+ end
+
+ def uninstall

+ pkguti "-y", "-r", @resource[:name]
+ end
end

--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:49 AM3/10/11
to puppe...@googlegroups.com

Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev
lib/puppet/provider/package/pkgutil.rb | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index 0e2056b..4a87932 100755
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -56,7 +56,7 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d

if hash[:justme]
# Ensure we picked up the package line, not any pkgutil noise.
- list.reject! { |h| h[:name] !~ /#{hash[:justme]}$/ }
+ list.reject! { |h| h[:name] != hash[:justme] }


return list[-1]
else
list.reject! { |h| h[:ensure] == :absent }

@@ -80,6 +80,10 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d


end
hash[:avail] = $3

+ if justme !~ /^[A-Z]+/
+ hash[:name].sub! /^[A-Z]+/, ''
+ end
+


if hash[:avail] =~ /^SAME\s*$/

hash[:avail] = hash[:ensure]

end
--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:36 AM3/10/11
to puppe...@googlegroups.com, Maciej Blizinski
From: Maciej Blizinski <mac...@opencsw.org>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev

lib/puppet/provider/package/pkgutil.rb | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index 4f6b5c2..b8ad548 100644
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -37,6 +37,9 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d
command = ["-c"]



if hash[:justme]
+ # The --single option speeds up the execution, because it queries
+ # the package managament system for one package only.
+ command << ["--single"]

command << hash[:justme]
end

--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:45 AM3/10/11
to puppe...@googlegroups.com, Dominic Cleal
From: Dominic Cleal <dcl...@redhat.com>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev

lib/puppet/provider/package/pkgutil.rb | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index b9d0ea4..dacd70a 100755
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -47,9 +47,9 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d


next if line =~ /^#/

next if line =~ /installed\s+catalog/ # header of package list

next if line =~ /^Checking integrity / # use_gpg
- next if line =~ /^gpg: / # gpg verification
- next if line =~ /^=+> / # catalog fetch
- next if line =~ /\d+:\d+:\d+ URL:/ # wget without -q

+ next if line =~ /^gpg: / # gpg verification
+ next if line =~ /^=+> / # catalog fetch
+ next if line =~ /\d+:\d+:\d+ URL:/ # wget without -q

parsed = pkgsplit(line)

--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:35 AM3/10/11
to puppe...@googlegroups.com, Maciej Blizinski
From: Maciej Blizinski <mac...@opencsw.org>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev
lib/puppet/provider/package/pkgutil.rb | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index ec48c94..4f6b5c2 100644
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -19,9 +19,9 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d


"The pkgutil command is missing; pkgutil 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"


+ unless FileTest.exists?("/var/opt/csw/pkgutil/admin")
+ Puppet.notice "It is highly recommended you create '/var/opt/csw/pkgutil/admin'."
+ Puppet.notice "See /var/opt/csw/pkgutil"
end

end

--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:46 AM3/10/11
to puppe...@googlegroups.com, Dominic Cleal
From: Dominic Cleal <dcl...@redhat.com>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev

lib/puppet/provider/package/pkgutil.rb | 19 ++++++-------------
1 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index dacd70a..f0900dc 100755
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -37,7 +37,7 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d
if hash[:justme]


# The --single option speeds up the execution, because it queries

# the package managament system for one package only.

- command << ["--single"]


+ command << "--single"
command << hash[:justme]
end

@@ -51,21 +51,15 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d


next if line =~ /^=+> / # catalog fetch

next if line =~ /\d+:\d+:\d+ URL:/ # wget without -q

- parsed = pkgsplit(line)


-
- # When finding one package, ensure we picked up the package line
- # itself, not any pkgutil noise.
- next if hash[:justme] and parsed[:name] != hash[:justme]
-
- parsed

+ pkgsplit(line)
end.reject { |h| h.nil? }

if hash[:justme]
+ # Ensure we picked up the package line, not any pkgutil noise.


+ list.reject! { |h| h[:name] != hash[:justme] }
return list[-1]
else

- list.reject! { |h|
- h[:ensure] == :absent
- }

+ list.reject! { |h| h[:ensure] == :absent }
return list
end

@@ -104,7 +98,7 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d


# Retrieve the version from the current package file.

def latest
hash = self.class.pkglist(:justme => @resource[:name])
- hash[:avail]
+ hash[:avail] if hash
end

def query
@@ -115,7 +109,6 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d
end
end



- # Remove the old package, and install the new one

def update


pkguti "-y", "-i", @resource[:name]

end
--
1.7.3.2

Juerg Walz

unread,
Mar 10, 2011, 2:48:44 AM3/10/11
to puppe...@googlegroups.com, Dominic Cleal
From: Dominic Cleal <dcl...@redhat.com>


Signed-off-by: Juerg Walz <jw...@pobox.com>
---
Local-branch: tickets/master/4258-dev

lib/puppet/provider/package/pkgutil.rb | 18 ++++++++----------
1 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
index 4e2c0d9..b9d0ea4 100755
--- a/lib/puppet/provider/package/pkgutil.rb
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -10,9 +10,6 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d



commands :pkguti => pkguti

- # This is so stupid, but then, so is blastwave.
- ENV["PAGER"] = "/usr/bin/cat"

-
def self.extended(mod)


unless command(:pkguti) != "pkgutil"

raise Puppet::Error,
@@ -26,14 +23,15 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d
end


def self.instances(hash = {})
- blastlist(hash).collect do |bhash|

+ pkglist(hash).collect do |bhash|
bhash.delete(:avail)
new(bhash)
end


end

- # Turn our blastwave listing into a bunch of hashes.
- def self.blastlist(hash)

+ # Turn our pkgutil -c listing into a bunch of hashes.
+ # Supports :justme => packagename, which uses the optimised --single arg
+ def self.pkglist(hash)


command = ["-c"]

if hash[:justme]

@@ -53,7 +51,7 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d


next if line =~ /^=+> / # catalog fetch
next if line =~ /\d+:\d+:\d+ URL:/ # wget without -q

- parsed = blastsplit(line)
+ parsed = pkgsplit(line)



# When finding one package, ensure we picked up the package line

# itself, not any pkgutil noise.

@@ -74,7 +72,7 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d
end


# Split the different lines into hashes.
- def self.blastsplit(line)

+ def self.pkgsplit(line)


if line =~ /\s*(\S+)\s+(\S+)\s+(.*)/

hash = {}
hash[:name] = $1

@@ -105,12 +103,12 @@ Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun d



# Retrieve the version from the current package file.
def latest

- hash = self.class.blastlist(:justme => @resource[:name])
+ hash = self.class.pkglist(:justme => @resource[:name])
hash[:avail]
end

def query
- if hash = self.class.blastlist(:justme => @resource[:name])
+ if hash = self.class.pkglist(:justme => @resource[:name])
hash
else
{:ensure => :absent}
--
1.7.3.2

Ben Hughes

unread,
Mar 15, 2011, 3:03:47 AM3/15/11
to puppe...@googlegroups.com
Going to try to add some unit tests to this if I can. Can people with Macs
have a test too please? Thanks.

Reply all
Reply to author
Forward
0 new messages