Updating and Maintaining Ports and Sources

We will now need to update ports then sources using the procedure below. To update ports for the very first time just run the following command:


# portsnap fetch && portsnap extract

to update ports thereafter just run


# portsnap fetch && portsnap update

You can also have ports updated via cron:


0 3 * * * root /usr/sbin/portsnap -I cron update && pkg_version -vIL=

You will no longer need to install subversion as svnlite is already installed into the FreeBSD base system.

Deleting the current ports and sources

First lets get rid of the current /usr/src:


# rm -dfr /usr/src
# mkdir /usr/src

Now we need to checkout sources using the following commands. If you are using FreeBSD 10 the commands shown below will work fine.


# cd /usr/src
# rm -dfr *
# svnlite checkout https://svn.FreeBSD.org/base/stable/11 /usr/src

Please DO NOT continue until at least the sources are updated via svn

Keeping up to date on your ports and sources is important. Updating sources helps your system keep up with the latest updates when you run you next make buildkernel. This is also helpful when you are upgrading. Upgrades don’t happen quite that often but it is a good idea to update them from time to time. Updating your ports is most important! If you don’t update ports, you are or could be installing an outdated port. I put this is a daily script in my ~user/bin folder called daily.sh. The command you use to update ports is


# cd /usr/ports
# svn checkout https://svn0.us-east.FreeBSD.org/ports/head /usr/ports

One good thing to start with is when you’re running scripts, give them good names so you don’t forget what they have in them. So if you run a script hourly, you can call it hourly.sh and so on. I have a daily script that runs twice a day that runs a bunch of different things:


#!/bin/sh
# Update the time to the MIT Time Server
/usr/sbin/ntpdate time.mit.edu
# updates your headers when you upgrade ClamAV or SpamAssassin
/usr/local/bin/setuidgid qscand /var/qmail/bin/qmail-scanner-queue.pl -z
# Update sources
/usr/local/bin/cvsup -g -L 2 /root/stable-supfile
# Update Ports
/usr/local/bin/cvsup -g -L 2 /root/ports-supfile
# Backup /usr/local/etc
/bin/rm /home/wolson/archives/etc.tgz
/usr/bin/tar cvzf /home/wolson/archives/etc.tgz /usr/local/etc

Just read the notes and you should be able to figure out what that script does. That’s my daily.sh script

I would definitely recommend running a backup of vpopmail if you have a test or a backup box running. Here is the URL for it:

http://freebsdrocks.net:8080/freebsdrocks.net/other/how-to-backup-from-one-server-to-another-using-rsync-ssh

Maintaining your Ports

It is a good idea to keep your ports system up to date. There really isn’t an easy way to do this via a script so I would recommend you do this kind of thing once a week or so. If you wait a month or two or even more, you’ll have a lot of fun doing a bunch of portupgrades. If you run the following command, it will tell you what needs updating:


# pkg version -vL=

Here is my output:


linux_base-8-8.0_14 < needs updating (port has 8.0_16)
portaudit-0.5.10 < needs updating (port has 0.5.11)

Generally the way we want top do this is via portupgrade. If you haven’t installed it yet, just do:


# cd /usr/ports/ports-mgmt/portupgrade
# make install clean

If I want to upgrade linux_base-8-8.0_14 and all it's upward-recursive and downward recursive dependencies, this is what I would do:


# portupgrade -rR linux_base-8-8.0_14


I WOULD NOT RECOMMEND THIS FOR A PRODUCTION MACHINE!!!

Here's how to upgrade all packages, downwards-recursive AND upwards-recursive, and clean up obsolete shared libraries:


# portupgrade -urRa

That’s basically it to updating and managing ports!