]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - debian/lightdm-session
Load all users only when really needed
[sojka/lightdm.git] / debian / lightdm-session
1 #!/bin/bash
2 #
3 # LightDM wrapper to run around X sessions.
4
5 echo "Running X session wrapper"
6
7 message () {
8   # pretty-print messages of arbitrary length; use xmessage if it
9   # is available and $DISPLAY is set
10   MESSAGE="$PROGNAME: $*"
11   echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2
12   if [ -n "$DISPLAY" ] && which xmessage > /dev/null 2>&1; then
13     echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} | xmessage -center -file -
14   fi
15 }
16
17 errormsg () {
18   # exit script with error
19   message "$*"
20   exit 1
21 }
22
23 # temporary storage of error messages
24 ERR=$(mktemp --tmpdir config-err-XXXXXX)
25
26 source_with_error_check () {
27     CONFIG_FILE="$1"
28     echo "Loading $CONFIG_FILE"
29     BASH_VERSION= . "$CONFIG_FILE" 2>"$ERR"
30     if [ -s "$ERR" ]; then
31         . /usr/lib/lightdm/config-error-dialog.sh
32     fi
33     cat "$ERR" >>/dev/stderr
34     truncate -s 0 "$ERR"
35 }
36
37 # Load profile
38 for file in "/etc/profile" "$HOME/.profile" "/etc/xprofile" "$HOME/.xprofile"; do
39     if [ -f "$file" ]; then
40         source_with_error_check "$file"
41     fi
42 done
43
44 # Load resources
45 if type xrdb >/dev/null 2>&1; then
46     xresourcedir="/etc/X11/Xresources"
47     if [ -d "$xresourcedir" ]; then
48         for file in $xresourcedir/*; do
49             echo "Loading resource: $file"
50             xrdb -merge "$file"
51         done
52     fi
53     xresourcefile="$HOME/.Xresources"
54     if [ -f "$xresourcefile" ]; then
55         echo "Loading resource: $xresourcefile"
56         xrdb -merge "$xresourcefile"
57     fi
58 fi
59
60 # Load keymaps
61 if type setxkbmap >/dev/null 2>&1; then
62     for file in "/etc/X11/Xkbmap" "$HOME/.Xkbmap"; do
63         if [ -f "$file" ]; then
64             echo "Loading keymap: $file"
65             setxkbmap `cat "$file"`
66             XKB_IN_USE=yes
67         fi
68     done
69 fi
70
71 # Load xmodmap if not using XKB
72 if type xmodmap >/dev/null 2>&1; then
73     if [ -z "$XKB_IN_USE" ]; then
74         for file in "/etc/X11/Xmodmap" "$HOME/.Xmodmap"; do
75             if [ -f "$file" ]; then
76                echo "Loading modmap: $file"
77                xmodmap "$file"
78             fi
79         done
80     fi
81 fi
82
83 unset XKB_IN_USE
84
85 # Run all system xinitrc shell scripts.
86 xinitdir="/etc/X11/xinit/xinitrc.d"
87 if [ -d "$xinitdir" ]; then
88     for script in $xinitdir/*; do
89         echo "Loading xinit script $script"
90         if [ -x "$script" -a ! -d "$script" ]; then
91             . "$script"
92         fi
93     done
94 fi
95
96 # Load Xsession scripts
97 # OPTIONFILE, USERXSESSION, USERXSESSIONRC and ALTUSERXSESSION are required
98 # by the scripts to work
99 xsessionddir="/etc/X11/Xsession.d"
100 OPTIONFILE=/etc/X11/Xsession.options
101 USERXSESSION=$HOME/.xsession
102 USERXSESSIONRC=$HOME/.xsessionrc
103 ALTUSERXSESSION=$HOME/.Xsession
104
105 if [ -d "$xsessionddir" ]; then
106     for i in `ls $xsessionddir`; do
107         script="$xsessionddir/$i"
108         echo "Loading X session script $script"
109         if [ -r "$script"  -a -f "$script" ] && expr "$i" : '^[[:alnum:]_-]\+$' > /dev/null; then
110             . "$script"
111         fi
112     done
113 fi
114
115 echo "X session wrapper complete, running session $@"
116
117 exec $@