Xsession.in 5.28 KB
Newer Older
1
#!@XSESSION_SHELL@
2
#
3 4 5 6 7
# This is SORT OF LIKE an X session, but not quite.  You get a command as the
# first argument (it could be multiple words, so run it with "eval").  As a
# special case, the command can be:
#  default - Run the appropriate Xclients startup (see the code below)
#  custom - Run ~/.xsession and if that's not available run 'default'
8
#
9 10
# (Note that other arguments could also follow, but only the command one is
# right now relevant and supported)
11
#
12
# The output is ALREADY redirected to .xsession-errors in GDM.  This way
13
# .xsession-errors actually gets more output such as if the PreSession script
14 15 16 17 18
# is failing.  This also prevents DoS attacks if some app in the users session
# can be prodded to dump lots of stuff on the stdout/stderr.  We wish to be
# robust don't we?  In case you wish to use an existing script for other DM's,
# you can just not redirect when GDMSESSION is set.  GDMSESSION will always
# be set from gdm.
19 20 21 22 23
#
# Also note that this is not run as a login shell, this is just executed.
# This is why we source the profile files below.
#
# based on:
Martin Peterson's avatar
Martin Peterson committed
24 25
# $XConsortium: Xsession /main/10 1995/12/18 18:21:28 gildea $

26
command="$@"
27

28 29
# this will go into the .xsession-errors along with all other echo's
# good for debugging where things went wrong
30
echo "$0: Beginning session setup..."
31

32 33
# First read /etc/profile and .profile
test -f /etc/profile && . /etc/profile
34
test -f "$HOME/.profile" && . "$HOME/.profile"
35 36
# Second read /etc/xprofile and .xprofile for X specific setup
test -f /etc/xprofile && . /etc/xprofile
37
test -f "$HOME/.xprofile" && . "$HOME/.xprofile"
38

39
# Translation stuff
40 41
if [ -x "@libexecdir@/gdmtranslate" ] ; then
  gdmtranslate="@libexecdir@/gdmtranslate"
42 43 44 45 46 47 48
else
  gdmtranslate=
fi

# Note that this should only go to zenity dialogs which always expect utf8
gettextfunc () {
  if [ "x$gdmtranslate" != "x" ] ; then
49
    "$gdmtranslate" --utf8 "$1"
50 51 52 53 54
  else
    echo "$1"
  fi
}

55 56
OLD_IFS=$IFS

57 58 59 60 61 62 63 64 65 66 67 68
gdmwhich () {
  COMMAND="$1"
  OUTPUT=
  IFS=:
  for dir in $PATH
  do
    if test -x "$dir/$COMMAND" ; then
      if test "x$OUTPUT" = "x" ; then
        OUTPUT="$dir/$COMMAND"
      fi
    fi
  done
69
  IFS=$OLD_IFS 
70 71 72 73
  echo "$OUTPUT"
}

zenity=`gdmwhich zenity`
74

Jiri (George) Lebl's avatar
Jiri (George) Lebl committed
75 76
# Note: ~/.xsession-errors is now done in the daemon so that it
# works for ALL sessions (except ones named 'Failsafe')
Martin Peterson's avatar
Martin Peterson committed
77 78

# clean up after xbanner
79
freetemp=`gdmwhich freetemp`
80
if [ -n "$freetemp" ] ; then
81
	"$freetemp"
82
fi
Martin Peterson's avatar
Martin Peterson committed
83

84 85 86
userresources="$HOME/.Xresources"
usermodmap="$HOME/.Xmodmap"
userxkbmap="$HOME/.Xkbmap"
George Lebl's avatar
George Lebl committed
87 88 89 90 91 92 93 94 95 96

sysresources=/etc/X11/Xresources 
sysmodmap=/etc/X11/Xmodmap 
sysxkbmap=/etc/X11/Xkbmap

rh6sysresources=/etc/X11/xinit/Xresources 
rh6sysmodmap=/etc/X11/xinit/Xmodmap 

# merge in defaults
if [ -f "$rh6sysresources" ]; then
Martin Pitt's avatar
Martin Pitt committed
97
    xrdb -nocpp -merge "$rh6sysresources"
