BSD DevCenter
oreilly.comSafari Books Online.Conferences.

advertisement


Ports Tricks

by Dru Lavigne
08/07/2003

One of the many reasons to love FreeBSD is its ports collection. Nearly 10,000 applications are available, and any installation is a mere make install clean away. In today's article, I'd like to share some of my favorite ports tricks.

README

Even if you've been using the ports collection for a while, a read through man ports may reveal some tricks you were unaware of. If you have lots of disk space but a slow or intermittent Internet connection, this tip from the manpage is a real gem:

% cd /usr/ports
% make readmes

You may want to go grab some lunch while the command does its thing. When it's finished, you'll have a new file called /usr/ports/README.html. Open that file in your favorite web browser and you'll find some very handy hyperlinks. First, there is a link to the FreeBSD handbook, which can be accessed either offline from your hard disk, or online from the FreeBSD web site. Next, there is a link to the Porter's Handbook. If you've ever wondered at the magic behind a port's Makefile or had the urge to make your own port, this is the file to read.

Next, there is a list of hyperlinks to each of the subdirectories in /usr/ports. Don't let the simplicity fool you. Select a subdirectory and one of its applications. I'll click on Editors->AbiWord2. The resulting page contains hyperlinks to the port's description, web site, and maintainer's email address, as well as the email address of the ports mailing list. It also contains a list of all of the port's dependencies. Granted, all of this information was already on your hard drive, but you can't beat accessing it via one bookmarkable web page that is available offline.

Making a Package Repository

Related Reading

The Complete FreeBSD
Documentation from the Source
By Greg Lehey

Another handy trick is making a package repository. This can be both a time- and bandwidth-saver if you need to install software on multiple machines in a network. It is also ideal for installing software on server machines, as you don't have to install the entire ports collection just to install your required applications.

Pick a machine in your network to contain the package repository. Only this machine will need the ports collection; it won't be required on the rest of the machines in the network. Start by creating a directory to hold the packages:

% mkdir /usr/ports/packages

Then create the packages you need. Here, I'll create two packages:

% cd /usr/ports/www/lynx
% make package
% cd /usr/ports/mail/getmail
% make package

When you use make package, two things happen. One, a package is created and stored in a subdirectory of /usr/ports/packages. Second, the port is installed on the local machine, if it hasn't already been installed. If you don't want to keep the application installed on the machine acting as the package repository, simply type make deinstall once the package has been created.

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, 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 be opened in vi. The default file contains some example syntax. I added this line to my file to reflect the network ID used on my network:

/usr/ports/packages -network 192.168.2.0 -mask 255.255.255.0

Once you've saved your changes, you can reboot to initialize the NFS server. If rebooting isn't an option, follow the directions in the handbook. Then, ensure the NFS server is listening for requests:

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

Next, you'll need to create NFS clients on each machine that is to use the package repository. This time, in /stand/sysinstall, choose NFS client instead of NFS server. You won't be prompted for anything; you'll just check off the box. Once you've exited the utility, type:

% nfsiod -n 4

Then, check to see if you can access the package repository. In my example, 192.168.2.12 is the machine containing the packages:

% mount 192.168.2.12:/usr/ports/packages /mnt
% ls /mnt
All	Latest	ipv6	mail	python	www

You'll note that subdirectories were created for mail/getmail and www/lynx. The ipv6 and python subdirectories were for dependencies of those packages. The All subdirectory is quite handy:

% ls /mnt/All
getmail-3.1.7.tbz	lynx-2.8.4.1d.tbz

I'll now try to add a package:

% pkg_add /mnt/www/lynx-2.8.4.1d.tbz

Once I receive my prompt back, I'll check that the application did indeed install:

% pkg_info | grep lynx
lynx-2.8.4.1d	A non-graphical, text-based World-Wide Web client

If you're used to installing ports, you'll find that packages don't install their dependencies for you. Rather, they complain when one is missing. For example:

% pkg_add /mnt/mail/getmail-3.1.7.tbz
pkg_add: could not find package python-2.2.3_2 !

Educate your users simply to install the dependency first (in this case, python-2.2.3_2), and then install the desired package. Also, when a user is finished, remind them to cd out of the NFS share and unmount it:

% cd
% umount /mnt

Pages: 1, 2

Next Pagearrow





Sponsored by: