#!/bin/bash

GEOMETRY="/tmp/.cocon.geometry"
CNFFILE="/tmp/.cocon.cnf"

if [ -e $CNFFILE ];
then
  . $CNFFILE
fi


# first, copy settings from skel.
cp -R /etc/skel/.config/ /home/xuser
cp /etc/skel/.profile /home/xuser
cp /etc/skel/.xinitrc /home/xuser 



# Workaround for graphics chipset bugs
# ( Userspace: not root )

# Workaround chips for broken X.org driver
#  (Currently ATI, Savage, Siliconmotion, Neomagic.
#   Almost these chips can display 24-bit color depth.)
if [ "` lsmod | grep -E 'radeon|savage|atyfb|sm7xx|neofb|i915'`" ];
then
  X_OPTION="-- -depth 24"
fi


if [ `echo $COCON_DEBUG` ];
then
  echo "DEBUG: before X. X_OPTION is $X_OPTION ."
  /bin/sh
fi

# opencocon userland startx
startx $X_OPTION
retr=$?

echo "X.org return: $retr"

if [ $retr -ne 0 ];
then
  # Error on wakeup X
  dialog --msgbox "Xorg initalize was failed. please try 'forcefb1', 'forcefb2' and 'forcefb3' option on boot loader." 20 60
  echo "To reboot, input 'exit'."
  /bin/sh
  exit 1
fi

exit 0
