#!/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

. /usr/share/debathena-recovery-mode-config/require_network.sh

echo "Testing networking, please wait..."
if ! require_network; then 
    echo "Can't verify that networking is available.  If you continue,"
    ask "errors may occur.  Continue? (y/N) " n
    if [ "$answer" = "n" ]; then
	exit 0
    fi
fi

echo "Running auto-updater, please wait..."
/usr/sbin/athena-auto-update -n -v
if [ $? != 0 ]; then
    echo "Something went wrong.  Press Enter to return to the menu."
    read dummy
    exit 0
fi
# We can just return to the menu and resume boot once LP:436936 gets fixed
ask "The workstation needs to be rebooted.  Do that now? (Y/n) " y
if [ "$answer" = "y" ]; then
    /sbin/reboot
fi
echo "Please reboot as soon as possible.  Press Enter to return to the menu."
read dummy
exit 0
