#!/bin/bash
# Load gparted live functions
. /usr/share/gparted/bin/gl-functions

#
start_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\" 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 GParted automatically"
  echo "(1) Run 'Forcevideo' to config X manually"
  echo "(2) Enter command line prompt"
  echo -n "[0] "
  read action
  case "$action" in
    1) Forcevideo --skip-start-x  # This process is still in rc2.d, skip start x
       ;;
    2) echo "Run \"exit\" to back to main menu when everything is done!"
       /bin/bash;;
    *) true;
  esac
}

if ! grep -qE "gl_batch" /proc/cmdline; then
  echo "*****************************************************"
  start_X
fi
