~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to lib/puppet/provider/package/pkgdmg.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
# in /var/db/.puppet_pkgdmg_installed_<name>
27
27
 
28
28
require 'puppet/provider/package'
 
29
require 'facter/util/plist'
29
30
 
30
31
Puppet::Type.type(:package).provide :pkgdmg, :parent => Puppet::Provider::Package do
31
32
    desc "Package management based on Apple's Installer.app and DiskUtility.app.  This package works by checking the contents of a DMG image for Apple pkg or mpkg files. Any number of pkg or mpkg files may exist in the root directory of the DMG file system. Sub directories are not checked for packages.  See `the wiki docs </trac/puppet/wiki/DmgPackages>` for more detail."
32
 
  
33
 
    confine :exists => "/Library/Receipts"
 
33
    
 
34
    confine :operatingsystem => :darwin
 
35
    defaultfor :operatingsystem => :darwin
34
36
    commands :installer => "/usr/sbin/installer"
35
37
    commands :hdiutil => "/usr/bin/hdiutil"
36
38
    commands :curl => "/usr/bin/curl"
64
66
          t.print "source: '#{orig_source}'\n"
65
67
      end
66
68
    end
67
 
    
 
69
 
68
70
    def self.installpkgdmg(source, name)
69
71
        unless source =~ /\.dmg$/i
70
 
            self.fail "Mac OS X PKG DMG's must specificy a source string ending in .dmg"
 
72
            raise Puppet::Error.new("Mac OS X PKG DMG's must specificy a source string ending in .dmg")
71
73
        end
72
74
        require 'open-uri'
73
 
        require 'facter/util/plist'
74
75
        cached_source = source
75
76
        if %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ cached_source
76
77
            cached_source = "/tmp/#{name}"
82
83
                cached_source = source
83
84
            end
84
85
        end
85
 
        
 
86
 
86
87
        begin
87
 
            open(cached_source) do |dmg|
 
88
            File.open(cached_source) do |dmg|
88
89
                xml_str = hdiutil "mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", dmg.path
89
 
                # JJM THIS IS A HORRIBLE HACK (Well, actually it's not so bad...)
90
 
                mounts = xml_str.scan(/<string>(\/tmp.*?)<\/string>/)[0]
 
90
                hdiutil_info = Plist::parse_xml(xml_str)
 
91
                unless hdiutil_info.has_key?("system-entities")
 
92
                    raise Puppet::Error.new("No disk entities returned by mount at %s" % dmg.path)
 
93
                end
 
94
                mounts = hdiutil_info["system-entities"].collect { |entity|
 
95
                    entity["mount-point"]
 
96
                }.compact
91
97
                begin
92
 
                    mounts.each do |fspath|
93
 
                        Dir.entries(fspath).select { |f|
 
98
                    mounts.each do |mountpoint|
 
99
                        Dir.entries(mountpoint).select { |f|
94
100
                            f =~ /\.m{0,1}pkg$/i
95
 
                            }.each do |pkg|
96
 
                                installpkg("#{fspath}/#{pkg}", name, source)
97
 
                            end
98
 
                    end # mounts.each do
 
101
                        }.each do |pkg|
 
102
                            installpkg("#{mountpoint}/#{pkg}", name, source)
 
103
                        end
 
104
                    end
99
105
                ensure
100
 
                    hdiutil "eject", mounts[0]
101
 
                end # begin
102
 
            end # open() do
 
106
                    mounts.each do |mountpoint|
 
107
                        hdiutil "eject", mountpoint
 
108
                    end
 
109
                end
 
110
            end
103
111
        ensure
104
112
            # JJM Remove the file if open-uri didn't already do so.
105
113
            File.unlink(cached_source) if File.exist?(cached_source)
106
 
        end # begin
107
 
    end # def self.installpkgdmg
 
114
        end
 
115
    end
108
116
 
109
117
    def query
110
118
        if FileTest.exists?("/var/db/.puppet_pkgdmg_installed_#{@resource[:name]}")
117
125
    def install
118
126
        source = nil
119
127
        unless source = @resource[:source]
120
 
            self.fail "Mac OS X PKG DMG's must specify a package source."
 
128
            raise Puppet::Error.new("Mac OS X PKG DMG's must specify a package source.")
121
129
        end
122
130
        unless name = @resource[:name]
123
 
            self.fail "Mac OS X PKG DMG's must specify a package name."
 
131
            raise Puppet::Error.new("Mac OS X PKG DMG's must specify a package name.")
124
132
        end
125
133
        self.class.installpkgdmg(source,name)
126
134
    end