summaryrefslogblamecommitdiffstats
path: root/core/modules/xorg/data/etc/X11/Xsession
blob: 0f9f051dd534a95cf2e701237b9c715aa76f6a54 (plain) (tree)
1
2
3
4
5
6
7
8
           





                                                                
                                                                                                  












                                                                          





                          

                                                                     
 



















                                                                                                  



                                                                                                                                                           





                                                              
                             


                                          


            




















                                                                                       

                                                                                         

                                                                                    

                                                                                              

                                                                
                                                                                                                    




                                                 
                                                               














                                                                                                 
#!/bin/bash
#
# /etc/X11/Xsession
#
# Xsession is executed to start the user's session (as the user)
# 

export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/openslx/sbin:/opt/openslx/bin"

PROGNAME=Xsession

message () {
  # pretty-print messages of arbitrary length; use xmessage if it
  # is available and $DISPLAY is set
  MESSAGE="$PROGNAME: $*"
  echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2
  if [ -n "$DISPLAY" ] && which xmessage > /dev/null 2>&1; then
    echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} | xmessage -center -file -
  fi
}

errormsg () {
  # exit script with error
  message "$*"
  exit 1
}

# Make sure we source the global profile - needed for ssh-agent, etc.
[ -e "/etc/profile" ] && . "/etc/profile"

# New kid on the block
OPTIONFILE=/etc/X11/Xsession.options
OPTIONS="$(
	if [ -r "$OPTIONFILE" ]; then
		cat "$OPTIONFILE"
	fi
	if [ -d /etc/X11/Xsession.options.d ]; then
		run-parts --list --regex '\.conf$' /etc/X11/Xsession.options.d | xargs -d '\n' cat
	fi
)"

has_option() {
	# Ensure that a later no-foo overrides an earlier foo
	if [ "$(echo "$OPTIONS" | grep -Eo "^(no-)?$1\>" | tail -n 1)" = "$1" ]; then
		return 0
	else
		return 1
	fi
}

# Workaround to start Xsession. The original Xsession script includes error handling functionality and sources other scrips from the Xsession.d/ directory.

SESSIONDIR="/etc/X11/Xsession.d"

tmpfile="$( mktemp "/tmp/xsession-log-$( date +%s )-XXXXXX" )"
if [ -n "$tmpfile" ]; then
	exec &> "$tmpfile"
	set -x
fi

if [ -d "$SESSIONDIR" ]; then
	for file in "$SESSIONDIR"/*; do
		[ -f "$file" ] || continue
		. "$file"
	done
fi

# start selected session
case "$1" in
	failsafe)
		# Failsafe session was requested.
		if [ -e /usr/bin/xterm ]; then
			if [ -x /usr/bin/xterm ]; then
				exec xterm -geometry +1+1
			else
				# fatal error
				errormsg "unable to launch failsafe X session ---" \
					"x-terminal-emulator not executable; aborting."
			fi
		else
			# fatal error
			errormsg "unable to launch failsafe X session ---" \
				"x-terminal-emulator not found; aborting."
		fi
	;;
	default)
		# Specific program was requested.
		SESSION="default"
		if [ -s "$HOME/.dmrc" ]; then
			SESSION=$( < "$HOME/.dmrc"  grep -m1 "Session" | cut -d "=" -f2 )
		fi
		# somehow .dmrc is cleared when logging in the first time after boot
		if [ -s "$HOME/.dmrc.real" ]; then
			SESSION=$( < "$HOME/.dmrc.real"  grep -m1 "Session" | cut -d "=" -f2 )
		fi
		[ "x$SESSION" == "xdefault" ] && SESSION="gnome"
		CMD=$( < "/opt/openslx/xsessions/$SESSION.desktop"  grep -m1 "Exec" | cut -d "=" -f2-99 | head -n1 )
		exec $CMD
	;;

	*)
		# Specific program was requested.
		STARTUP_FULL_PATH=$( which "${1%% *}" || true )
		if [ -n "$STARTUP_FULL_PATH" ] && [ -e "$STARTUP_FULL_PATH" ]; then
			if [ -x "$STARTUP_FULL_PATH" ]; then
				exec $1
			else
				message "unable to launch \"$1\" X session ---" \
					"\"$1\" not executable; falling back to default session."
			fi
		else
			message "unable to launch \"$1\" X session ---" \
				"\"$1\" not found; falling back to default session."
		fi
	;;

esac