diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-07-04 05:45:28 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-07-04 05:45:28 +0000 |
commit | 87ce8ed7b672b574b4bd2870a42b6c186182c5a7 (patch) | |
tree | 6fa6028f61fb5746f45b8786a566441e6a81da05 /lib | |
parent | 2e78526b6bf646584feb19adb95a4f5fdd8f8b7a (diff) | |
download | puppet-87ce8ed7b672b574b4bd2870a42b6c186182c5a7.tar.gz puppet-87ce8ed7b672b574b4bd2870a42b6c186182c5a7.tar.xz puppet-87ce8ed7b672b574b4bd2870a42b6c186182c5a7.zip |
Adding blastwave packaging, and doing some fixes on gem and sun packaging
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1356 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/puppet/type/package/blastwave.rb | 136 | ||||
-rwxr-xr-x | lib/puppet/type/package/gem.rb | 6 | ||||
-rwxr-xr-x | lib/puppet/type/package/sun.rb | 44 |
3 files changed, 163 insertions, 23 deletions
diff --git a/lib/puppet/type/package/blastwave.rb b/lib/puppet/type/package/blastwave.rb new file mode 100755 index 000000000..6698a4029 --- /dev/null +++ b/lib/puppet/type/package/blastwave.rb @@ -0,0 +1,136 @@ +module Puppet + Puppet.type(:package).newpkgtype(:blastwave, :sun) do + if pkgget = %x{which pkg-get 2>/dev/null}.chomp and pkgget != "" + @@pkgget = pkgget + else + @@pkgget = nil + end + + # This is so stupid + ENV["PAGER"] = "/usr/bin/cat" + + def self.extended(mod) + unless @@pkgget + 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 + + # Turn our blastwave listing into a bunch of hashes. + def blastlist(hash) + command = "#{@@pkgget} -c" + + if hash[:justme] + command += " " + self[:name] + end + + begin + output = execute(command) + rescue ExecutionError => detail + raise Puppet::Error, "Could not get package listing: %s" % + detail + end + + 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 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 + hash[:type] = :blastwave + + return hash + else + Puppet.warning "Cannot match %s" % line + return nil + end + end + + module_function :blastlist, :blastsplit + + def install + begin + execute("#{@@pkgget} -f install #{self[:name]}") + rescue ExecutionFailure => detail + raise Puppet::Error, + "Could not install %s: %s" % + [self[:name], detail] + end + end + + # Retrieve the version from the current package file. + def latest + hash = blastlist(:justme => true) + hash[:avail] + end + + def list(hash = {}) + blastlist(hash).each do |bhash| + bhash.delete(:avail) + Puppet::Type.type(:package).installedpkg(bhash) + end + end + + def query + hash = blastlist(:justme => true) + + {:ensure => hash[:ensure]} + end + + # Remove the old package, and install the new one + def update + begin + execute("#{@@pkgget} -f upgrade #{self[:name]}") + rescue ExecutionFailure => detail + raise Puppet::Error, + "Could not upgrade %s: %s" % + [self[:name], detail] + end + end + + def uninstall + begin + execute("#{@@pkgget} -f remove #{self[:name]}") + rescue ExecutionFailure => detail + raise Puppet::Error, + "Could not remove %s: %s" % + [self[:name], detail] + end + end + end +end + +# $Id$ diff --git a/lib/puppet/type/package/gem.rb b/lib/puppet/type/package/gem.rb index 3763cf992..a5d111c1e 100755 --- a/lib/puppet/type/package/gem.rb +++ b/lib/puppet/type/package/gem.rb @@ -5,10 +5,10 @@ module Puppet else @@gem = nil end - def self.extended(mod) - unless @@gem - raise Puppet::Error, "The gem command is missing; gems unavailable" + unless @@pkgget + raise Puppet::Error, + "The gem command is missing; gems unavailable" end end diff --git a/lib/puppet/type/package/sun.rb b/lib/puppet/type/package/sun.rb index c0c34a19d..1b419f4b9 100755 --- a/lib/puppet/type/package/sun.rb +++ b/lib/puppet/type/package/sun.rb @@ -7,7 +7,7 @@ module Puppet "NAME" => nil, "CATEGORY" => :category, "ARCH" => :platform, - "VERSION" => :version, + "VERSION" => :ensure, "BASEDIR" => :root, "HOTLINE" => nil, "EMAIL" => nil, @@ -62,13 +62,13 @@ module Puppet raise Puppet::Error, "Sun packages must specify a package source" end cmd = ["pkgadd"] - + if self[:adminfile] - cmd += ["-a", self[:adminfile]] + cmd << " -a " + self[:adminfile] end if self[:responsefile] - cmd += ["-r", self[:responsefile]] + cmd << " -r " + self[:responsefile] end cmd += ["-d", self[:source]] @@ -76,7 +76,7 @@ module Puppet cmd << "2>&1" cmd = cmd.join(" ") - self.info "Executing %s" % cmd.inspect + self.debug "Executing %s" % cmd.inspect output = %x{#{cmd} 2>&1} unless $? == 0 @@ -98,7 +98,7 @@ module Puppet "NAME" => nil, "CATEGORY" => :category, "ARCH" => :platform, - "VERSION" => :version, + "VERSION" => :ensure, "BASEDIR" => :root, "HOTLINE" => nil, "EMAIL" => nil, @@ -117,15 +117,7 @@ module Puppet process.each { |line| case line when /^$/: - if self.is_a? Puppet::Type and type = self[:type] - hash[:type] = type - elsif self.is_a? Module and self.respond_to? :name - hash[:type] = self.name - else - raise Puppet::DevError, "Cannot determine package type" - end - - hash[:ensure] = :present + hash[:type] = :sun packages.push Puppet.type(:package).installedpkg(hash) hash.clear @@ -152,14 +144,24 @@ module Puppet end def uninstall - cmd = "pkgrm -n %s 2>&1" % self[:name] - output = %x{#{cmd}} - if $? != 0 - raise Puppet::Error, "Removal of %s failed: %s" % [self.name, output] + command = "/usr/sbin/pkgrm -n " + + if self[:adminfile] + command += " -a " + self[:adminfile] + end + + command += " " + self[:name] + begin + execute(command) + rescue ExecutionFailure => detail + raise Puppet::Error, + "Could not uninstall %s: %s" % + [self[:name], detail] end end - # Remove the old package, and install the new one + # Remove the old package, and install the new one. This will probably + # often fail. def update if @states[:ensure].is != :absent self.uninstall @@ -168,3 +170,5 @@ module Puppet end end end + +# $Id$ |