Keeping unstable machines up to date easily.

Posted by Steve on Tue 16 Nov 2004 at 14:46

If you're running the Debian Unstable distribution you will probably want to keep it fairly current, so that you have the latest and greatest packages available to use. Running automated upgrades could be dangerous, but there is a simple way to keep your machine ready for updating at all times.

Because updating systems is usually a simple matter of running two commands people can be tempted to automate this.

The two commands used are:

apt-get update
apt-get upgrade


The first updates your systems package lists, so that apt can determine which packages on your system may be upgraded. The second actually performs the update.

Adding these two commands to a cron job (something that can be scheduled to occur at regular intervals with cron) is a tempting idea.

However it is a dangerous one. As the upgrade happens blindly you might miss out on important notes and questions.

An ideal compromise is to download the package lists and the packages that are available - but not actually install them.

For those users on broadband it makes sense to do this overnight. Every day your machine will download the packages, and when you are ready you simply run:

apt-get upgrade


This will actually do the upgrade live for you, without needing to actually download anything. Any questions that are asked will be done in front of you, and any important notes will be immediately visible.

To do this is a simple matter of placing a script in the directory /etc/cron.daily. The scripts in this directory are run automatically once a day, so it's a perfect location for us.

Create a script /etc/cron.daily/update-apt with the following contents:
#!/bin/sh
#
# Update APT's local packages, making them ready for
# upgrading at a later date.
#

# Clean packages, and download the latest lists
/usr/bin/apt-get clean
/usr/bin/apt-get update

# Now download the packages, but don't install them.
/usr/bin/apt-get --download-only --yes upgrade


Don't forget to make the script executable by running:
chmod 755 /etc/cron.daily/update-apt


Now your system should be ready, and tomorrow you should find that running apt-get upgrade takes only a short amount of time, as all the pending packages have been downloaded already.

This article can be found online at the Debian Administration website at the following bookmarkable URL:

This article is copyright 2004 Steve - please ask for permission to republish or translate.