George Lebl's avatar
George Lebl committed
98 99 100
fi

if [ -f "$sysresources" ]; then
Martin Pitt's avatar
Martin Pitt committed
101
    xrdb -nocpp -merge "$sysresources"
George Lebl's avatar
George Lebl committed
102 103 104
fi

if [ -f "$userresources" ]; then
Martin Pitt's avatar
Martin Pitt committed
105
    xrdb -nocpp -merge "$userresources"
George Lebl's avatar
George Lebl committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
fi

# merge in keymaps
if [ -f "$sysxkbmap" ]; then
    setxkbmap `cat "$sysxkbmap"`
    XKB_IN_USE=yes
fi

if [ -f "$userxkbmap" ]; then
    setxkbmap `cat "$userxkbmap"`
    XKB_IN_USE=yes
fi

#
# Eeek, this seems like too much magic here
#
if [ -z "$XKB_IN_USE" -a ! -L /etc/X11/X ]; then
    if grep '^exec.*/Xsun' /etc/X11/X > /dev/null 2>&1 && [ -f /etc/X11/XF86Config ]; then
       xkbsymbols=`sed -n -e 's/^[     ]*XkbSymbols[   ]*"\(.*\)".*$/\1/p' /etc/X11/XF86Config`
       if [ -n "$xkbsymbols" ]; then
           setxkbmap -symbols "$xkbsymbols"
           XKB_IN_USE=yes
       fi
    fi
fi

# xkb and xmodmap don't play nice together
if [ -z "$XKB_IN_USE" ]; then
    if [ -f "$rh6sysmodmap" ]; then
       xmodmap "$rh6sysmodmap"
    fi

    if [ -f "$sysmodmap" ]; then
       xmodmap "$sysmodmap"
    fi

    if [ -f "$usermodmap" ]; then
       xmodmap "$usermodmap"
    fi
fi

unset XKB_IN_USE
Martin Peterson's avatar
Martin Peterson committed
148

149 150
xhost +si:localuser:`id -un` || :

151 152 153
# run all system xinitrc shell scripts.
if [ -d /etc/X11/xinit/xinitrc.d ]; then
    for i in /etc/X11/xinit/xinitrc.d/* ; do
154
        if [ -x "$i" -a ! -d "$i" ]; then
155 156 157 158 159
	    . "$i"
        fi
    done
fi

160
if [ "x$command" = "xdefault" ] ; then
161 162 163 164 165 166 167
  if [ -x "$HOME/.Xclients" ]; then
    command="$HOME/.Xclients"
  elif [ -x /etc/X11/xinit/Xclients ]; then
    command="/etc/X11/xinit/Xclients"
  elif [ -x /etc/X11/Xclients ]; then
    command="/etc/X11/Xclients"
  else
168 169 170 171 172 173
    if [ -n "$zenity" ] ; then
	disptext=`gettextfunc "System has no Xclients file, so starting a failsafe xterm session.  Windows will have focus only if the mouse pointer is above them.  To get out of this mode type 'exit' in the window."`
      "$zenity" --info --text "$disptext"
    else
      echo "$0: Cannot find Xclients"
    fi
174
    exec xterm -geometry 80x24+0+0
175
  fi
Martin Peterson's avatar
Martin Peterson committed
176
fi
177 178

# add ssh-agent if found
179
sshagent="`gdmwhich ssh-agent`"
180 181
if [ -n "$sshagent" ] && [ -x "$sshagent" ] && [ -z "$SSH_AUTH_SOCK" ]; then
    command="$sshagent -- $command"
182
elif [ -z "$sshagent" ] ; then
183
    echo "$0: ssh-agent not found!"
184 185
fi

186
echo "$0: Setup done, will execute: $command"
187 188

eval exec $command
189

190
echo "$0: Executing $command failed, will run xterm"
191 192

if [ -n "$zenity" ] ; then
193
	disptext=`gettextfunc "Failed to start the session, so starting a failsafe xterm session.  Windows will have focus only if the mouse pointer is above them.  To get out of this mode type 'exit' in the window."`
194
	"$zenity" --info --text "$disptext"
195 196 197
fi

exec xterm -geometry 80x24+0+0