summaryrefslogtreecommitdiff
blob: 237fb36306612610a5a71d6150eed46fb49a4059 (plain)
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
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
148
149
150
151
152
153
154
155
156
157
158
#!/bin/sh
#
# Slim login manager Xsession script
#

command="$@"

# this will go into slim.log along with all other echo's
# good for debugging where things go wrong
echo "$0: Beginning session setup..."

# First read /etc/profile and .profile
test -f /etc/profile && . /etc/profile
test -f "$HOME/.profile" && . "$HOME/.profile"
# Second read /etc/xprofile and .xprofile for X specific setup
test -f /etc/xprofile && . /etc/xprofile
test -f "$HOME/.xprofile" && . "$HOME/.xprofile"

# wrap possible arguments to determine whether to treat special or not
if [ "x$command" = "xcustom" ] || [ "x$command" = "xCustom" ] || [ "x$command" = "xdefault" ] || [ "x$command" = "xDefault" ]; then
  command="Xsession"
fi
if [ "x$command" = "x" ]; then
  # no default specified, check if Xsession will complete
  # and if not then assign XSESSION to command
  if [ -x "$HOME/.xsession" ] || [ -x "$HOME/.Xclients" ] || [ -x /etc/X11/xinit/Xclients ] || [ -x /etc/X11/Xclients ]; then
    command="Xsession"
  else
    command=$XSESSION
  fi
fi

# most of this is from /etc/X11/chooser.sh
sessionscript=""
if [ -n "${command}" ]; then
  # find a match for $command in /etc/X11/Sessions
  for x in /etc/X11/Sessions/* ; do
    if [ "`echo ${x##*/} | awk '{ print toupper($1) }'`" = "`echo ${command} | awk '{ print toupper($1) }'`" ]; then
      sessionscript=${x}
      break
    fi
  done
  if [ -n "${sessionscript}" ]; then
    if [ -x "${sessionscript}" ]; then
      command="${sessionscript}"
    else
      command="/bin/sh ${sessionscript}"
    fi
  else

    # find an executable for $command
    x=""
    y=""

    for x in "${command}" "`echo ${command} | awk '{ print toupper($1) }'`" "`echo ${command} | awk '{ print tolower($1) }'`"
    do
      # Fall through ...
      if [ -x "`which ${x} 2>/dev/null`" ]; then
	y="`which ${x} 2>/dev/null`"
	break
      fi
    done
    # note , if the command could not be found then $command will be empty
    command="$y"
    unset x
    unset y
  fi
fi

# call xrdb and xmodmap and such, since $command is not a session script
if [ -z "${sessionscript}" ]; then
  userresources="$HOME/.Xresources"
  usermodmap="$HOME/.Xmodmap"
  userxkbmap="$HOME/.Xkbmap"

  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
    xrdb -merge "$rh6sysresources"
  fi

  if [ -f "$sysresources" ]; then
    xrdb -merge "$sysresources"
  fi

  if [ -f "$userresources" ]; then
    xrdb -merge "$userresources"
  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
fi
unset sessionscript

# start failsafe session
if [ -z "${command}" ]; then
  echo "$0: Failed to find a command to start the session, so starting a failsafe xterm."
  exec xterm -geometry 80x24+0+0
fi

# run all system xinitrc shell scripts which will update command
if [ -d /etc/X11/xinit/xinitrc.d ]; then
  for i in /etc/X11/xinit/xinitrc.d/* ; do
    if [ -x "$i" ]; then
      . "$i"
    fi
  done
  unset i
fi

echo "$0: Setup done, will execute: $command"
exec $command

# vim:ts=4