#!/bin/bash
set -e
set -x
export LC_ALL=C

if [ -d fs ]; then sudo rm -fr fs; fi
if [ "$debian_mirror" = "" ]; then
    debian_mirror="http://apt-proxy.kurp.hut.fi:9999/debian"
fi
sudo debootstrap etch fs $debian_mirror
remove="apt-utils aptitude bsdmainutils cpio cron dmidecode dselect ed groff-base info iptables"
remove+=" klogd laptop-detect libconsole libdb4.4 libgdbm3 liblocale-gettext-perl libncursesw5"
remove+=" libnewt0.52 libpopt0 libsasl2 libtext-charwidth-perl libtext-iconv-perl libtext-wrapi18n-perl"
remove+=" logrotate man-db manpages nano netcat procps sysklogd tasksel tasksel-data traceroute"
remove+=" vim-common vim-tiny wget whiptail"
sudo chroot fs apt-get -y remove $remove
sudo chroot fs dpkg -P $remove
add="debconf-english libedit2 libkrb53 openssh-client openssh-server"
add+=" grub ifupdown dhcp3-client"
add+=" linux-image-2.6-486"
echo -e "n\nn" | sudo chroot fs apt-get --force-yes -y install $add
sudo tee fs/etc/kernel-img.conf <<EOF
do_symlinks = yes
relative_links = yes
do_bootloader = no
do_bootfloppy = no
do_initrd = yes
link_in_boot = no
postinst_hook = /usr/sbin/update-grub
postrm_hook   = /usr/sbin/update-grub
EOF
