Hack 81 Create a Package Repository

figs/expert.gif figs/hack81.gif

Combine the advantages of compiling from source and installing packages.

We saw in [Hack #69] that compiling applications from source, i.e., by making their ports, has several advantages. You can tune /etc/make.conf to take advantage of your architecture. You can also customize the installation by passing various arguments to make.

However, if you're responsible for maintaining software on multiple machines, do you always want to install from source? If your systems run similar hardware, why not create your own customized packages on one machine and make them available to your other systems via a package repository?

Creating your own custom packages allows you to retain all the benefits of make. Even better, the resulting package installs the desired software very quickly. This can be a real time-saver when you maintain multiple systems.

The experienced hacker may prefer to use /usr/ports/devel/distcc to provide multiple builds.

8.6.1 Creating Custom Packages

Pick a machine in your network to contain the package repository, and install the ports collection on that system. The rest of your systems won't need the ports collection, which saves their disk space for other purposes.

On the system containing the ports collection, create a directory to store the packages:

# mkdir /usr/ports/packages

Then, decide which packages you'd like to create. I'll start with Exim. Before creating the package, I'll search through the port's Makefile to see if there are any make options:

# grep WITH /usr/ports/mail/exim/Makefile #WITH_TCP_WRAPPERS=   yes #WITH_MYSQL=          yes #WITH_SASLAUTHD=      yes #WITHOUT_TLS=         yes #WITHOUT_PERL=        yes #WITHOUT_PAM=         yes <snip>

This particular port has dozens of tweakables. After a more careful read-through of the Makefile, I've chosen to use WITHOUT_IPV6 and WITH_SASLAUTHD.

Next, I need to determine if there are any dependencies:

# grep DEP /usr/ports/mail/exim/Makefile LIB_DEPENDS=    iconv.3:${PORTSDIR}/converters/libiconv RUN_DEPENDS=    ${LOCALBASE}/sbin/eximon:${PORTSDIR}/mail/exim-monitor LIB_DEPENDS+=    db4.0:${PORTSDIR}/databases/db4 LIB_DEPENDS+=    db41.1:${PORTSDIR}/databases/db41 LIB_DEPENDS+=    db-4.2.2:${PORTSDIR}/databases/db42 RUN_DEPENDS+=    ${LOCALBASE}/sbin/saslauthd:${PORTSDIR}/security/                   cyrus-sasl2-saslauthd RUN_DEPENDS+=    ${LOCALBASE}/sbin/pwcheck:${PORTSDIR}/security/cyrus-sasl LIB_DEPENDS+=    pq.3:${PORTSDIR}/${POSTGRESQL_PORT}

Yup. Lots of those as well. This means I'll pass an extra argument to make to ensure the package also creates packages for each dependency. Once I know the desired make arguments, I create the package:

# cd /usr/ports/mail/exim # make package -DWITHOUT_IPV6 -DWITH_SASLAUTHD DEPENDS_TARGET=package

Notice that I used make package rather than the usual make install. I then included my two make options. I ended the command with the DEPENDS_TARGET=package option. (I found this argument on a mailing list as the result of a Google search.) If you're building any package that has dependencies, remember to include that option.

make package does two things. First, it creates and stores the package in a subdirectory of /usr/ports/packages. In this example, that subdirectory will be mail. Second, it installs the port on the local machine, if necessary. If you don't want to keep the application installed on the machine acting as the package repository, simply type make deinstall after creating the package.

8.6.2 Creating the NFS Share

Once you've populated /usr/ports/packages with the packages required by your network, set up an NFS mount to share the package repository. The easiest way to do this is with stand/sysinstall. On the machine holding the packages:

# /stand/sysinstall

Choose Configure, then Networking, and then NFS server. You should see the following message:

Operating as an NFS server means that you must first configure an  /etc/exports file to indicate which hosts are allowed certain kinds of  access to your local file systems. Press [ENTER] now to invoke an editor  on /etc/exports

Unless you've changed your default editor, /etc/exports will open in vi. The default file contains some example syntax; see man exports for additional tips.

I added this line to reflect my network settings:

/usr/ports/packages -network -mask

Once you've saved your changes, initialize and start the NFS server:

# /etc/rc.d/nfsd rcvar # /etc/rc.d/nfsd start

Then, ensure the NFS server is listening for requests:

# sockstat | grep nfs root   nfsd   3973   tcp4*:2049   *:*

Next, you'll need to create an NFS client on each machine that will use the package repository. This time, in /stand/sysinstall, choose NFS client instead of NFS server. There are no prompts, so just select the box. Once you've exited the utility, type:

# nfsiod -n 4

This will optimize the performance of the NFS client.

Then, check to see if you can access your package repository. In my example, the machine containing the packages has an IP address of and the local machine has a mount point called /packages:

# mkdir /packages # mount /packages # ls /packages All    Latest    ipv6            mail    security    sysutils

These various subdirectories contain the Exim package and its dependencies. To get an idea of which packages are available, use ls /packages/All.

It's also a good idea to try a test installation of a package:

# pkg_add /packages/mail/exim-4.30.tbz

Don't forget to unmount the NFS share when you're finished:

# umount /packages

8.6.3 See Also

  • man exports

  • man nfsiod

BSD Hacks
BSD Hacks
ISBN: 0596006799
EAN: 2147483647
Year: 2006
Pages: 160
Authors: Lavigne

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net