2012/04/07: Upgrading ports -- essentially a simple for loop...

FreeBSD ports are quite automatic. Installation is as simple as

cd /usr/ports/category/port && make install clean
and getting rid of an installed port is also a simple command.
pkg_delete package

Nevertheless, for upgrading your ports hardly anyone calls these commands by hand. Instead there are tools like portupgrade(1), portmaster(8), and many others.

There is not much to do. You can use pkg_version(1) to find out, which ports need updating. Then you sort them by dependency, and upgrade each of them, skipping those that depend on ports that failed to upgrade. So, essentially it's a big for loop.

Recently, I wrote my own set of port upgrade tools, to understand where the power of these tools come from. A big part really is convenience. Typing a sequence of two or three commands is easy; typing essentially that same sequence hundreds of times is completely annoying, to say the least.

However, there are also some subtle points. To make the upgrade a smooth experience, you have to preserve shared libraries during the update until all ports depending on that library have also been upgraded—upgrading from source just isn't instant. Another subtle point is dependencies. If you replace one package by a compatible one, you still have to inform all packages depending on it, that they now depend on a different package. So, automatising here is not only convenient, but also helps to avoid forgetting one of the "obvious" points.



Cross-referenced by: