Skip to content

Commit

Permalink
package provider: add support for source parameter
Browse files Browse the repository at this point in the history
Allow using the `source` parameter as an URI to determine from where to
install the package.

If `source` is not set, then use `pkg install` to install the package
using the default repository logic.

A URN of the form: urn:freebsd:repo:<tag> will force `pkg install` to
install from the given repository using the '-r' flag. URLs are passed
as-is to `pkg add` to install directly.
  • Loading branch information
Russell Jackson committed Mar 6, 2014
1 parent 652c09a commit 8a85dd2
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions lib/puppet/provider/package/pkgng.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,34 @@ def self.prefetch(resources)
end
end

def repo_tag_from_urn(urn)
# extract repo tag from URN: urn:freebsd:repo:<tag>
schema = ['urn', 'freebsd', 'repo', nil]
validation = schema.zip(urn.split(':'))
result = validation.map do |should, actual|
if should.nil?
value = actual
else
raise ArgumentError source.inspect unless should == actual
value = nil
end
value
end
result.compact.first
end

def install
if File.exists?('/usr/local/etc/pkg.conf')
pkg(['install', '-qy', resource[:name]])
else
raise Puppet::Error.new("/usr/local/etc/pkg.conf does not exist")
source = resource[:source]
source = URI(source) unless source.nil?
if not source # install using default repo logic
args = ['install', '-qy', resource[:name]]
elsif source.scheme == 'urn' # install from repo named in URN
tag = repo_tag_from_urn(source.to_s)
args = ['install', '-qy', '-r', tag, resource[:name]]
else # add package located at URL
args = ['add', '-q', source.to_s]
end
pkg(args)
end

def uninstall
Expand Down

0 comments on commit 8a85dd2

Please sign in to comment.