Cleaning Up Ports
Pages: 1, 2
Now you have a database of package information, /var/db/pkg/pkgdb.db.
You'll also have a ports database, /usr/ports/index.db and
/usr/ports/index.dbo. The various portupgrade tools use these
databases to work their magic. Whenever you upgrade your ports tree,
upgrade the ports database and /usr/ports/INDEX. You can do this
easily with portsdb -Uu.
Now that we have the tools installed, let's see what we can do. To
see what you have that's obsolete, use portversion (1). This works in
the same way as pkg_info but is far faster.
# portversion
Hermes =
Mesa =
ORBit <
XFree86-aoutlibs <
Xaw3d =
aalib =
A < means that the installed version is older than what is available
in the ports tree. You can easily run portversion | grep '<' to see
which ports are obsolete. I do this every so often just to see what's
installed on my system. For example, my Apache package is outdated.
I'm no longer using Apache on my laptop, however, so I can remove it.
The standard pkg_delete command still works, but if I use it my
package database will fall out of synch with my system. Use
pkg_deinstall(1) instead.
# pkg_deinstall apache
---< Deinstalling 'apache-1.3.20'
[Updating the pkgdb in /var/db/pkg ... - 182 packages found (-1 +0)
(...) done]
#
The nice thing is, I no longer need to give the full version number!
(That's bugged me about the FreeBSD pkg_* tools for quite some time,
but never enough to do anything about it.) The portupgrade
tools include globbing functions, which means that they can do pattern
matching.
I want to upgrade certain other ports. What's more, I want to upgrade
these while keeping the database synchronized, and updating the
now-correct entries in /var/db/pkg. For example, pkgversion tells me
that gd is out of date. It's simple enough to upgrade:
# portupgrade gd
===> Cleaning for gettext-0.10.35
===> Cleaning for gmake-3.79.1
===> Cleaning for libtool-1.3.4_2
===> Cleaning for jpeg-6b
===> Cleaning for png-1.2.0
===> Cleaning for freetype2-2.0.5
===> Cleaning for gd-1.8.4_4
If you want to compile in X support use
'make -DWITH_X11' instead
===> Extracting for gd-1.8.4_4
....
You'll see the familiar make output for a while. If you keep
watching, though, you'll see it make a detour to deinstall the
existing package, update the database, and keep going.
...
---> Deinstalling 'gd-1.8.4_3'
pkg_delete: package 'gd-1.8.4_3' is required by these other packages
and may not be deinstalled (but I'll delete it anyway):
scr2png-1.1
[Updating the pkgdb in /var/db/pkg ... - 180 packages found (-1 +0)
(...) done]
===> Installing for gd-1.8.4_4
...
Once the install finishes, it updates the package database again. Everything is synchronized.
Now, let's look at something difficult. My docproj port is out of
date. The docproj port is a port that doesn't include anything in and
of itself, but has dependencies on every tool needed to edit the
FreeBSD Documentation Project. If you regularly build the docs tree,
you need this tool to be up-to-date. Also, you don't want to
recursively rebuild the whole thing just for a minor update; docproj
has some huge dependencies.
If I wanted to save some time, I could use portupgrade -P to tell
portupgrade to use packages for this. Time is something my computer
has no shortage of, so I'll use ports. We need to tell portupgrade to
recursively upgrade packages, however, so it will upgrade the packages
required by docproj. You can do this with the -R flag. Let's give it
a try.
# portupgrade -R docproj
This port will try to ensure that the tools used by the FreeBSD
Documentation Project are installed on your system so you can convert
documentation from SGML to other formats.
One of these components is JadeTeX, which depends on TeTeX. The source for TeTeX is larger than 30 MB, and may be a very long download.
If you do not want to produce PostScript and PDF formats from the
documentation, you do not need JadeTeX, and you should set the
variable JADETEX to "no". If you do want to produce PostScript and
PDF output then set JADETEX to "yes".
For example:
make JADETEX=no
make JADETEX=yes
*** Error code 1
Stop.
** Command failed: make clean build
** Fix the problem and try again.
** The following packages were not installed or upgraded (-:skipped /
!:failed)
! textproc/docproj (docproj-1.4) (unknown build error)
#
Ugh. This port requires customization. You can edit
/usr/ports/textproc/docproj/Makefile to add JADETEX=no somewhere. It
will now run transparently.
When you've finished, you can check how things stand with portversion.
You might find that other port dependencies have changed -- for
example, if port A depends on port B, but port C also depends on port
B, running portupgrade A will not edit the dependencies of port C.
Be prepared to run pkgdb -F on occasion to find and fix these
problems.
If you want to have the system handle these things itself, you can use
portupgrade -rR; this will upgrade both dependent and depending
ports. If you always want the latest software on your system, this is
the way to go. portupgrade includes a variety of other tools that
simplify software management on FreeBSD, but this should be enough to
get you started.
You might find that you have to rebuild a single port multiple times
from the same distfile. If a port is revised, portversion will catch
it and mark it as outdated. You'll want to keep the distfiles for the
ports you have installed, but delete outdated distfiles. portsclean
-D will do this. Similarly, you might want to remove shared
libraries that are not referenced in the package database. I don't
want to use that option -- remember, I installed XFree86 from scratch,
not from ports. This function would remove my X setup, ouch! But
portsclean -L would do this, and it would help deal with problems
such as leftover files from my defective Mesa install.
Finally, I have to say that this tool seems fairly robust. As I was finishing this article, I ran these programs to check my examples. I noticed one obsolete package, and simply had to try to upgrade it.
# portupgrade -R portupgrade
Yep, it works. I'd say this tool is a definite winner.
Read more Big Scary Daemons columns.
Return to the BSD DevCenter.