Skip to content

Commit

Permalink
Merge pull request #30 from skoef/master
Browse files Browse the repository at this point in the history
Added support for managing multiple repositories
  • Loading branch information
Zach Leslie committed Feb 18, 2014
2 parents 4ef4512 + b5ddf6c commit 652c09a
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 69 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
107 changes: 41 additions & 66 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
# 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")
}

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)
}
3 changes: 0 additions & 3 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
39 changes: 39 additions & 0 deletions manifests/repo.pp
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions templates/repo.erb
Original file line number Diff line number Diff line change
@@ -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 652c09a

Please sign in to comment.