Sha256: d499ef8d13e21943c63790ce7f2308e76f4297e0de8d5614e7d6ee2ae69794ba

Contents?: true

Size: 1.42 KB

Versions: 28

Compression:

Stored size: 1.42 KB

Contents

require "puppet/provider/package"

Puppet::Type.type(:package).provide :pkgin, :parent => Puppet::Provider::Package do
  desc "Package management using pkgin, a binary package manager for pkgsrc."

  commands :pkgin => "pkgin"

  defaultfor :operatingsystem => :dragonfly

  has_feature :installable, :uninstallable

  def self.parse_pkgin_line(package, force_status=nil)

    # e.g.
    #   vim-7.2.446 =        Vim editor (vi clone) without GUI
    match, name, version, status = *package.match(/(\S+)-(\S+)(?: (=|>|<))?\s+.+$/)
    if match
      ensure_status = if force_status
        force_status
      elsif status
        :present
      else
        :absent
      end

      {
        :name     => name,
        :ensure   => ensure_status,
        :provider => :pkgin
      }
    end
  end

  def self.instances
    pkgin(:list).split("\n").map do |package|
      new(parse_pkgin_line(package, :present))
    end
  end

  def query
    packages = pkgin(:search, resource[:name]).split("\n")

    # Remove the last three lines of help text.
    packages.slice!(-3, 3)

    matching_package = nil
    packages.detect do |package|
      properties = self.class.parse_pkgin_line(package)
      matching_package = properties if properties && resource[:name] == properties[:name]
    end

    matching_package
  end

  def install
    pkgin("-y", :install, resource[:name])
  end

  def uninstall
    pkgin("-y", :remove, resource[:name])
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
puppet-3.4.3 lib/puppet/provider/package/pkgin.rb
puppet-3.4.2 lib/puppet/provider/package/pkgin.rb
puppet-3.4.1 lib/puppet/provider/package/pkgin.rb
puppet-3.4.0 lib/puppet/provider/package/pkgin.rb
puppet-3.4.0.rc2 lib/puppet/provider/package/pkgin.rb
puppet-3.4.0.rc1 lib/puppet/provider/package/pkgin.rb
puppet-3.3.2 lib/puppet/provider/package/pkgin.rb
puppet-3.3.1 lib/puppet/provider/package/pkgin.rb
puppet-3.3.1.rc3 lib/puppet/provider/package/pkgin.rb
puppet-3.3.1.rc2 lib/puppet/provider/package/pkgin.rb
puppet-3.3.1.rc1 lib/puppet/provider/package/pkgin.rb
puppet-3.3.0 lib/puppet/provider/package/pkgin.rb
puppet-3.3.0.rc3 lib/puppet/provider/package/pkgin.rb
puppet-3.3.0.rc2 lib/puppet/provider/package/pkgin.rb
puppet-3.2.4 lib/puppet/provider/package/pkgin.rb
puppet-3.2.3 lib/puppet/provider/package/pkgin.rb
puppet-3.2.3.rc1 lib/puppet/provider/package/pkgin.rb
puppet-3.2.2 lib/puppet/provider/package/pkgin.rb
puppet-3.2.1 lib/puppet/provider/package/pkgin.rb
puppet-3.2.1.rc1 lib/puppet/provider/package/pkgin.rb