Bootstrapping PKGNG From Your Own Repository
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 pkg.FreeBSD.org 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
1#!/bin/sh
2
3# PKGNG bootstrapper
4# 20150312, Mohammad Al-Shami
5
6# Use full pathes just in case
7PKG=/usr/sbin/pkg
8ENV=/usr/bin/env
9UNAME=/usr/bin/uname
10SED=/usr/bin/sed
11MV=/bin/mv
12RM=/bin/rm
13MKDIR=/bin/mkdir
14CAT=/bin/cat
15
16# If for some reason you want to use a different package server
17# Send it as a parameter to the script
18if [ ! -z $1 ]; then
19 pkgServer=$1
20else
21 pkgServer=192.168.1.150
22fi
23release=`$UNAME -r | $SED -r "s/([0-9]+).([0-9]+)-RELEASE.*/\1\2x64/"`
24
25export PACKAGESITE=http://$pkgServer/$release-default
26
27# Remove the default FreeBSD repo, only if it exists
28if [ -f /etc/pkg/FreeBSD.conf ]; then
29 $MV /etc/pkg/FreeBSD.conf /etc/pkg/FreeBSD.conf.org
30fi
31
32# Bootstrap pkg
33$ENV ASSUME_ALWAYS_YES=YES $PKG bootstrap
34
35# Perform some cleanup
36$RM -f /usr/local/etc/pkg.conf
37
38# Set up our repo, which will then be overwritten by Salt
39$MKDIR -p /usr/local/etc/pkg/repos/
40$CAT > /usr/local/etc/pkg/repos/repositories.conf <<EOF
41sauron : {
42 url : "pkg+$PACKAGESITE",
43 mirror_type : "srv",
44 enabled : true,
45}
46EOF
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:
1# To you use the default IP address in the script (here it is 192.168.1.150)
2fetch http://192.168.1.150/pkgng.sh -o - | sh -
3# To use a different IP (If used from a remote site with NAT)
4fetch http://repo.mycompany.tld/pkgng.sh -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.
Recent Posts