Shami's Blog

Sysadmin, Because Even Developers Need Heroes

Bootstrapping PKGNG From Your Own Repository

2015-03-13 by Mohammad H. Al-Shami

I’ve been building my own PKGNG repositories with Poudriere lately. Some of the benefits include:

  • Faster deployment times; You won’t have to compile every package and any needed dependencies every time you need them, all updated packages are pre-built the night before
  • Conserve bandwidth; All installations happen on the local network, so no need to access the Internet during installation, and packages are only downloaded once
  • Compile packages with the options you need; Sometimes you might want to change the default compile options used for packages, e.g. the nginx version available at does not support SPDY, or you might want to remove an option you don’t need to minimize the attack surface

To quickly setup your new servers to use your own repository, just add this script to the root of your repository


# PKGNG bootstrapper
# 20150312, Mohammad Al-Shami

# Use full pathes just in case

# If for some reason you want to use a different package server
# Send it as a parameter to the script
if [ ! -z $1 ]; then
release=`$UNAME -r | $SED -r "s/([0-9]+).([0-9]+)-RELEASE.*/\1\2x64/"`

export PACKAGESITE=http://$pkgServer/$release-default

# Remove the default FreeBSD repo, only if it exists
if [ -f /etc/pkg/FreeBSD.conf ]; then
        $MV /etc/pkg/FreeBSD.conf /etc/pkg/

# Bootstrap pkg

# Perform some cleanup
$RM -f /usr/local/etc/pkg.conf

# Set up our repo, which will then be overwritten by Salt
$MKDIR -p /usr/local/etc/pkg/repos/
$CAT > /usr/local/etc/pkg/repos/repositories.conf <<EOF
sauron : {
    url : "pkg+$PACKAGESITE",
    mirror_type : "srv",
    enabled : true,

For me, this bootstraps my base repository to allow me to easily install Salt which I then use to manage the repository list.

To bootstrap, just run one the following commands:

# To you use the default IP address in the script (here it is
fetch -o - | sh -
# To use a different IP (If used from a remote site with NAT)
fetch http://repo.mycompany.tld/ -o - | sh -s repo.mycompany.tld -

About Me

Dev gone Ops gone DevOps. Any views expressed on this blog are mine alone and do not necessarily reflect the views of my employer.