Friday, January 29, 2010

Switch distribution version in Debian

Use testing version of Debian as my primary working environment. But some softwares are available only in sid version, and bugs are fixed in sid firstly. So switching between testing and sid is routine. A simple script as follow is used to simplify/accelerate the operation.

#!/bin/sh

prog=$(basename $0)

usage()
{
echo "Usage: $prog <testing|sid>"
}

current_dist()
{
if grep sid /etc/apt/sources.list > /dev/null; then
echo sid
else
echo testing
fi
}

if [ $# -ne 1 ]; then
usage
exit -1
fi

tdist=$1
if [ $tdist != "sid" -a $tdist != "testing" ]; then
usage
exit -1
fi

cdist=$(current_dist)
if [ "$tdist" != "$cdist" ]; then
cp /etc/apt/sources.list.$tdist /etc/apt/sources.list
mv /var/lib/apt/lists /var/lib/apt/lists.$cdist
if [ -d /var/lib/apt/lists.$tdist ]; then
mv /var/lib/apt/lists.$tdist /var/lib/apt/lists
fi
fi

apt-get update

No comments: