#!/bin/bash
# Load functions
. /opt/drbl/sbin/drbl-conf-functions
. /opt/drbl/sbin/ocs-functions
. /opt/drbl/conf/drbl-ocs.conf
# load keymap if it exists
[ -e /etc/drbl/drbl-live.conf ] && . /etc/drbl/drbl-live.conf

#
config_X() {
  local action
  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
  echo "///NOTE/// Later we will enter graphical environment if you choose '0'. However, if graphical environment (X-window) fails to start, you can:"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo "Run \"sudo /etc/init.d/Forcevideo-drbl-live restart\" to configure it again. Choose 1024x768, 800x600 or 640x480 as your resolution and the driver for your VGA card, etc. Most of the time you can accept the default values if you have no idea about them."
  echo "If failing to enter graphical environment, and it does not return to text mode, you can reboot again, and choose '1' here to config X manually."
  echo "------------------------------------------"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
  echo "Which mode do you prefer ?"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo "(0) Continue to start X to use DRBL live"
  echo "(1) Run 'Forcevideo-drbl-live' to config X manually"
  echo "(2) Enter command line prompt to config X by yourself"
  echo -n "[0] "
  read action
  case "$action" in
    1) /etc/init.d/Forcevideo-drbl-live --skip-start-x restart # This process is still in rc*.d, skip start x
       ;;
    2) echo "Run \"exit\" to back to main menu when everything is done!"
       /bin/bash;;
    *) true;
  esac
}

if ! grep -qE "drbl_live_batch" /proc/cmdline; then
  echo "*****************************************************"
  config_X
fi
