fink.rb

Udo Waechter, 05/17/2007 11:39 am

Download (2.65 KB)

 
1
Puppet::Type.type(:package).provide :fink, :parent => :dpkg do
2
    # Provide sorting functionality
3
    include Puppet::Util::Package
4

    
5
    desc "Package management via ``fink``."
6
    
7
        commands :fink => "/sw/bin/fink"
8
    commands :aptget => "/sw/bin/apt-get"
9
    commands :aptcache => "/sw/bin/apt-cache"
10
    commands :dpkgquery => "/sw/bin/dpkg-query"
11
    #commands :preseed => "/usr/bin/debconf-set-selections"
12

    
13
    defaultfor :operatingsystem => :darwin
14

    
15
    ENV['DEBIAN_FRONTEND'] = "noninteractive"
16

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

    
21
    def finkcmd(*args)
22
        fink(*args)
23
    end
24

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

    
33
        str = @resource[:name]
34
        case should
35
        when true, false, Symbol
36
            # pass
37
        else
38
            # Add the package version
39
            str += "=%s" % should
40
        end
41
        cmd = %w{-b -q -y}
42

    
43
        keep = ""
44
      #  if config = @resource[:configfiles]
45
      #      case config
46
      #      when :keep
47
      #          cmd << "-o" << 'DPkg::Options::=--force-confold'
48
      #      when :replace
49
      #         cmd << "-o" << 'DPkg::Options::=--force-confnew'
50
      #      else
51
      #          raise Puppet::Error, "Invalid 'configfiles' value %s" % config
52
      #      end
53
      #  end
54

    
55
        cmd << :install << str
56
        
57
        finkcmd(cmd)
58
    end
59

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

    
64
        if output =~ /Candidate:\s+(\S+)\s/
65
            return $1
66
                else
67
            self.err "Could not find latest version"
68
            return nil
69
                end
70
                end
71

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

    
79
            preseed response
80
        else 
81
            self.info "No responsefile specified or non existant, not preseeding anything"
82
        end
83
    end
84

    
85
    def update
86
        self.install
87
    end
88

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

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

    
97
    def versionable?
98
        true
99
    end
100
end
101

    
102
# $Id: apt.rb 2501 2007-05-09 23:08:42Z luke $