#!/bin/ash

# TODO implement an rc.lessdisks.d directory structure

# copyright 2004 vagrant@freegeek.org, distributed under the terms of the
# GNU General Public License version 2 or any later version.

export PATH="/usr/local/bin:/usr/local/sbin:$PATH"

# run crucial scripts...
if [ -z "$(mount | egrep devfs)" ]; then
  mount -t devfs devfs /dev
fi
/etc/init.d/devfsd start
/etc/init.d/lessdisks
if [ -r /etc/lessdisks/init.config ]; then
  . /etc/lessdisks/init.config
fi
if [ "yes" = "$syslogging" ]; then
  /etc/init.d/sysklogd start
  /etc/init.d/klogd start
fi

# call the script as it was meant to be....
# possible scripts would be ones for updating the server image,
# updating a clone, installing a new clone, or installing a new image.
# these scripts must be called from the bootpromt

echo "starting shell, probably on tty2"
/usr/bin/openvt /bin/ash

# time will display the length of time a script runs.
# install the "time" package to use it.  it is also available
# as a bash builtin, but we like ash...
if [ -x /usr/bin/time ]
then
  usetime=/usr/bin/time
fi

case $1 in
  # compatibility with old freegeek disks
  install-clone|cloner)
    shift
    $usetime /usr/bin/lessdisks-cloner $@ ;;
  *) $usetime $@ ;;
esac

echo "install finished."

# avoid frightening but harmless kernel panic when init ends...
while /bin/true
do
  echo "eject the floppy if it's still in the floppy drive."
  echo "press the reset or power button, and restart the computer"
  echo ""
  read pause
done
