#!/bin/sh

# Blatantly stolen from the installer
ask() {
  answer=''
  while [ y != "$answer" -a n != "$answer" ]; do
    echo -n "$1"
    read answer
    [ Y = answer ] && answer=y
    [ N = answer ] && answer=n
    [ -z "$answer" ] && answer=$2
  done
}

if [ "$1" = "test" ]; then
  echo "Reboot the workstation (bypassing kexec)"
  exit 0
fi
ask "Are you sure you want to reboot? (y/n) " y
if [ "$answer" = "y" ]; then
    echo "OK, rebooting..."
    [ -x "/sbin/kexec" ] && /sbin/kexec -u
    /sbin/reboot
fi
echo "OK, cancelled.  Press Enter to return to the menu."
read dummy
