#!/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 "Force an update of the workstation"
  exit 0
fi

# Unloading kexec doesn't work, awesome.  Use new -n option to prevent
# auto-update from rebooting
echo "Running auto-updater, please wait..."
/usr/sbin/athena-auto-update -n
if [ $? != 0 ]; then
    echo "Something went wrong.  Press Enter to return to the menu."
    read dummy
    exit 0
fi
ask "The workstation needs to be shut down and rebooted.  Do that now? (y/n) " y
if [ "$answer" = "y" ]; then
    echo "The workstation will now shut down.  You can then turn it back on."
    echo "(Press Enter to continue)"
    ready dummy
    /sbin/poweroff
fi
echo "Please shut down as soon as possible.  Press Enter to return to the menu."
read dummy
