# Reboot script that writes to reboot device (installed in /tmp/reboot)
# Input: 
#   2 - Reboot-requested     - confirm user before reboot
#   3 - Powerdown-requested  - confirm user before soft shutdown
#   4 - Poweroff-requested   - NOT IMPLEMENTED
#   5 - Reboot-forced        - force reboot without user confirmation
#   6 - Powerdown-forced     - force soft-shutdown without user confirmation
#   7 - Poweroff-forced      - NOT IMPLEMENTED

# 
# Calls reboot device driver with 0 (for reboot) or 1 (for soft shutdown)     

sync; sync; sync

. /etc/rc.d/rc.IBM_NS.env

# Confirm with user for inputs 2, 3 - Fill this later
if [ x$1 = x"2" -o x$1 = x"3" ]; then
  echo "Confirm user"
fi   


# for reboot
if [ x$1 = x"2" -o x$1 = x"5" ]; then
  /IBM/bin/gentrap 6 0 /IBM/bin/reboot_IBM_NS
  echo "Do reboot"
  if [ $MODEL_TYPE = "N70" -o $MODEL_TYPE = "BIOS" ]; then
     /IBM/bin/reboot_n70
  else
     echo 0 > /tmp/reboot 
  fi
  exit
fi   

# for soft shutdown
if [ x$1 = x"3" -o x$1 = x"6" -o x$1 = x"7" ]; then
  /IBM/bin/gentrap 6 0 /IBM/bin/reboot_IBM_NS
  echo "Do soft shutdown"
  if [ $MODEL_TYPE = "N70" -o $MODEL_TYPE = "BIOS" ]; then
     # this particular shutdown/kernel combo doesnt do powerdown, 
     #  but halt works OK, so...
     sync
     sleep 1
     umount -a -f -t noproc,nocramfs &
     sleep 2
     [ -f /proc/bus/usb/devices ] && umount /proc/bus/usb
     sync
     /sbin/halt -f -p
     # /sbin/shutdown -n -h now
  else
     echo 1 > /tmp/reboot 
  fi
  exit
fi   


if [ x$1 = x"4" -o -o x$1 = x ]; then
  echo "Invalid Input or No input; Usage is:"
  echo "   reboot_IBM_NS  2 : Confirm user and do reboot"
  echo "   reboot_IBM_NS  3 : Confirm user and do soft shutdown"
  echo "   reboot_IBM_NS  5 : Do reboot"
  echo "   reboot_IBM_NS  6 : Do soft shutdown"
fi   
