#!/bin/sh

# Default VNC Server (Virtual-Mode) start-up script.
#
# This file is automatically generated. DO NOT EDIT.
# To override settings in this file, create or edit /etc/vnc/xstartup.custom
# and make it executable. This will then be executed instead of this file.

# The following keymap code is designed to support VNC Viewers with US and
# Western European keyboards. If you expect VNC Viewers to have different
# keyboards, override this file as described above, making sure to preserve all
# this code. You can then change the variable assignment appropriately. For
# example, setting:
#
# targetkbMap="pc+cz+ru:2+gr:3+fr:4"
#
# ...provides support for Czech, Russian, Greek and French keyboards.
targetkbMap="pc+us+us(intl):2"
if which setxkbmap > /dev/null 2>&1 && \
  which sed > /dev/null 2>&1 && \
  which xkbcomp > /dev/null 2>&1 ; then
  setxkbmap -symbols "$targetkbMap" -print | sed -n '/xkb_keymap {/,$p' | xkbcomp - $DISPLAY
fi
# End of keymap code

[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey

if [ -x /usr/bin/gnome-session -a -z "$VNC_SYSTEMXORG" ]; then
  # Some gnome session types won't work with Xvnc, try to pick a sensible
  # default.
  for SESSION in "ubuntu-2d" "2d-gnome" "gnome-classic" "gnome-fallback"; do
    if [ -f /usr/share/gnome-session/sessions/$SESSION.session ]; then
      DESKTOP_SESSION=$SESSION; export DESKTOP_SESSION
      GDMSESSION=$SESSION; export GDMSESSION
      STARTUP="/usr/bin/gnome-session --session=$SESSION"; export STARTUP
    fi
  done
fi

if [ -f /usr/share/gnome-session/sessions/ubuntu.session -a -n "$VNC_SYSTEMXORG" ]; then
    GNOME_SHELL_SESSION_MODE=ubuntu; export GNOME_SHELL_SESSION_MODE
fi

unset SESSIONBIN
XTERM_COMMAND="xterm -geometry 80x24+10+10 -ls"

if   [ -x /etc/X11/Xsession ]; then SESSIONBIN="/etc/X11/Xsession"
elif [ -x /etc/X11/xdm/Xsession ]; then SESSIONBIN="/etc/X11/xdm/Xsession"
elif [ -x /etc/X11/xinit/Xsession ]; then 
  SESSIONBIN="/etc/X11/xinit/Xsession"
  # Use gnome as a sensible default in SystemXorg mode on RedHat based systems
  if [ ! -x "$HOME/.xsession" -a ! -x "$HOME/.Xclients" -a \
      "$VNC_SYSTEMXORG" -a -e /etc/redhat-release -a -x /usr/bin/gnome-session ]; then
    SESSIONBIN="$SESSIONBIN gnome"
  fi
elif [ -x /etc/X11/gdm/Xsession ]; then SESSIONBIN="/etc/X11/gdm/Xsession gnome-session"
elif [ -x /etc/gdm/Xsession ]; then SESSIONBIN="/etc/gdm/Xsession gnome-session"
elif [ -x /etc/kde/kdm/Xsession ]; then SESSIONBIN="/etc/kde/kdm/Xsession"
elif [ -x /usr/dt/bin/Xsession ]; then
  XSTATION=1
  DTXSERVERLOCATION=local
  export XSTATION DTXSERVERLOCATION
  SESSIONBIN="/usr/dt/bin/Xsession"
elif [ -x /usr/dt/bin/dtsession ]; then SESSIONBIN="/usr/dt/bin/dtsession"
elif which twm > /dev/null 2>&1; then
  $XTERM_COMMAND &
  SESSIONBIN="twm"
fi

if [ "x${SESSIONBIN}" = "x" ]; then
  echo "No session located; just starting a terminal"
  $XTERM_COMMAND
  echo "Terminal closed with return code $?"
else
  echo "Starting session: $SESSIONBIN"
  $SESSIONBIN
  echo "Session terminated with return code $?"
fi
