Aug 052000

Keeping up with the ports – pkg_version

Since this article was written the portupgrade tool was written. I think you should use that tool.

David W. Chapman Jr. wrote in with this article about pkg_version.  Thanks.

This article will show you how to keep up to date with your installed ports versus the latest source that you’ve cvsuped to them.




cvsup and cvsuping your ports


From the man page:

The pkg_version command is used to produce a report of non-base software packages installed using the pkg_add(1) command. Version numbers are compared against an index file, to see which packages might need updating.

Basically this program will tell you how your currently installed port version numbers compare to what is in your /usr/ports source tree.  Just running the command pkg_version will display the port name and whether its equal to the current cvsup version, less than the current version, or unknown

pkg_version -v will display some information about the version information for both currently installed ports and what you have in your ports source tree

pkg_version -l'flag' will limit the output to certain flags, ie.

  • pkg_version -l '<' will display all ports that are not up to date
  • pkg_version -l'=' will display all up to date ports

pkg_version -c will display the required commands to upgrade all installed ports to the current version. (see below for a note on the -c option).

Putting these together you can run pkg_version -vl'<' to check your version numbers against what’s in the ports tree to see what needs to be upgraded and pkg_version -cv'<' to display the commands needed to upgrade your ports.  Taking this one step further you could pipe the last command to a shell interpreter to do it for you. pkg_version -cv'<' | sh does just that.  Note that some ports might fail during this procedure, you should manually take care of upgrading those ports and then run this procedure again.

Note that this method is not recommended.  The recommended way of doing this is to redirect the output of pkg_version -cv'<' to a file and edit the contents so that it contains the ports you wish to update.  For example pkg_version -cv'<' >, you would then edit the file and delete the ports you wish to not update and run the file, sh

16 March 2001 – David wrote in with an update:

You now have to run:

pkg_version -cl'<' | grep -v echo | grep -v exit | sh

to pipe it to sh.  This changed in 4.3.  Apparently they don’t think you should pipe it to the shell, which can have its problems.

Be wary of -c (added on 7 August 2000)

Mark Ovens (always good to see people from reading the Diary) wrote in to tell me that there is a bug with the -c option:

It may be a good idea to mention in the article about the use of pkg_version(1) that there is a bug with the “-c” option that gets the port to make wrong if a port doesn’t exist, e.g.:

#  mozilla-fonts
#  unknown in index
cd /usr/ports/lang/modula-3-lib
make && pkg_delete -f mozilla-fonts-1.0
make install

(note that this was before mozilla-fonts was added to the ports tree)

There is a PR for it, bin/18176, which was committed and MFC’d today.

Thanks Mark.

  2 Responses to “Keeping up with the ports – pkg_version”

  1. in the article:

    The recommended way of doing this is to redirect the output of pkg_version -cv'<‘ to a file and edit the contents so that it contains the ports you wish to update.

    this returns an invalid option error. the correct way to do this is with pkg_version -cvl'<‘

    the "l" option tells pkg_version to limit output to packages with the status flag within the quotes, in this case ‘<‘