#!/bin/tcsh -f
# JLdL 19May08.
#
# This script updates the template node, using chroot in a way that
# _ allows the upgrade; it requires one argument, which can be one of
# _ "sarge-i386", "etch-i386" or "etch-amd64".
#
# Verify the required argument.
if ( "$1" != sarge-i386 && "$1" != etch-i386 && "$1" != etch-amd64 ) then
    echo `basename $0`: requires one argument: sarge-i386, etch-i386 or etch-amd64
    exit
endif
#
# Copy a few files into the node, to enable it to
# _ operate within the local network.
cp -pf hosts.TEMP root.$1/etc/hosts
cp -pf sources.list.TEMP.$1 root.$1/etc/apt/sources.list
#
# Include a policy-rc.d file, to avoid trouble with
# _ the daemons on the server.
cp -pf policy-rc.d.TEMP root.$1/usr/sbin/policy-rc.d
#
# Give /proc access to the node.
mount --bind /proc root.$1/proc/
#
# Update the node via chroot.
chroot root.$1 /usr/bin/apt-get update
#
# Upgrade the node via chroot.
chroot root.$1 /usr/bin/apt-get dist-upgrade
#
# Undo the /proc access.
umount root.$1/proc/
#
# Return the original files to their places.
cp -pf hosts.ORIG root.$1/etc/hosts
cp -pf sources.list.ORIG.$1 root.$1/etc/apt/sources.list
#
# Remove the policy-rc.d script.
rm -f root.$1/usr/sbin/policy-rc.d
