#!/bin/bash -ex

# Last changed Fri Dec  5 16:01:12 EST 2008

trap '
SAVEDSTATUS=$?
set +x
if [ x$CLEANEXIT = x ]
then
	echo "$0: ERROR Unexpected exit with return value of $SAVEDSTATUS"
	exit $SAVEDSTATUS
fi' EXIT

#-----

# Add new software respositories

if [ ! -e /etc/apt/sources.list.bak ]
then
	cp -p /etc/apt/sources.list{,.bak}
fi

for i in 'deb http://cran.R-project.org/bin/linux/ubuntu intrepid/' \
	'deb http://packages.medibuntu.org/ intrepid free non-free' \
	'deb-src http://packages.medibuntu.org/ intrepid free non-free'
do
	if grep -q "^$i\$" /etc/apt/sources.list
	then
		:
	else
		echo "$i" >> /etc/apt/sources.list
	fi
done

sed \
	-e 's|^# deb http://archive.canonical.com/ubuntu intrepid partner$|deb http://archive.canonical.com/ubuntu intrepid partner|g' \
	-e 's|^# deb-src http://archive.canonical.com/ubuntu intrepid partner$|deb-src http://archive.canonical.com/ubuntu intrepid partner|g' \
	< /etc/apt/sources.list > /etc/apt/sources.list.tmp

mv /etc/apt/sources.list.tmp /etc/apt/sources.list

# Add PGP keys for R packages and acroread

gpg --keyserver subkeys.pgp.net --recv-key E2A11821
gpg -a --export E2A11821 | apt-key add -

wget -q http://packages.medibuntu.org/medibuntu-key.gpg -O - | apt-key add -

# Get updates since the cd

apt-get -y update
apt-get -y dist-upgrade

#-----

CLEANEXIT=1
exit 0

