summaryrefslogtreecommitdiffstats
path: root/core/modules/xorg/data/etc/X11/Xsession
blob: fadc69ba7c7ea94a2b9f4a1b209b648efdc0e7b9 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/ash
#
# /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
}

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

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

internal_errormsg () {
  # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message
  # One big call to message() for the sake of xmessage; if we had two then
  # the user would have dismissed the error we want reported before seeing the
  # request to report it.
  errormsg "$*" \
           "Please report the installed version of the \"x11-common\"" \
           "package and the complete text of this error message to" \
           "<debian-x@lists.debian.org>."
}

# 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"

if [ -d "$SESSIONDIR" ]; then
	for file in $SESSIONDIR/*; do
		. $file || slxlog "xsession" "Xsession: Could not source $file" "$file"
	done
fi

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

# 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 [ -e $HOME/.dmrc ]; then
			SESSION=$(cat $HOME/.dmrc|grep "Session"| cut -d "=" -f2)
		fi
		# somehow .dmrc is cleared when logging in the first time after boot
		if [ -e $HOME/.dmrc.real ]; then
			SESSION=$(cat $HOME/.dmrc.real|grep "Session"| cut -d "=" -f2)
		fi
		[ "x$SESSION" == "xdefault" ] && SESSION="gnome"
		CMD=$(cat /opt/openslx/xsessions/$SESSION.desktop|grep "Exec"| cut -d "=" -f2-99|head -n1)
		exec $CMD
	;;

	*)
		# Specific program was requested.
		STARTUP_FULL_PATH=$(/opt/openslx/bin/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