summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider/package/rug.rb
blob: 56cce70b73a63c1b76227c9dd4333c6baa7ba787 (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
Puppet.type(:package).provide :rug, :parent => :rpm do
    desc "Support for suse ``rug`` package manager."

    has_feature :versionable

    commands :rug => "/usr/bin/rug"
    defaultfor :operatingsystem => :suse 
    confine    :operatingsystem => :suse

    # Install a package using 'rug'.
    def install
        should = @resource.should(:ensure)
        self.debug "Ensuring => #{should}"
        wanted = @resource[:name]

        # XXX: We don't actually deal with epochs here.
        case should
        when true, false, Symbol
            # pass
        else
            # Add the package version
            wanted += "-%s" % should
        end
        output = rug "--quiet", :install, "-y", wanted

        unless self.query
            raise Puppet::ExecutionFailure.new(
                "Could not find package %s" % self.name
            )
        end
    end

    # What's the latest package version available?
    def latest
        #rug can only get a list of *all* available packages?
        output = rug "list-updates"

        if output =~ /#{@resource[:name]}\s*\|\s*([0-9\.\-]+)/
            return $1
        else
            # rug didn't find updates, pretend the current
            # version is the latest
            return @property_hash[:ensure]
        end
    end

    def update
        # rug install can be used for update, too
        self.install
    end
end