From 96538d0956c4ad98ef3c65ccfa4e6a6517a8bf59 Mon Sep 17 00:00:00 2001 From: Reinier Schoof Date: Sun, 16 Feb 2014 20:56:41 +0100 Subject: [PATCH 1/2] added support for managing multiple repositories removed support for pkgng before version 1.1.4 --- README.md | 5 +++ manifests/init.pp | 107 +++++++++++++++++--------------------------- manifests/params.pp | 3 -- manifests/repo.pp | 39 ++++++++++++++++ templates/repo.erb | 7 +++ 5 files changed, 92 insertions(+), 69 deletions(-) create mode 100644 manifests/repo.pp create mode 100644 templates/repo.erb diff --git a/README.md b/README.md index d078773..38b1845 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/manifests/init.pp b/manifests/init.pp index d2f6a3e..f1db4fc 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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) } diff --git a/manifests/params.pp b/manifests/params.pp index d847839..8a69e15 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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' diff --git a/manifests/repo.pp b/manifests/repo.pp new file mode 100644 index 0000000..fb15290 --- /dev/null +++ b/manifests/repo.pp @@ -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'], + } +} diff --git a/templates/repo.erb b/templates/repo.erb new file mode 100644 index 0000000..43245ca --- /dev/null +++ b/templates/repo.erb @@ -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 %>, +} From b5ddf6c3dc3b80abd7aafa9476c045df8f02aaf2 Mon Sep 17 00:00:00 2001 From: Reinier Schoof Date: Sun, 16 Feb 2014 20:59:57 +0100 Subject: [PATCH 2/2] updated comment --- manifests/init.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index f1db4fc..2036064 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -12,7 +12,7 @@ $repos = {}, ) inherits pkgng::params { - # At the time of this writing, only FreeBSD 9 and up are supported by pkgng + # PkgNG versions before 1.1.4 use another method of defining repositories 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") }