home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / etc / gdm / Xsession < prev   
Encoding:
Text File  |  2006-10-20  |  6.4 KB  |  225 lines

  1. #!/bin/sh
  2. #
  3. # This is SORT OF LIKE an X session, but not quite.  You get a command as the
  4. # first argument (it could be multiple words, so run it with "eval").  As a
  5. # special case, the command can be:
  6. #  failsafe - Run an xterm only
  7. #  default - Run the appropriate Xclients startup (see the code below)
  8. #  custom - Run ~/.xsession and if that's not available run 'default'
  9. #
  10. # (Note that other arguments could also follow, but only the command one is
  11. # right now relevant and supported)
  12. #
  13. # The output is ALREADY redirected to .xsession-errors in GDM.  This way
  14. # .xsession-errors actually gets more output such as if the PreSession script
  15. # is failing.  This also prevents DoS attacks if some app in the users session
  16. # can be prodded to dump lots of stuff on the stdout/stderr.  We wish to be
  17. # robust don't we?  In case you wish to use an existing script for other DM's,
  18. # you can just not redirect when GDMSESSION is set.  GDMSESSION will always
  19. # be set from gdm.
  20. #
  21. # Also note that this is not run as a login shell, this is just executed.
  22. #
  23. # based on:
  24. # $XConsortium: Xsession /main/10 1995/12/18 18:21:28 gildea $
  25.  
  26. PROGNAME=Xsession
  27.  
  28. message () {
  29.   # pretty-print messages of arbitrary length; use xmessage if it
  30.   # is available and $DISPLAY is set
  31.   MESSAGE="$PROGNAME: $*"
  32.   echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2
  33.   if [ -n "$DISPLAY" ]; then
  34.     if [ -n "$zenity" ]; then
  35.       "$zenity" --info --text "`gettextfunc "$MESSAGE"`"
  36.     elif [ -n "$xmessage" ]; then
  37.       echo "$MESSAGE" | fold -s -w ${COLUMNS:-80} | $xmessage -center -file -
  38.     fi
  39.   fi
  40. }
  41.  
  42. message_nonl () {
  43.   # pretty-print messages of arbitrary length (no trailing newline); use
  44.   # xmessage if it is available and $DISPLAY is set
  45.   MESSAGE="$PROGNAME: $*"
  46.   echo -n "$MESSAGE" | fold -s -w ${COLUMNS:-80} >&2;
  47.   if [ -n "$DISPLAY" ]; then
  48.     if [ -n "$zenity" ]; then
  49.       "$zenity" --info --text "`gettextfunc "$MESSAGE"`"
  50.     elif [ -n "$xmessage" ]; then
  51.       echo -n "$MESSAGE" | fold -s -w ${COLUMNS:-80} | $xmessage -center -file -
  52.     fi
  53.   fi
  54. }
  55.  
  56. errormsg () {
  57.   # exit script with error
  58.   message "$*"
  59.   exit 1
  60. }
  61.  
  62. internal_errormsg () {
  63.   # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message
  64.   # One big call to message() for the sake of xmessage; if we had two then
  65.   # the user would have dismissed the error we want reported before seeing the
  66.   # request to report it.
  67.   errormsg "$*" \
  68.            "Please report the installed version of the \"xfree86-common\"" \
  69.            "package and the complete text of this error message to" \
  70.            "<debian-x@lists.debian.org>."
  71. }
  72.  
  73. run_parts () {
  74.   # until run-parts --noexec is implemented
  75.   if [ -z "$1" ]; then
  76.     internal_errormsg "run_parts() called without an argument."
  77.   fi
  78.   if [ ! -d "$1" ]; then
  79.     internal_errormsg "run_parts() called, but \"$1\" does not exist or is" \
  80.                       "not a directory."
  81.   fi
  82.   for F in $(/bin/ls $1); do
  83.     if expr "$F" : '[[:alnum:]_-]\+$' > /dev/null 2>&1; then
  84.       if [ -f "$1/$F" ]; then
  85.         echo "$1/$F"
  86.       fi
  87.     fi
  88.   done
  89. }
  90. # initialize variables for use by all session scripts
  91.  
  92. OPTIONFILE=/etc/X11/Xsession.options
  93.  
  94. SYSRESOURCES=/etc/X11/Xresources
  95. USRRESOURCES=$HOME/.Xresources
  96.  
  97. SYSSESSIONDIR=/etc/X11/Xsession.d
  98. USERXSESSION=$HOME/.xsession
  99. ALTUSERXSESSION=$HOME/.Xsession
  100.  
  101. # this will go into the .xsession-errors along with all other echo's
  102. # good for debugging where things went wrong
  103. echo "$0: Beginning session setup..."
  104.  
  105. # First read /etc/profile and .profile
  106. test -f /etc/profile && . /etc/profile
  107. test -f "$HOME/.profile" && . "$HOME/.profile"
  108. # Second read /etc/xprofile and .xprofile for X specific setup
  109. test -f /etc/xprofile && . /etc/xprofile
  110. test -f "$HOME/.xprofile" && . "$HOME/.xprofile"
  111.  
  112. # Translation stuff
  113. if [ -x "/usr/lib/gdm/gdmtranslate" ] ; then
  114.   gdmtranslate="/usr/lib/gdm/gdmtranslate"
  115. else
  116.   gdmtranslate=
  117. fi
  118.  
  119. # Note that this should only go to zenity dialogs which always expect utf8
  120. gettextfunc () {
  121.   if [ "x$gdmtranslate" != "x" ] ; then
  122.     "$gdmtranslate" --utf8 "$1"
  123.   else
  124.     echo "$1"
  125.   fi
  126. }
  127.  
  128. zenity=`which zenity 2>/dev/null`
  129. xmessage=`which xmessage 2>/dev/null`
  130.  
  131. command="$1"
  132.  
  133. if [ -z "$command" ] ; then
  134.   command=failsafe
  135. fi
  136.  
  137. if [ x"$command" = xfailsafe ] ; then
  138.   if [ -n "$zenity" ] ; then
  139.     "$zenity" --info --text "`gettextfunc "This is the failsafe xterm session.  Windows now have focus only if you have your cursor above them.  To get out of this mode type 'exit' in the window in the upper left corner"`"
  140.   else
  141.     echo "$0: Starting the failsafe xterm session."
  142.   fi
  143.   exec xterm -geometry 80x24+0+0
  144. fi
  145.  
  146. # clean up after xbanner
  147. freetemp=`which freetemp 2>/dev/null`
  148. if [ -n "$freetemp" ] ; then
  149.     "$freetemp"
  150. fi
  151.  
  152. usermodmap="$HOME/.Xmodmap"
  153. userxkbmap="$HOME/.Xkbmap"
  154.  
  155. if [ -f "$userxkbmap" ]; then
  156.     setxkbmap `cat "$userxkbmap"`
  157.     XKB_IN_USE=yes
  158. fi
  159.  
  160. # xkb and xmodmap don't play nice together
  161. if [ -z "$XKB_IN_USE" ]; then
  162.     if [ -f "$usermodmap" ]; then
  163.        xmodmap "$usermodmap"
  164.     fi
  165. fi
  166.  
  167. unset XKB_IN_USE
  168.  
  169. # Normalize languages, some places/distros screw us up in /etc/profile,
  170. # so in case the user did select a language
  171. if [ -n "$GDM_LANG" ]; then
  172.   LANG="$GDM_LANG"
  173.   export LANG
  174.  
  175.   if [ -n "$LC_ALL" ]; then
  176.     if [ "$LC_ALL" != "$LANG" ]; then
  177.       LC_ALL="$LANG"
  178.     fi
  179.   else
  180.     unset LC_ALL
  181.   fi
  182.  
  183.   if [ -n "$LANGUAGE" ]; then
  184.     if [ "$LANGUAGE" != "$LANG" ]; then
  185.       LANGUAGE="$LANG"
  186.     fi
  187.   else
  188.     unset LANGUAGE
  189.   fi
  190.  
  191.   if [ -n "$LINGUAS" ]; then
  192.     if [ "$LINGUAS" != "$LANG" ]; then
  193.       LINGUAS="$LANG"
  194.     fi
  195.   else
  196.     unset LINGUAS
  197.   fi
  198. fi
  199.  
  200. # The default Debian session runs xsession first, so we just do that for
  201. # "custom"
  202. if [ "x$command" = "xcustom" ] ; then
  203.   shift
  204.   set default $*
  205. fi
  206.  
  207. # use run-parts to source every file in the session directory; we source
  208. # instead of executing so that the variables and functions defined above
  209. # are available to the scripts, and so that they can pass variables to each
  210. # other
  211. SESSIONFILES=$(run_parts $SYSSESSIONDIR)
  212. if [ -n "$SESSIONFILES" ]; then
  213.   for SESSIONFILE in $SESSIONFILES; do
  214.     . $SESSIONFILE
  215.   done
  216. fi
  217.  
  218. echo "$0: Executing $command failed, will try to run x-terminal-emulator"
  219.  
  220. if [ -n "$zenity" ] ; then
  221.     "$zenity" --info --text "`gettextfunc "I could not start your session and so I have started the failsafe xterm session.  Windows now have focus only if you have your cursor above them.  To get out of this mode type 'exit' in the window in the upper left corner"`"
  222. fi
  223.  
  224. exec x-terminal-emulator -geometry 80x24+0+0
  225.