summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider/package/fink.rb
blob: 4d560666b14ea26a15e3825805a56e78d0618205 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Puppet::Type.type(:package).provide :fink, :parent => :dpkg, :source => :dpkg do
    # Provide sorting functionality
    include Puppet::Util::Package

    desc "Package management via ``fink``."
    
    commands :fink => "/sw/bin/fink"
    commands :aptget => "/sw/bin/apt-get"
    commands :aptcache => "/sw/bin/apt-cache"
    commands :dpkgquery => "/sw/bin/dpkg-query"

    has_feature :versionable

    # A derivative of DPKG; this is how most people actually manage
    # Debian boxes, and the only thing that differs is that it can
    # install packages from remote sites.

    def finkcmd(*args)
        fink(*args)
    end

    # Install a package using 'apt-get'.  This function needs to support
    # installing a specific version.
    def install
        if @resource[:responsefile]
            self.run_preseed
        end
        should = @resource.should(:ensure)

        str = @resource[:name]
        case should
        when true, false, Symbol
            # pass
        else
            # Add the package version
            str += "=%s" % should
        end
        cmd = %w{-b -q -y}

        keep = ""

        cmd << :install << str
        
        finkcmd(cmd)
    end

    # What's the latest package version available?
    def latest
        output = aptcache :policy,  @resource[:name]

        if output =~ /Candidate:\s+(\S+)\s/
            return $1
                else
            self.err "Could not find latest version"
            return nil
                end
                end

	#
	# preseeds answers to dpkg-set-selection from the "responsefile"
	#
    def run_preseed
        if response = @resource[:responsefile] and FileTest.exists?(response)
            self.info("Preseeding %s to debconf-set-selections" % response)

            preseed response
        else 
            self.info "No responsefile specified or non existant, not preseeding anything"
        end
    end

    def update
        self.install
    end

    def uninstall
        finkcmd "-y", "-q", :remove, @model[:name]
    end

    def purge
        aptget '-y', '-q', 'remove', '--purge', @resource[:name]
     end
end