added support for managing multiple repositories

removed support for pkgng before version 1.1.4
This commit is contained in:
Reinier Schoof 2014-02-16 20:56:41 +01:00
Родитель 4ef4512d7b
Коммит 96538d0956
5 изменённых файлов: 98 добавлений и 75 удалений

Просмотреть файл

@ -21,6 +21,11 @@ Then to configure your system to use a PkgNG, a simple include will do.
include pkgng include pkgng
or when you want to use specific PkgNG repositories:
pkgng::repo { 'pkg.freebsd.org': }
pkgng::repo { 'my.own.repo': }
### Installation via r10K ### Installation via r10K
You can also clone this repo to somewhere in your modulepath, or use something You can also clone this repo to somewhere in your modulepath, or use something

Просмотреть файл

@ -6,82 +6,57 @@
# make -C /usr/ports/ports-mgmg/pkg install clean # make -C /usr/ports/ports-mgmg/pkg install clean
class pkgng ( 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_dbdir = $pkgng::params::pkg_dbdir,
$pkg_cachedir = $pkgng::params::pkg_cachedir, $pkg_cachedir = $pkgng::params::pkg_cachedir,
$portsdir = $pkgng::params::portsdir, $portsdir = $pkgng::params::portsdir,
$repos = {},
) inherits pkgng::params { ) inherits pkgng::params {
# At the time of this writing, only FreeBSD 9 and 10 are supported by pkgng # At the time of this writing, only FreeBSD 9 and up are supported by pkgng
if $pkgng_supported { if ! $pkgng_supported or versioncmp($pkgng_version, "1.1.4") < 0 {
$config_content = "PKG_DBDIR: ${pkg_dbdir}\nPKG_CACHEDIR: ${pkg_cachedir}\n" fail("PKGng is either not supported on your system or it is too old")
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,
}
File["/usr/local/etc/pkg.conf"] {
content => "${config_content}"
}
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}",
}
}
file { "/etc/make.conf":
ensure => present,
}
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",
}
# 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")
} }
file { "/usr/local/etc/pkg.conf":
content => "PKG_DBDIR: ${pkg_dbdir}\nPKG_CACHEDIR: ${pkg_cachedir}\nPORTSDIR: ${portsdir}\n",
notify => Exec['pkg update'],
}
# 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_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',
}
# 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)
} }

Просмотреть файл

@ -1,7 +1,4 @@
class pkgng::params { class pkgng::params {
$repo_name = "FreeBSD"
$packagesite = 'pkg+http://pkg.FreeBSD.org/${ABI}/latest'
$srv_mirrors = 'NO'
$pkg_dbdir = '/var/db/pkg' $pkg_dbdir = '/var/db/pkg'
$pkg_cachedir = '/var/cache/pkg' $pkg_cachedir = '/var/cache/pkg'
$portsdir = '/usr/ports' $portsdir = '/usr/ports'

39
manifests/repo.pp Normal file
Просмотреть файл

@ -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'],
}
}

7
templates/repo.erb Normal file
Просмотреть файл

@ -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 %>,
}