#!/bin/bash
#
# This is not the original gnome-session but a start script
# to install some preconfiguration for GNOME2
# and some variables to check.
#
# For feedback on this script please use
# https://bugzilla.novell.com/
#

# For checks that are SLE-only.
if test "x`head -n 1 /etc/SuSE-brand 2> /dev/null`" != "xopenSUSE"; then
  # openSUSE <= 10.3 and SLED <= 10 modified the user GConf database to change background.
  # New openSUSE obsoletes this mechanism by branding and gnome-wp-list.
  # We still have to detect old modifications in the user database and remove them.
  #
  # This code may disappear after SLED 12:
  OLD_WALLPAPER=$(gconftool-2 --get /desktop/gnome/background/picture_filename 2>/dev/null)
  PICTURE_OPTIONS=$(gconftool-2 --get /desktop/gnome/background/picture_options 2>/dev/null)
  if [ "$PICTURE_OPTIONS" != "none" -a \(\
       "$OLD_WALLPAPER" != "${OLD_WALLPAPER#/usr/share/wallpapers/default}" -o ! -e "$OLD_WALLPAPER" \) ] ; then
          gconftool-2 -u /desktop/gnome/background/picture_filename
          gconftool-2 -u /desktop/gnome/background/picture_options
  fi
fi

# Some actions that are specific to the LiveCD
if [ -e /usr/share/applications/YaST2/live-installer.desktop ] ; then
  # Install the live install desktop icon this way until there is a better
  # solution. The actual files reside in gnome2-SuSE the
  # /usr/share/applications/YaST2/live-installer.desktop exists on a live
  # install system
  if [ -e .config/user-dirs.dirs ]; then
    . .config/user-dirs.dirs
  else
    XDG_DESKTOP_DIR="$HOME/Desktop"
  fi
  mkdir -p $XDG_DESKTOP_DIR
  cp -u /usr/share/applications/YaST2/live-installer.desktop $XDG_DESKTOP_DIR/

  # setup live install to not have a lock-enabled screensaver
  gconftool-2 --set /apps/gnome-screensaver/lock_enabled --type=bool "false"

  # setup live install to not start beagled
  if [ -e /etc/xdg/autostart/beagled-autostart.desktop ] ; then
    mkdir -p ~/.config/autostart
	cp /etc/xdg/autostart/beagled-autostart.desktop ~/.config/autostart
	echo "X-GNOME-Autostart-enabled=false" >> ~/.config/autostart/beagled-autostart.desktop
  fi

  # setup live install to not start updater-applet
  if [ -e /usr/share/gnome/autostart/gpk-update-icon.desktop ] ; then
    mkdir -p ~/.config/autostart
	cp /usr/share/gnome/autostart/gpk-update-icon.desktop ~/.config/autostart
	echo "X-GNOME-Autostart-enabled=false" >> ~/.config/autostart/gpk-update-icon.desktop
  fi
fi

# Uncomment after SLED12, remove after SLED14:
#rm -f ~/.skel/gnome2-run ~/.skel/gnome2-run-9.2 ~/.skel/sled10-run

# TODO: look for a better fix for 11.1
export SDL_AUDIODRIVER=pulse
if test -f /etc/alsa-pulse.conf ; then
  export ALSA_CONFIG_PATH=/etc/alsa-pulse.conf
fi

exec /usr/bin/gnome-session
