Permalink
Browse files

added support for managing multiple repositories

removed support for pkgng before version 1.1.4
  • Loading branch information...
1 parent 4ef4512 commit 96538d0956c4ad98ef3c65ccfa4e6a6517a8bf59 @skoef skoef committed Feb 16, 2014
Showing with 92 additions and 69 deletions.
  1. +5 −0 README.md
  2. +41 −66 manifests/init.pp
  3. +0 −3 manifests/params.pp
  4. +39 −0 manifests/repo.pp
  5. +7 −0 templates/repo.erb
View
@@ -21,6 +21,11 @@ Then to configure your system to use a PkgNG, a simple include will do.
include pkgng
+or when you want to use specific PkgNG repositories:
+
+ pkgng::repo { 'pkg.freebsd.org': }
+ pkgng::repo { 'my.own.repo': }
+
### Installation via r10K
You can also clone this repo to somewhere in your modulepath, or use something
View
@@ -6,82 +6,57 @@
# make -C /usr/ports/ports-mgmg/pkg install clean
class pkgng (
- $packagesite = $pkgng::params::packagesite,
- $repo_name = $pkgng::params::repo_name,
- $srv_mirrors = $pkgng::params::srv_mirrors,
$pkg_dbdir = $pkgng::params::pkg_dbdir,
$pkg_cachedir = $pkgng::params::pkg_cachedir,
$portsdir = $pkgng::params::portsdir,
+ $repos = {},
) inherits pkgng::params {
- # At the time of this writing, only FreeBSD 9 and 10 are supported by pkgng
- if $pkgng_supported {
- $config_content = "PKG_DBDIR: ${pkg_dbdir}\nPKG_CACHEDIR: ${pkg_cachedir}\n"
-
- if $srv_mirrors == "YES" or $packagesite =~ /^pkg\+http/ {
- $mirror_type = "SRV"
- } else {
- $mirror_type = "HTTP"
- }
-
- file { "/usr/local/etc/pkg.conf":
- notify => Exec['pkg update'],
- }
-
- # from pkgng 1.1.4 and up, a different repo format is used
- if versioncmp($pkgng_version, "1.1.4") >= 0 {
- # make sure repo config dir is present
- file { "/usr/local/etc/pkg":
- ensure => directory,
- }
-
- file { "/usr/local/etc/pkg/repos/":
- ensure => directory,
- }
+ # At the time of this writing, only FreeBSD 9 and up are supported by pkgng
+ if ! $pkgng_supported or versioncmp($pkgng_version, "1.1.4") < 0 {
+ fail("PKGng is either not supported on your system or it is too old")
+ }
- File["/usr/local/etc/pkg.conf"] {
- content => "${config_content}"
- }
+ file { "/usr/local/etc/pkg.conf":
+ content => "PKG_DBDIR: ${pkg_dbdir}\nPKG_CACHEDIR: ${pkg_cachedir}\nPORTSDIR: ${portsdir}\n",
+ notify => Exec['pkg update'],
+ }
- file { "/usr/local/etc/pkg/repos/${repo_name}.conf":
- content => "${repo_name}: {\n url: ${$packagesite},\n mirror_type: ${mirror_type},\n enabled: true,\n}",
- notify => Exec['pkg update'],
- }
- } else {
- File["/usr/local/etc/pkg.conf"] {
- content => "PACKAGESITE: ${packagesite}\n${config_content}",
- }
- }
+ # make sure repo config dir is present
+ file { ['/usr/local/etc/pkg', '/usr/local/etc/pkg/repos']:
+ ensure => directory,
+ }
- file { "/etc/make.conf":
- ensure => present,
- }
+ file { '/etc/make.conf':
+ ensure => present,
+ }
- file_line { "WITH_PKGNG":
- path => '/etc/make.conf',
- line => "WITH_PKGNG=yes\n",
- require => File['/etc/make.conf'],
- }
+ file_line { 'WITH_PKGNG':
+ path => '/etc/make.conf',
+ line => "WITH_PKGNG=yes\n",
+ require => File['/etc/make.conf'],
+ }
- # Triggered on config changes
- exec { "pkg update":
- path => '/usr/local/sbin',
- refreshonly => true,
- command => "pkg -q update -f",
- }
+ # Triggered on config changes
+ exec { 'pkg update':
+ path => '/usr/local/sbin',
+ refreshonly => true,
+ command => 'pkg -q update -f',
+ }
- # This exec should really on ever be run once, and only upon converting to
- # pkgng. If you are building up a new system where the only software that
- # has been installed form ports is the pkgng itself, then the pkg database
- # is already up to date, and this is not required. As you will see,
- # refreshonly, but nothing notifies this. I am uncertain at this time how
- # to proceed, other than manually.
- exec { "convert pkg database to pkgng":
- path => '/usr/local/sbin',
- refreshonly => true,
- command => "pkg2ng",
- }
- } else {
- notice("pkgng is not supported on this release")
+ # This exec should really on ever be run once, and only upon converting to
+ # pkgng. If you are building up a new system where the only software that
+ # has been installed form ports is the pkgng itself, then the pkg database
+ # is already up to date, and this is not required. As you will see,
+ # refreshonly, but nothing notifies this. I am uncertain at this time how
+ # to proceed, other than manually.
+ exec { 'convert pkg database to pkgng':
+ path => '/usr/local/sbin',
+ refreshonly => true,
+ command => 'pkg2ng',
+ require => File['/etc/make.conf'],
}
+
+ # expand all pkg repositories from hashtable
+ create_resources('pkgng::repo', $repos)
}
View
@@ -1,7 +1,4 @@
class pkgng::params {
- $repo_name = "FreeBSD"
- $packagesite = 'pkg+http://pkg.FreeBSD.org/${ABI}/latest'
- $srv_mirrors = 'NO'
$pkg_dbdir = '/var/db/pkg'
$pkg_cachedir = '/var/cache/pkg'
$portsdir = '/usr/ports'
View
@@ -0,0 +1,39 @@
+# This configures a single PkgNG repository. Instead of defining the repo
+# with the repo URL, we split it up in hostname, mirror_type, protocol and
+# repopath. This way, this resource can be integrated with possible firewalls
+# better.
+
+define pkgng::repo (
+ $packagehost = $name,
+ $release = $::operatingsystemrelease,
+ $protocol = 'http',
+ $mirror_type = 'srv',
+ $repopath = '/${ABI}/latest',
+ $enabled = true,
+) {
+ include ::pkgng
+
+ # validate protocol against chosen mirror_type
+ case $mirror_type {
+ /(?i:srv)/: {
+ if $protocol !~ /(?i:http(s)?)/ {
+ fail("Mirror type ${mirror_type} support http:// and https:// only")
+ }
+ }
+ /(?i:http)/: {
+ if $protocol !~ /(?i:(http|https|ftp|file|ssh))/ {
+ fail("Mirror type ${mirror_type} support http://, https://, ftp://, file://, ssh:// only")
+ }
+ }
+ default: {
+ fail("Mirror type ${mirror_type} not supported")
+ }
+ }
+
+ # define repository configuration
+ file { "/usr/local/etc/pkg/repos/${name}.conf":
+ ensure => $ensure,
+ content => template("${module_name}/repo.erb"),
+ notify => Exec['pkg update'],
+ }
+}
View
@@ -0,0 +1,7 @@
+# File managed by Puppet
+
+<%= @name -%>: {
+ url: "<% if @mirror_type =~ /srv/i %>pkg+<% end %><%= @protocol %>://<%= @packagehost %><%= @repopath %>",
+ mirror_type: "<%= @mirror_type %>",
+ enabled: <% if @enabled == true or @enabled == 'yes' %>yes<% else %>no<% end %>,
+}

0 comments on commit 96538d0

Please sign in to comment.