#! /bin/sh

PREREQ=""

prereqs()
{
	echo "$PREREQ"
}

case $1 in
prereqs)
	prereqs
	exit 0
	;;
esac

. /scripts/functions-uniklu
. /scripts/functions

chvt 1

[ "$quiet" != "y" ] && log_begin_msg "Initializing loopback network"
rootmnt=/target
# prepare minimal /etc/network/interfaces
  touch ${rootmnt}/etc/network/interfaces
  if [ -e /etc/network/interfaces ]; then
    cp /etc/network/interfaces ${rootmnt}/etc/network/interfaces
  fi
  # ????? ensure eth0 is NOT present (otherwise conflicts with
  # several plugged in usb devices)
  #if grep -q "auto eth0" ${rootmnt}/etc/network/interfaces; then
  #  grep -v eth0 ${rootmnt}/etc/network/interfaces > ${rootmnt}/etc/network/interfaces.tmp
  #  mv ${rootmnt}/etc/network/interfaces.tmp ${rootmnt}/etc/network/interfaces
  #fi
  if ! grep -q "auto eth0" ${rootmnt}/etc/network/interfaces; then
    echo "auto eth0" >> ${rootmnt}/etc/network/interfaces
    echo "iface eth0 inet dhcp" >> ${rootmnt}/etc/network/interfaces
  fi
  if [ -n "$BREAK" ]; then
    panic "after eth0 configuration in /target"
  fi
  # ensure loopback is present
  if grep -q "auto lo" ${rootmnt}/etc/network/interfaces; then
    [ "$quiet" != "y" ] && log_end_msg
  else
    echo "auto lo" >> ${rootmnt}/etc/network/interfaces
    echo "iface lo inet loopback" >> ${rootmnt}/etc/network/interfaces
    [ "$quiet" != "y" ] && log_end_msg
  fi
  if [ -n "$BREAK" ]; then
    panic "after loopback configuration in /target"
  fi
  mv $rootmnt/etc/resolv.conf $rootmnt/etc/resolv.conf.tmp
  cp /etc/resolv.conf $rootmnt/etc/resolv.conf
  chroot $rootmnt /etc/init.d/uniklu-config start
  chmod 644 $rootmnt/etc/init.d/uniklu-config
  rm -f $rootmnt/etc/resolv.conf
  mv $rootmnt/etc/resolv.conf.tmp $rootmnt/etc/resolv.conf
  if [ -n "$BREAK" ]; then
    panic "after uniklu configuration in /target"
  fi

