Skip to content

Commit

Permalink
Merge pull request #32 from xraj/master
Browse files Browse the repository at this point in the history
package provider: add support for `source` parameter
  • Loading branch information
Zach Leslie committed Mar 12, 2014
2 parents 652c09a + 8a85dd2 commit c8d71e6
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 c8d71e6

Please sign in to comment.