#!/bin/sh

source GoboPath

operation="$1"
action="$2"

# Check if we are running from USB or CD
LIVECD_DEVICE=$(basename $(grep "/Mount/.Pivot/Mount/CD-ROM" /proc/mounts | awk {'print $1'}))

case "$operation" in
   [sS]tart)
      # Kill all processes
      killall5

      # Unmount file systems
      cat $goboStatus/mounts | sort -r | awk {'print $2'} | while read mp
      do
         umount ${mp} 2> /dev/null
      done

      # Quiet the kernel
      echo 1 > $goboStatus/sys/kernel/printk

      # Eject the CD from the tray
      if [ "$LIVECD_DEVICE" = "sr0" ]
      then
         eject
      fi

      $goboExecutables/BootDriver $action 2> /dev/null
      ;;
   *)
      ;;
esac
