Ok, here they are: From 6405eb5e2b81191e7858084647d276d64bfe9bfd Mon Sep 17 00:00:00 2001 From: Udo Waechter <[email protected]> Date: Fri, 24 Jul 2009 13:38:40 +0200 Subject: [PATCH 1/2] added uninstall capabilities
Signed-off-by: Udo Waechter <[email protected]> ---lib/puppet/provider/package/appdmg.rb | 188 ++++++++++++++++++ +--------------
1 files changed, 110 insertions(+), 78 deletions(-)diff --git a/lib/puppet/provider/package/appdmg.rb b/lib/puppet/ provider/package/appdmg.rb
index 352f873..d334edc 100644 --- a/lib/puppet/provider/package/appdmg.rb +++ b/lib/puppet/provider/package/appdmg.rb @@ -13,102 +13,134 @@ # in /var/db/.puppet_appdmg_installed_<name> require 'puppet/provider/package' +require 'yaml' +require "FileUtils" +Puppet::Type.type(:package).provide(:appdmg, :parent => Puppet::Provider::Package) do - desc "Package management which copies application bundles to a target." + desc "Package management which copies application bundles to a target."
+ $appdmg_target = "/Applications"
+ confine :operatingsystem => :darwin
- confine :operatingsystem => :darwin
-
- commands :hdiutil => "/usr/bin/hdiutil"
- commands :curl => "/usr/bin/curl"
- commands :ditto => "/usr/bin/ditto"
+ commands :hdiutil => "/usr/bin/hdiutil"
+ commands :curl => "/usr/bin/curl"
+ commands :ditto => "/usr/bin/ditto"
+ # JJM We store a cookie for each installed .app.dmg in /var/db
+ def self.instances_by_name
+ Dir.entries("/var/db").find_all { |f|
+ f =~ /^\.puppet_appdmg_installed_/
+ }.collect do |f|
+ name = f.sub(/^\.puppet_appdmg_installed_/, '')
+ yield name if block_given?
+ name
+ end
+ end
- # JJM We store a cookie for each installed .app.dmg in /var/db
- def self.instances_by_name
- Dir.entries("/var/db").find_all { |f|
- f =~ /^\.puppet_appdmg_installed_/
- }.collect do |f|
- name = f.sub(/^\.puppet_appdmg_installed_/, '')
- yield name if block_given?
- name
- end
+ def self.instances
+ instances_by_name.collect do |name|
+ new(:name => name, :provider => :appdmg, :ensure => :installed)
end
+ end
- def self.instances
- instances_by_name.collect do |name|
- new(:name => name, :provider => :appdmg, :ensure
=> :installed)
- end
+ def self.installapp(source, name, orig_source)
+ appname = File.basename(source);
+ ditto "--rsrc", source, "#{$appdmg_target}/#{appname}"
+ dbfile = "/var/db/.puppet_appdmg_installed_#{name}"
+ receipthash = {}
+ receipthash["files"] = []
+ if File.exist?(dbfile)
+ receipthash = YAML::load_file(dbfile)
end
+ receipthash["name"] = name
+ receipthash["source"] = orig_source
+ receipthash["files"].include?(appname) or
receipthash["files"].push(appname)
+ f = File.open(dbfile,"w")
+ f.print receipthash.to_yaml
+ f.close
+ end
- def self.installapp(source, name, orig_source)
- appname = File.basename(source);
- ditto "--rsrc", source, "/Applications/#{appname}"
- File.open("/var/db/.puppet_appdmg_installed_#{name}", "w") do |t|
- t.print "name: '#{name}'\n"
- t.print "source: '#{orig_source}'\n"
+ def self.uninstallappdmg(name)
+ dbfile = "/var/db/.puppet_appdmg_installed_#{name}"
+ unless File.exist?(dbfile)
+ raise Puppet::Error.new("App DMG Package #{name} not installed.")
+ end
+ receipthash = YAML::load_file(dbfile)
+ receipthash["files"].each do |appname|
+ FileUtils.remove_entry_secure("#{$appdmg_target}/#{appname}")
+ unless $? == 0
+ raise Puppet::Error.new("App DMG could not remove
\"#{$appdmg_target}/#{appname}\"")
end
end
+ File.unlink(dbfile)
+ end
- def self.installpkgdmg(source, name)
- unless source =~ /\.dmg$/i
- self.fail "Mac OS X PKG DMG's must specificy a source
string ending in .dmg"
- end - require 'open-uri' - require 'facter/util/plist' + def self.installappdmg(source, name) + unless source =~ /\.dmg$/i+ raise Puppet::Error.new("Mac OS X app DMG's must specificy a source string ending in .dmg")
+ end
+ require 'open-uri'
+ require 'facter/util/plist'
+ cached_source = source
+ if %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ cached_source
+ cached_source = "/tmp/#{name}"
+ begin
+ curl "-o", cached_source, "-C", "-", "-k", "-s", "--url",
source
+ Puppet.debug "Success: curl transfered [#{name}]"
+ rescue Puppet::ExecutionFailure
+ Puppet.debug "curl did not transfer [#{name}]. Falling back
to slower open-uri transfer methods."
cached_source = source
- if %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ cached_source
- cached_source = "/tmp/#{name}"
- begin
- curl "-o", cached_source, "-C", "-", "-k", "-s", "--
url", source
- Puppet.debug "Success: curl transfered [#{name}]"
- rescue Puppet::ExecutionFailure
- Puppet.debug "curl did not transfer [#{name}].
Falling back to slower open-uri transfer methods."
- cached_source = source - end - end + end + end + begin + open(cached_source) do |dmg|+ xml_str = hdiutil "mount", "-plist", "-nobrowse", "- readonly", "-mountrandom", "/tmp", dmg.path
+ ptable = Plist::parse_xml xml_str+ # JJM Filter out all mount-paths into a single array, discard the rest.
+ mounts = ptable['system-entities'].collect { |entity|
+ entity['mount-point']
+ }.select { |mountloc|; mountloc }
begin
- open(cached_source) do |dmg|
- xml_str = hdiutil "mount", "-plist", "-nobrowse", "-
readonly", "-mountrandom", "/tmp", dmg.path
- ptable = Plist::parse_xml xml_str- # JJM Filter out all mount-paths into a single array, discard the rest. - mounts = ptable['system-entities'].collect { | entity|
- entity['mount-point']
- }.select { |mountloc|; mountloc }
- begin
- mounts.each do |fspath|
- Dir.entries(fspath).select { |f|
- f =~ /\.app$/i
- }.each do |pkg|
- installapp("#{fspath}/#{pkg}", name,
source)
- end
- end # mounts.each do
- ensure
- hdiutil "eject", mounts[0]
- end # begin
- end # open() do
+ mounts.each do |fspath|
+ Dir.entries(fspath).select { |f|
+ f =~ /\.app$/i
+ }.each do |app|
+ installapp("#{fspath}/#{app}", name, source)
+ end
+ end # mounts.each do
ensure
- # JJM Remove the file if open-uri didn't already do so.
- File.unlink(cached_source) if File.exist?(cached_source)
+ hdiutil "eject", mounts[0]
end # begin
- end # def self.installpkgdmg
+ end # open() do
+ ensure
+ # JJM Remove the file if open-uri didn't already do so.
+ File.unlink(cached_source) if File.exist?(cached_source)
+ end # begin
+ end # def self.installappdmg
- def query
- if FileTest.exists?("/var/
db/.puppet_appdmg_installed...@resource[:name]}")
- return {:name => @resource[:name], :ensure => :present}
- else
- return nil
- end
+ def query
+ if FileTest.exists?("/var/
db/.puppet_appdmg_installed...@resource[:name]}")
+ return {:name => @resource[:name], :ensure => :present}
+ else
+ return nil
+ end
+ end
+
+ def install
+ source = nil
+ unless source = @resource[:source]
+ raise Puppet::Error.new("Mac OS X app DMG's must specify a
package source.")
+ end + unless name = @resource[:name]+ raise Puppet::Error.new("Mac OS X app DMG's must specify a package name.")
end
+ self.class.installappdmg(source,name)
+ end
- def install
- source = nil
- unless source = @resource[:source]
- self.fail "Mac OS X PKG DMG's must specify a package
source."
- end - unless name = @resource[:name] - self.fail "Mac OS X PKG DMG's must specify a package name." - end - self.class.installpkgdmg(source,name) + def uninstall + unless name = @resource[:name]+ raise Puppet::Error.new("Mac OS X app DMG's must specify a package name.")
end
+ self.class.uninstallappdmg(name)
+ end
end
--
1.6.3.3
From f87fbcf962be9106f45e576d2f79c46d9969505c Mon Sep 17 00:00:00 2001
From: Udo Waechter <[email protected]>
Date: Fri, 24 Jul 2009 13:44:36 +0200
Subject: [PATCH 2/2] changed email address
Signed-off-by: Udo Waechter <[email protected]>
---
lib/puppet/provider/package/appdmg.rb | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/puppet/provider/package/appdmg.rb b/lib/puppet/
provider/package/appdmg.rb
index d334edc..37b82ae 100644 --- a/lib/puppet/provider/package/appdmg.rb +++ b/lib/puppet/provider/package/appdmg.rb @@ -1,5 +1,5 @@ # Jeff McCune <[email protected]> -# Changed to app.dmg by: Udo Waechter <[email protected]> +# Changed to app.dmg by: Udo Waechter <[email protected]> # Mac OS X Package Installer which handles application (.app) # bundles inside an Apple Disk Image. # -- 1.6.3.3 On 25.07.2009, at 00:54, Luke Kanies wrote:
Hi, Can you republish the code inline? Even just pasting it in will work. Thanks. On Jul 24, 2009, at 5:13 AM, Waechter Udo wrote:Hey all, sorry to post these patches this way, for some reason "rake mail_patches" does not work now and I currently do not have the nerv to debug that.I have extended provider/package/appdmg.rb such that one can uninstallapplication bundles now. For that, I needed to rewrite the format of /var/ db/.puppet_appdmg_*dmg file, such that it is yaml now. In a .dmg, there can be more than one .app bundles, thus I now record each of those in the yaml file.When uninstalling, these files are deleted and the .puppet_appdmg.*dmgafterwards. The patches are against current master, but do work with 0.24.x also. Problems that remain, must be solved: - how to convert already existing /var/db/.puppet_appdmg* files? (remove them if they are not yaml, thus let puppet reinstall those?) - is yaml fine, or should I use something else? - is line 68: FileUtils.remove_entry_secure(...) good? - does anyone except me use this provider? Please do comment, if you like it, then I will try to stick to thedeveloper-workflow (write tests, commit to git and all that) to submitthese patches. In a next step, we try to find out how to uninstall .pkgs.... That will be tricky. Have fun, udo.<0001-added-uninstall-capabilities.patch><0002-changed-email- address.patch> -- --[ System Administration Team ]-- --[ Institute of Cognitive Science @ University of Osnabrueck ]-- --[ Albrechtstrasse 28 - 49076 Osnabrueck, Germany ]-- --[ Tel. +49-541-9693363, Fax. +49-541-9693381 ]-- --[ https://doc.ikw.uni-osnabrueck.de | http://ikw.uni- osnabrueck.de ]---- "They called me mad, and I called them mad, and damn them, they outvoted me." -- Nathaniel Lee, on being consigned to a mental institution, circa 17th c. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com --~--~---------~--~----~------------~-------~--~----~You received this message because you are subscribed to the Google Groups "Puppet Developers" group.To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en -~----------~----~----~----~------~----~------~--~---
-- :: udo waechter - [email protected] :: N 52º16'30.5" E 8º3'10.1" :: genuine input for your ears: http://auriculabovinari.de :: your eyes: http://ezag.zoide.net :: your brain: http://zoide.net
smime.p7s
Description: S/MIME cryptographic signature
