#! /bin/sh

# prepare the base system on the install client

# ftp and http needs resolv.conf in chroot environment, /etc/hosts is useful
# think about using fcopy for these two files
[ -f /tmp/etc/resolv.conf ] && cp /tmp/etc/resolv.conf $FAI_ROOT/etc
[ -f /etc/hosts ] && cp /etc/hosts $FAI_ROOT/etc
# set hostname in $FAI_ROOT
echo -e "$IPADDR\t$HOSTNAME.$DOMAIN $HOSTNAME" >>$FAI_ROOT/etc/hosts
echo $HOSTNAME >$FAI_ROOT/etc/hostname
cp /etc/apt/* $FAI_ROOT/etc/apt/
# some packages must access /proc even in chroot environment
mount -t proc proc $FAI_ROOT/proc

# if libc is upgraded init u is called in chroot environment and
# then init will eat up much cpu time
fai-divert -a /sbin/init /usr/sbin/liloconfig

$ROOTCMD apt-get update
$ROOTCMD apt-get check
[ $? -ne 0 ] && $ROOTCMD apt-get -f -y install </dev/null 
$ROOTCMD dpkg -C
[ $? -ne 0 ] && yes '' | $ROOTCMD dpkg --configure -a 
$ROOTCMD apt-get -f -y dist-upgrade </dev/null
# update dpkg info which packages are available
$ROOTCMD apt-cache dumpavail > $FAI_ROOT/tmp/dumpavail
$ROOTCMD dpkg --update-avail /tmp/dumpavail
rm -f $FAI_ROOT/tmp/dumpavail

# fake some more programs
fai-divert -a /etc/init.d/nis /sbin/start-stop-daemon
cp /sbin/start-stop-daemon $FAI_ROOT/sbin/start-stop-daemon
