#!/bin/sh
set -e

# script_file=`readlink -f "$0"`
# `dirname "$script_file"`/share/
# we don't really on readlink -f "$0", as we always want to
# point to current/ to get latest update applied immediately.

# on Wayland, this is the first process setting this env variable
if [ -z "$XDG_DATA_DIRS" ]; then
    XDG_DATA_DIRS="/usr/local/share/:/usr/share/"
fi
if [ -n "${XDG_DATA_DIRS##*/snap/communitheme/current/share/*}" ]; then
    XDG_DATA_DIRS=/snap/communitheme/current/share/:"$XDG_DATA_DIRS"
    export XDG_DATA_DIRS
fi

current=$(gsettings get org.gnome.desktop.interface gtk-theme)

if [ $current = "'Communitheme'" ]; then
  GTK2_RC_FILES="/snap/communitheme/current/share/themes/Communitheme/gtk-2.0/gtkrc"
elif [ $current = "'Communitheme-dark'" ]; then
  GTK2_RC_FILES="/snap/communitheme/current/share/themes/Communitheme-dark/gtk-2.0/gtkrc"
else
  GTK2_RC_FILES=""
fi

export GTK2_RC_FILES

gnome-session --session=ubuntu

