summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider/package/apple.rb
blob: 9214d4eb5c28bd2ce0f7bac36dced8a533e5e689 (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
require 'puppet/provider/package'

# OS X Packaging sucks.  We can install packages, but that's about it.
Puppet::Type.type(:package).provide :apple, :parent => Puppet::Provider::Package do
    desc "Package management based on OS X's builtin packaging system.  This is
        essentially the simplest and least functional package system in existence --
        it only supports installation; no deletion or upgrades.  The provider will
        automatically add the ``.pkg`` extension, so leave that off when specifying
        the package name."

    confine :operatingsystem => :darwin
    commands :installer => "/usr/sbin/installer"

    def self.instances
        instance_by_name.collect do |name|

                        self.new(
                
                :name => name,
                :provider => :apple,
        
                :ensure => :installed
            )
        end
    end

    def self.instance_by_name
        Dir.entries("/Library/Receipts").find_all { |f|
            f =~ /\.pkg$/
        }.collect { |f|
            name = f.sub(/\.pkg/, '')
            yield name if block_given?

            name
        }
    end

    def query
        if FileTest.exists?("/Library/Receipts/#{@resource[:name]}.pkg")
            return {:name => @resource[:name], :ensure => :present}
        else
            return nil
        end
    end

    def install
        source = nil
        unless source = @resource[:source]
            self.fail "Mac OS X packages must specify a package source"
        end

        installer "-pkg", source, "-target", "/"
    end
end