#!/bin/tcsh -f
# JLdL 19May08.
#
# This script does a chroot into the template node, in a way that allows
# _ one to upgrade it; 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/
#
# Do the chroot, running a bash shell, since the
# _ node does not have tcsh installed.
chroot root.$1 /bin/bash
#
# 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
