Creating custom pkgng repository for FreeBSD

pkg is a utility for installing binary packages in FreeBSD. But to install non-default options not selected by the packager/maintainer across multiple servers, use the ports to roll out custom packages. Creating custom package is very easy. There are only small changes compared to creating packages for the old pkg_* toolset.

mkdir -p /usr/ports/packages/All
make package-recursive install

Note that install keyword has been used, because new pkgng does not install the main port while creating the package. It will install all dependent ports though. Once packages are created, copy all of them to a staging directory:

cp /usr/ports/packages/All/* .

Alternatively, if the ports are already installed, create packages using:

pkg create -a

This will create packages for all installed ports in the current directory.

Once all the packages are in current directory, run pkg repo command to create repo files:

pkg repo .

Current directory now contains all the files to host custom repository :). Move it to some publicly accessible place which is reachable by target computers. Use of directory under a web server makes it easier. For more control over repository creation and how packages are created, see poudriere and tinderbox

On the target computers to use this repository, make a few changes. Disable the base FreeBSD repository:

mkdir -p /usr/local/etc/pkg/repos
echo "FreeBSD: { enabled: no }" > /usr/local/etc/pkg/repos/FreeBSD.conf

Now make the new repository active

echo 'REPONAME: { url: "http://REPO_URL"}' > /usr/local/etc/pkg/repos/REPONAME.conf
pkg upgrade

There are tons of options for the conf files, and also how to use multiple repositories with priorities, but those are beyond the scope this article. Consult man pages for pkg-repository and pkg.conf for more details.

Custom repository is now ready for use.

Please note that anything related to PACKAGESITE is no longer valid for the new versions of pkgng .

Advertisements