#!/bin/bash
# Author: Steven Shiau <steven _at_ nchc org tw>
# License: GPL

# Load DRBL setting and functions
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/opt/drbl/}"

. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
. $DRBL_SCRIPT_PATH/conf/drbl-ocs.conf
. $DRBL_SCRIPT_PATH/sbin/ocs-functions

# 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 Forcevideo-drbl-live\" 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) Forcevideo-drbl-live --skip-start-x # 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
} # end of config_X

#
if ! type X &>/dev/null; then
  echo "X was not found! Skip configuring X."
  exit 3
fi

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