summaryrefslogtreecommitdiffstats
path: root/core/modules/xorg/data/etc/X11/Xsession
blob: 33a003ac21a34100e2fe4a6811953caaaad87977 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/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:/sbin:/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"

# 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