Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Safe upgrade of a debian system
#!/bin/sh
OLDDIST=lenny
NEWDIST=squeeze
BACKUP_DIR="/var/tmp/backup.$OLDDIST"
echo "+ Create backup directory"
mkdir -p "$BACKUP_DIR"
echo "+ Backup system config directories"
rsync -ac /etc /var/lib/dpkg /var/lib/apt/extended_states "$BACKUP_DIR"
dpkg --get-selections "*" > "$BACKUP_DIR/curr-pkgs.txt"
echo "+ Check aptitude in visual mode and press 'g' [ENTER]"
read
#aptitude
echo "+ Check apt preferences (pinnged packages)"
if [ -e "/etc/apt/preferences" ]; then
echo "Check that you haven't pinned any packages [ENTER]"
read
fi
echo "+ Check dpkg audit log"
dpkg --audit
if [ "$?" != "0" ]; then
echo "Something failed with dpkg --audit ? "
exit 1
fi
echo "+ Search packages on hold"
#aptitude search "~ahold"
dpkg --get-selections | grep hold > "$BACKUP_DIR/pkgs-on-hold.txt"
if [ "$(grep proposed-updates /etc/apt/sources.list)" != "" ]; then
echo "***** You should remove proposed-updates from your sources.list"
exit 2
fi
if [ "$(grep backports /etc/apt/sources.list)" != "" ]; then
echo "***** Backports is enabled. Remove it."
exit 3
fi
echo "+ Update the sources.list to point to $NEWDIST [ENTER]"
read
echo "+ Update apt database..."
apt-get update
echo "+ Disk space check..."
apt-get -o APT::Get::Trivial-Only=true dist-upgrade
echo "+ Minimal system upgrade [ENTER]"
read
apt-get upgrade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment