~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mto: (3.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20080726154345-1fmgo76b4l72ulvc
ImportĀ upstreamĀ versionĀ 0.24.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Puppet::Type.type(:package).provide :apt, :parent => :dpkg do
 
1
Puppet::Type.type(:package).provide :apt, :parent => :dpkg, :source => :dpkg do
2
2
    # Provide sorting functionality
3
3
    include Puppet::Util::Package
4
4
 
5
5
    desc "Package management via ``apt-get``."
6
6
 
 
7
    has_feature :versionable
 
8
 
7
9
    commands :aptget => "/usr/bin/apt-get"
8
10
    commands :aptcache => "/usr/bin/apt-cache"
9
11
    commands :preseed => "/usr/bin/debconf-set-selections"
16
18
    # Debian boxes, and the only thing that differs is that it can
17
19
    # install packages from remote sites.
18
20
 
19
 
    def aptcmd(arg)
20
 
        aptget(arg)
21
 
    end
22
 
 
23
21
    def checkforcdrom
24
22
        unless defined? @@checkedforcdrom
25
23
            if FileTest.exists? "/etc/apt/sources.list"
35
33
            end
36
34
        end
37
35
 
38
 
        if @@checkedforcdrom and @model[:allowcdrom] != :true
 
36
        if @@checkedforcdrom and @resource[:allowcdrom] != :true
39
37
            raise Puppet::Error,
40
38
                "/etc/apt/sources.list contains a cdrom source; not installing.  Use 'allowcdrom' to override this failure."
41
39
        end
44
42
    # Install a package using 'apt-get'.  This function needs to support
45
43
    # installing a specific version.
46
44
    def install
47
 
        if @model[:responsefile]
 
45
        if @resource[:responsefile]
48
46
            self.run_preseed
49
47
        end
50
 
        should = @model.should(:ensure)
 
48
        should = @resource.should(:ensure)
51
49
 
52
50
        checkforcdrom()
53
51
 
54
 
        str = @model[:name]
 
52
        str = @resource[:name]
55
53
        case should
56
54
        when true, false, Symbol
57
55
            # pass
59
57
            # Add the package version
60
58
            str += "=%s" % should
61
59
        end
 
60
        cmd = %w{-q -y}
62
61
 
63
62
        keep = ""
64
 
        if config = @model[:configfiles]
 
63
        if config = @resource[:configfiles]
65
64
            case config
66
65
            when :keep
67
 
                keep = "-o 'DPkg::Options::=--force-confold'"
 
66
                cmd << "-o" << 'DPkg::Options::=--force-confold'
68
67
            when :replace
69
 
                keep = "-o 'DPkg::Options::=--force-confnew'"
 
68
                cmd << "-o" << 'DPkg::Options::=--force-confnew'
70
69
            else
71
70
                raise Puppet::Error, "Invalid 'configfiles' value %s" % config
72
71
            end
73
72
        end
 
73
 
 
74
        cmd << :install << str
74
75
        
75
 
        aptcmd("-q -y %s install %s" % [keep, str])
 
76
        aptget(*cmd)
76
77
    end
77
78
 
78
79
    # What's the latest package version available?
79
80
    def latest
80
 
        output = aptcache("showpkg %s" % @model[:name] )
81
 
 
82
 
        if output =~ /Versions:\s*\n((\n|.)+)^$/
83
 
            versions = $1
84
 
            version = versions.split(/\n/).collect { |version|
85
 
                if version =~ /^([^\(]+)\(/
86
 
                    $1
87
 
                else
88
 
                    self.warning "Could not match version '%s'" % version
89
 
                    nil
90
 
                end
91
 
            }.reject { |vers| vers.nil? }.sort { |a,b|
92
 
                versioncmp(a,b)
93
 
            }
94
 
 
95
 
            unless version.length > 0
96
 
                self.debug "No latest version"
97
 
                if Puppet[:debug]
98
 
                    print output
99
 
                end
100
 
            end
101
 
 
102
 
            return version.shift
 
81
        output = aptcache :policy,  @resource[:name]
 
82
 
 
83
        if output =~ /Candidate:\s+(\S+)\s/
 
84
            return $1
103
85
        else
104
 
            self.err "Could not match string"
 
86
            self.err "Could not find latest version"
 
87
            return nil
105
88
        end
106
89
    end
107
90
 
109
92
        # preseeds answers to dpkg-set-selection from the "responsefile"
110
93
        #
111
94
    def run_preseed
112
 
        if response = @model[:responsefile] && FileTest.exists?(response)
 
95
        if response = @resource[:responsefile] and FileTest.exists?(response)
113
96
            self.info("Preseeding %s to debconf-set-selections" % response)
114
97
 
115
98
            preseed response
123
106
    end
124
107
 
125
108
    def uninstall
126
 
        aptcmd("-y -q remove %s" % @model[:name])
 
109
        aptget "-y", "-q", :remove, @resource[:name]
127
110
    end
128
111
 
129
 
    def versionable?
130
 
        true
 
112
    def purge
 
113
        aptget '-y', '-q', 'remove', '--purge', @resource[:name]
 
114
        # workaround a "bug" in apt, that already removed packages are not purged
 
115
        super
131
116
    end
132
117
end
133
118
 
134
 
# $Id: apt.rb 1853 2006-11-10 17:51:47Z luke $