#!/bin/sh -e
# vim:et

# WARNING - little error checking.  See chroot/README

# builds a stable chroot in /usr/local/chroot/stable
# 1. fetches potato base2_2.tgz.  Uses existing one if it's
#    in /usr/local/chroot.
# 2. untars it in /usr/local/chroot/stable/	 
#      - this must be done as root.  wget the base2_2.tgz as non-root
#      first if you like.
#	   - expects target directory to be clean
# 3. copies over some config files from the base install
# 4. puts you in the chroot so you can update it to current potato
#      - you'll want to "apt-get clean" after updating

CHROOT=/usr/local/chroot/stable
if [ ! -e $CHROOT ] ; then mkdir -p $CHROOT; fi
cd $CHROOT

BASE=base2_2.tgz
ARCH=`dpkg --print-installation-architecture`

echo ..getting $BASE
if [ ! -e ../$BASE ] ; then
	wget http://http.us.debian.org/debian/dists/stable/main/disks-$ARCH/current/base2_2.tgz
	mv $BASE ..
fi
echo -n ..untarring
tar zxf ../$BASE
echo .

echo ..copying over some /etc files from base
cp \
	/etc/fstab \
	/etc/group \
	/etc/host.conf \
	/etc/hostname \
	/etc/hosts \
	/etc/hosts.allow \
	/etc/hosts.deny \
	/etc/mailname \
	/etc/nsswitch.conf \
	/etc/passwd \
	/etc/resolv.conf \
	/etc/services \
	/etc/shadow \
	/etc/sudoers \
	/etc/timezone \
	etc/

cp /usr/doc/sbuild/configs/ref-* $CHROOT/..

cat <<EOF

..do this manually once in the chroot (i.e. now..)
dpkg --purge lilo
apt-get update
yes '' | apt-get -y install build-essential dpkg-dev fakeroot ssmtp sudo

You may need a few iterations of "dpkg --configure -a" and the above
if the upgrade doesn't go well.

EOF

mount proc -t proc $CHROOT/proc
chroot $CHROOT bin/sh
umount $CHROOT/proc

