Package updates in OpenBSD 3.8
There used to be a severe limitation in upgrading OpenBSD. Now this has changed somewhat, with more changes soon to come. Formerly, you couldn’t upgrade packages. Now with the -u switch to pkg_add you can see what the package should upgrade to, and pkg_add. And, you can replace the old package with the new one by using the -r switch. nice.
Here I will reproduce the new relevant part of the faq updated on 12/18/2005, and add a few tips that are helping me. It can be found here at http://openbsd.org/faq/faq15.html#PkgUpdate.
From The OpenBSD FAQ:
15.2.6 – Updating installed packages
Since OpenBSD 3.7, it is possible to update existing packages by using the -r (= replace) switch to pkg_add(1). OpenBSD 3.8 introduces the -u switch to pkg_add(1). It is the beginning of a true update mechanism, and will be extended in future releases. For now, it will only tell you the name of the new package.Let’s say you had an older version of unzip installed before upgrading this box from OpenBSD 3.7 to 3.8. The -u switch can be used to find out the new package name, particularly the new version number, as follows:
$ sudo pkg_add -u unzip Updating unzip-5.51 -> unzip-5.52 Update using pkg_add -r unzip-5.52Now you can easily upgrade to the newer 3.8 package by just following the above instruction and replacing the old package in one go:
$ sudo pkg_add -r unzip-5.52 unzip-5.52 (extracting): complete unzip-5.51 (deleting): complete unzip-5.52 (installing): complete Clean shared items: completeInvoking pkg_add(1) with the -u flag and no package name will just examine all installed packages for updated versions. When a package has dependencies, they are also examined for updates.
Note: The -u switch relies on the PKG_PATH environment variable. If it is not set, pkg_add(1) will not be able to find updates.
If you had a configuration file belonging to the old version, which you modified, it will be left untouched by default. You can, however, replace it with the default configuration file of the new version, by calling pkg_add(1) with the -c flag.
The above is a handy way to quickly upgrade a package with a new version. It works well in more than 99% of the cases. Some very complicated software, however, will still require you to use the old method of first removing the old package, then adding the new package. This is slightly inconvenient, as packages may trigger dependencies, and you may have to remove a large subset of packages for an update.
My 2 cents:
First it is handy to have your PKG_PATH automatically set rather than manually setting it each time you upgrade to a new release. for instance your PKG_PATH will change when you go from 3.7 > 3.8. This line is in my /root/.profile. So, regardless of what version you upgrade to, it will always be current:
PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/`uname -r`/packages/`uname -m`
export PKG_PATH
Since I am running OpenBSD 3.8 This produces:
# echo $PKG_PATH
ftp://ftp.openbsd.org/pub/OpenBSD/3.8/packages/i386
Next, I produce a list of packages installed with:
pkg_info | awk '{print $1}' > installed_packages_3.6
( I had just upgraded from 3.6 to 3.8. Normally you want to upgrade with the supported 3.6 > 3.7 > 3.8, but I reviewed the changes in /etc and decided to just take the risk.)
Now let’s run the package add update and see what our package add replace command should look like:
pkg_add -u `cat installed_packages_3.6 > pkg_add_update.log &
tail -f pkg_add_update.log
When you see everything stream by, you will notice the last line telling you what you should run to update it all. Ctrl-C to get out of tail, and
`sed -n "/^Update using /s///p" pkg_add_update.log` > pkg_add_replace.log &
tail -f pkg_add_replace.log
Things like this will stream by:
mplayer-1.0pre7p5 (installing): complete
pkgconfig-0.15.0p0 (extracting): complete
pkgconfig-0.15.0 (deleting): complete
pkgconfig-0.15.0p0 (installing): complete
recode-3.6p2 (extracting): complete
recode-3.6p1 (deleting): complete
recode-3.6p2 (installing): complete
netpbm-9.24p3 (extracting): complete
Occasionally something will fail. One common thing may be failing dependancies because of a package you may have installed from ports. Maybe you compiled in some extra features, or you compiled something that isn’t present in the package repository. In this case just delete that package from your pkg_add_update.log and run the previous command again.
Sometimes a package may not update because of a possibly unsafe command the package instructs the pkg_add utility to run. you can use the “-F update” argument to the pkg_add command, but read the pkg_add man page and understand this and other -F or ‘force’ commands. Only you know your system. You do know your system dont’ you? :-)
Anyway, continue this process until everything seems to be updated minus any packages you may have deleted out of your log previously because you compiled them from ports. You’ll want to update those later too most likely.
It would be a good idea to check at this point if all your package versions match with the ones from the respository. If they do not, then fix that, or if this is acceptable because it is something you compiled from ports, then leave it alone.
Thanks to z0mbix for an awkless uname, and boshuk for a better sed. Both from misc at openbsd dot org