Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2011
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 16.21 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. #  DEFAULT KDE STARTUP SCRIPT ( 4.4.5 (KDE 4.4.5) )
  4. #
  5.  
  6. if test "x$1" = x--failsafe; then
  7.     KDE_FAILSAFE=1 # General failsafe flag
  8.     KWIN_COMPOSE=N # Disable KWin's compositing
  9.     export KWIN_COMPOSE KDE_FAILSAFE
  10. fi
  11.  
  12. # When the X server dies we get a HUP signal from xinit. We must ignore it
  13. # because we still need to do some cleanup.
  14. trap 'echo GOT SIGHUP' HUP
  15.  
  16. # Check if a KDE session already is running and whether it's possible to connect to X
  17. kcheckrunning
  18. kcheckrunning_result=$?
  19. if test $kcheckrunning_result -eq 0 ; then
  20.         echo "KDE seems to be already running on this display."
  21.         xmessage -geometry 500x100 "KDE seems to be already running on this display." > /dev/null 2>/dev/null
  22.         exit 1
  23. elif test $kcheckrunning_result -eq 2 ; then
  24.         echo "\$DISPLAY is not set or cannot connect to the X server."
  25.         exit 1
  26. fi
  27.  
  28. # Set the background to plain grey.
  29. # The standard X background is nasty, causing moire effects and exploding
  30. # people's heads. We use colours from the standard KDE palette for those with
  31. # palettised displays.
  32. if test -z "$XDM_MANAGED" || echo "$XDM_MANAGED" | grep ",auto" > /dev/null; then
  33.   xsetroot -solid "#000000"
  34. fi
  35.  
  36. # we have to unset this for Darwin since it will screw up KDE's dynamic-loading
  37. unset DYLD_FORCE_FLAT_NAMESPACE
  38.  
  39. # in case we have been started with full pathname spec without being in PATH
  40. bindir=`echo "$0" | sed -n 's,^\(/.*\)/[^/][^/]*$,\1,p'`
  41. if [ -n "$bindir" ]; then
  42.   qbindir=`$bindir/kde4-config --qt-binaries`
  43.   if [ -n "$qbindir" ]; then
  44.     case $PATH in
  45.       $qbindir|$qbindir:*|*:$qbindir|*:$qbindir:*) ;;
  46.       *) PATH=$qbindir:$PATH; export PATH;;
  47.     esac
  48.   fi
  49.   case $PATH in
  50.     $bindir|$bindir:*|*:$bindir|*:$bindir:*) ;;
  51.     *) PATH=$bindir:$PATH; export PATH;;
  52.   esac
  53. fi
  54.  
  55. # Boot sequence:
  56. #
  57. # kdeinit is used to fork off processes which improves memory usage
  58. # and startup time.
  59. #
  60. # * kdeinit starts klauncher first.
  61. # * Then kded is started. kded is responsible for keeping the sycoca
  62. #   database up to date. When an up to date database is present it goes
  63. #   into the background and the startup continues.
  64. # * Then kdeinit starts kcminit. kcminit performs initialisation of
  65. #   certain devices according to the user's settings
  66. #
  67. # * Then ksmserver is started which takes control of the rest of the startup sequence
  68.  
  69. # The user's personal KDE directory is usually ~/.kde, but this setting
  70. # may be overridden by setting KDEHOME.
  71.  
  72. kdehome=$HOME/.kde
  73. test -n "$KDEHOME" && kdehome=`echo "$KDEHOME"|sed "s,^~/,$HOME/,"`
  74.  
  75. # Read LANG and write the country part to kdeglobals
  76. # de_AT.UTF-8 => Country=at
  77. # This is necessary because klocale.cpp (kdelibs) does only try to read the value
  78. # from kdeglobals and then falls back to default instead of triyng to detect it
  79.  
  80. if [ ! -e $kdehome/share/config/kdeglobals ] || [ ! `grep "Country=" $kdehome/share/config/kdeglobals` ]; then
  81.   if [ ! $LANG ]; then
  82.     if [ -e /etc/default/locale ]; then
  83.       localefile='/etc/default/locale'
  84.     elif [ -e /etc/environment ]; then
  85.       localefile='/etc/environment'
  86.       localefile='/etc/environment'
  87.     fi
  88.     if [ $localefile ]; then
  89.       locale=`sed -ne 's/^LANG="\(.*\)"$/\1/p' $localefile`
  90.     fi
  91.   else
  92.     locale=$LANG
  93.   fi
  94.   if [ $locale ]; then
  95.     country=`echo $locale | sed -ne 's/^[A-Za-z]*_\([A-Za-z]*\).*$/\1/p'|tr 'A-Z' 'a-z'`
  96.     if [ ! $country = "" ]; then
  97. cat >>$kdehome/share/config/kdeglobals <<EOF
  98. [Locale]
  99. Country=$country
  100. EOF
  101.     fi
  102.   fi
  103. fi
  104.  
  105. # see kstartupconfig source for usage
  106. mkdir -m 700 -p $kdehome
  107. mkdir -m 700 -p $kdehome/share
  108. mkdir -m 700 -p $kdehome/share/config
  109. cat >$kdehome/share/config/startupconfigkeys <<EOF
  110. kcminputrc Mouse cursorTheme 'Oxygen_Black'
  111. kcminputrc Mouse cursorSize ''
  112. ksplashrc KSplash Theme Default
  113. ksplashrc KSplash Engine KSplashX
  114. kcmfonts General forceFontDPI 0
  115. kdeglobals Locale Language '' # trigger requesting languages from KLocale
  116. kdeglobals Locale Country ''
  117. EOF
  118. kstartupconfig4
  119. returncode=$?
  120. if test $returncode -ne 0; then
  121.     xmessage -geometry 500x100 "kstartupconfig4 does not exist or fails. The error code is $returncode. Check your installation."
  122.     exit 1
  123. fi
  124. [ -r $kdehome/share/config/startupconfig ] && . $kdehome/share/config/startupconfig
  125.  
  126. # XCursor mouse theme needs to be applied here to work even for kded or ksmserver
  127. if test -n "$kcminputrc_mouse_cursortheme" -o -n "$kcminputrc_mouse_cursorsize" ; then
  128.  
  129.  
  130.     kapplymousetheme "$kcminputrc_mouse_cursortheme" "$kcminputrc_mouse_cursorsize"
  131.     if test $? -eq 10; then
  132.         XCURSOR_THEME=default
  133.         export XCURSOR_THEME
  134.     elif test -n "$kcminputrc_mouse_cursortheme"; then
  135.         XCURSOR_THEME="$kcminputrc_mouse_cursortheme"
  136.         export XCURSOR_THEME
  137.     fi
  138.     if test -n "$kcminputrc_mouse_cursorsize"; then
  139.         XCURSOR_SIZE="$kcminputrc_mouse_cursorsize"
  140.         export XCURSOR_SIZE
  141.     fi
  142. fi
  143.  
  144.  
  145. if test "$kcmfonts_general_forcefontdpi" -eq 120; then
  146.     xrdb -quiet -merge -nocpp <<EOF
  147. Xft.dpi: 120
  148. EOF
  149. elif test "$kcmfonts_general_forcefontdpi" -eq 96; then
  150.     xrdb -quiet -merge -nocpp <<EOF
  151. Xft.dpi: 96
  152. EOF
  153. fi
  154.  
  155.  
  156. dl=$DESKTOP_LOCKED
  157. unset DESKTOP_LOCKED # Don't want it in the environment
  158.  
  159. ksplash_pid=
  160. if test -z "$dl"; then
  161.   # languages as resolved by KLocale, for the splash screens use
  162.   # klocale_languages is assembled by kdostartupconfig4 calling KLocale
  163.   KLOCALE_LANGUAGES="$klocale_languages"
  164.   export KLOCALE_LANGUAGES
  165.   # the splashscreen and progress indicator
  166.   case "$ksplashrc_ksplash_engine" in
  167.     KSplashX)
  168.       ksplash_pid=`ksplashx "${ksplashrc_ksplash_theme}" --pid`
  169.  
  170.       ;;
  171.     None)
  172.       ;;
  173.     Simple)
  174.       ksplash_pid=`ksplashsimple "${ksplashrc_ksplash_theme}" --pid`
  175.       ;;
  176.     *)
  177.       ;;
  178.   esac
  179.   # no longer needed in the environment
  180.   unset KLOCALE_LANGUAGES
  181. fi
  182.  
  183. # configuration of the gtk2-engines-qtcurve if not already set
  184.  
  185. # First we need to remove previous gtk-qt-engines config if any
  186. if [ -e $kdehome/env/gtk-qt-engine.rc.sh ] && [ ! -e /var/lib/dpkg/info/gtk-qt-engine.list ] ; then
  187.   rm -f $kdehome/env/gtk-qt-engine.rc.sh
  188.   # We also have to remove .gtkrc-2.0-kde4 since it'll have gtk-qt-engines config in it
  189.   if [ -e $HOME/.gtkrc-2.0-kde4 ] ; then
  190.     rm -f $HOME/.gtkrc-2.0-kde4
  191.   fi
  192. fi
  193.  
  194. if [ -e /var/lib/dpkg/info/gtk2-engines-qtcurve.list ] && [ -e /var/lib/dpkg/info/kubuntu-default-settings.list ] ; then
  195.   # The theme and k-d-s are installed, configuring...
  196.   if [ ! -e $kdehome/env/gtk2-engines-qtcurve.rc.sh ] && [ -e /usr/share/kubuntu-default-settings/gtk2-engines-qtcurve.rc.sh ] ; then
  197.     mkdir -p $kdehome/env
  198.     cp -f /usr/share/kubuntu-default-settings/gtk2-engines-qtcurve.rc.sh $kdehome/env
  199.     chmod 755 $kdehome/env/gtk2-engines-qtcurve.rc.sh
  200.   fi
  201.  
  202.   if [ ! -e $HOME/.gtkrc-2.0-kde4 ] && [ -e /usr/share/kubuntu-default-settings/dot-gtkrc-2.0-kde4 ] ; then
  203.     cp -f /usr/share/kubuntu-default-settings/dot-gtkrc-2.0-kde4 $HOME/.gtkrc-2.0-kde4
  204.   fi
  205. else
  206.   # Either the theme or k-d-s are missing, not forcing the configuration then...
  207.   if [ -e $kdehome/env/gtk2-engines-qtcurve.rc.sh ] ; then
  208.     rm -f $kdehome/env/gtk2-engines-qtcurve.rc.sh
  209.   fi
  210.  
  211.   if [ -e $HOME/.gtkrc-2.0-kde4 ] && [ ! -e /var/lib/dpkg/info/gtk-qt-engine.list ] ; then
  212.     rm -f $HOME/.gtkrc-2.0-kde4
  213.   fi
  214. fi
  215.  
  216. # Source scripts found in <localprefix>/env/*.sh and <prefixes>/env/*.sh
  217. # (where <localprefix> is $KDEHOME or ~/.kde, and <prefixes> is where KDE is installed)
  218. #
  219. # This is where you can define environment variables that will be available to
  220. # all KDE programs, so this is where you can run agents using e.g. eval `ssh-agent`
  221. # or eval `gpg-agent --daemon`.
  222. # Note: if you do that, you should also put "ssh-agent -k" as a shutdown script
  223. #
  224. # (see end of this file).
  225. # For anything else (that doesn't set env vars, or that needs a window manager),
  226. # better use the Autostart folder.
  227.  
  228. libpath=`kde4-config --path lib | tr : '\n'`
  229.  
  230. for prefix in `echo "$libpath" | sed -n -e 's,/lib[^/]*/,/env/,p'`; do
  231.   for file in "$prefix"*.sh; do
  232.     test -r "$file" && . "$file"
  233.   done
  234. done
  235.  
  236. # Set the path for Qt plugins provided by KDE
  237. if test -n "$QT_PLUGIN_PATH"; then
  238.   QT_PLUGIN_PATH="$QT_PLUGIN_PATH:`kde4-config --path qtplugins`"
  239. else
  240.   QT_PLUGIN_PATH="`kde4-config --path qtplugins`"
  241. fi
  242. export QT_PLUGIN_PATH
  243.  
  244. # Activate the kde font directories.
  245. #
  246. # There are 4 directories that may be used for supplying fonts for KDE.
  247. #
  248. # There are two system directories. These belong to the administrator.
  249. # There are two user directories, where the user may add her own fonts.
  250. #
  251. # The 'override' versions are for fonts that should come first in the list,
  252. # i.e. if you have a font in your 'override' directory, it will be used in
  253. # preference to any other.
  254. #
  255. # The preference order looks like this:
  256. # user override, system override, X, user, system
  257. #
  258. # Where X is the original font database that was set up before this script
  259. # runs.
  260.  
  261. usr_odir=$HOME/.fonts/kde-override
  262. usr_fdir=$HOME/.fonts
  263.  
  264. if test -n "$KDEDIRS"; then
  265.   kdedirs_first=`echo "$KDEDIRS"|sed -e 's/:.*//'`
  266.   sys_odir=$kdedirs_first/share/fonts/override
  267.   sys_fdir=$kdedirs_first/share/fonts
  268. else
  269.   sys_odir=$KDEDIR/share/fonts/override
  270.   sys_fdir=$KDEDIR/share/fonts
  271. fi
  272.  
  273. # We run mkfontdir on the user's font dirs (if we have permission) to pick
  274. # up any new fonts they may have installed. If mkfontdir fails, we still
  275. # add the user's dirs to the font path, as they might simply have been made
  276. # read-only by the administrator, for whatever reason.
  277.  
  278. test -d "$sys_odir" && xset +fp "$sys_odir"
  279. test -d "$usr_odir" && (mkfontdir "$usr_odir" ; xset +fp "$usr_odir")
  280. test -d "$usr_fdir" && (mkfontdir "$usr_fdir" ; xset fp+ "$usr_fdir")
  281. test -d "$sys_fdir" && xset fp+ "$sys_fdir"
  282.  
  283. # Ask X11 to rebuild its font list.
  284. xset fp rehash
  285.  
  286. # Set a left cursor instead of the standard X11 "X" cursor, since I've heard
  287. # from some users that they're confused and don't know what to do. This is
  288. # especially necessary on slow machines, where starting KDE takes one or two
  289. # minutes until anything appears on the screen.
  290. #
  291. # If the user has overwritten fonts, the cursor font may be different now
  292. # so don't move this up.
  293. #
  294. xsetroot -cursor_name left_ptr
  295.  
  296. # Get Ghostscript to look into user's KDE fonts dir for additional Fontmap
  297. if test -n "$GS_LIB" ; then
  298.     GS_LIB=$usr_fdir:$GS_LIB
  299.     export GS_LIB
  300. else
  301.     GS_LIB=$usr_fdir
  302.     export GS_LIB
  303. fi
  304.  
  305. lnusertemp=`kde4-config --path exe --locate lnusertemp`
  306. if test -z "$lnusertemp"; then
  307.   # Startup error
  308.   echo 'startkde: ERROR: Could not locate lnusertemp in '`kde4-config --path exe` 1>&2
  309. fi
  310.  
  311. # Link "tmp" "socket" and "cache" resources to directory in /tmp
  312. # Creates:
  313. # - a directory /tmp/kde-$USER and links $KDEHOME/tmp-$HOSTNAME to it.
  314. # - a directory /tmp/ksocket-$USER and links $KDEHOME/socket-$HOSTNAME to it.
  315. # - a directory /var/tmp/kdecache-$USER and links $KDEHOME/cache-$HOSTNAME to it.
  316. # Note: temporary locations can be overriden through the KDETMP and KDEVARTMP
  317. # environment variables
  318. for resource in tmp cache socket; do
  319.     if "$lnusertemp" $resource >/dev/null; then
  320.         : # ok
  321.     else
  322.         echo 'startkde: Call to lnusertemp failed (temporary directories full?). Check your installation.'  1>&2
  323.         test -n "$ksplash_pid" && kill "$ksplash_pid" 2>/dev/null
  324.         xmessage -geometry 600x100 "Call to lnusertemp failed (temporary directories full?). Check your installation."
  325.         exit 1
  326.     fi
  327. done
  328.  
  329. # In case of dcop sockets left by a previous session, cleanup
  330. #dcopserver_shutdown
  331.  
  332. echo 'startkde: Starting up...'  1>&2
  333.  
  334. # Make sure that D-Bus is running
  335. if test -z "$XDG_DATA_DIRS"; then
  336.     XDG_DATA_DIRS="`kde4-config --prefix`/share:/usr/share:/usr/local/share"
  337.     export XDG_DATA_DIRS
  338. fi
  339. # D-Bus autolaunch is broken
  340. if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
  341.     eval `dbus-launch --sh-syntax --exit-with-session`
  342. fi
  343. if qdbus >/dev/null 2>/dev/null; then
  344.     : # ok
  345. else
  346.     echo 'startkde: Could not start D-Bus. Can you call qdbus?'  1>&2
  347.     test -n "$ksplash_pid" && kill "$ksplash_pid" 2>/dev/null
  348.     xmessage -geometry 500x100 "Could not start D-Bus. Can you call qdbus?"
  349.     exit 1
  350. fi
  351.  
  352.  
  353. # Mark that full KDE session is running (e.g. Konqueror preloading works only
  354. # with full KDE running). The KDE_FULL_SESSION property can be detected by
  355. # any X client connected to the same X session, even if not launched
  356. # directly from the KDE session but e.g. using "ssh -X", kdesu. $KDE_FULL_SESSION
  357. # however guarantees that the application is launched in the same environment
  358. # like the KDE session and that e.g. KDE utilities/libraries are available.
  359. # KDE_FULL_SESSION property is also only available since KDE 3.5.5.
  360. # The matching tests are:
  361. #   For $KDE_FULL_SESSION:
  362. #     if test -n "$KDE_FULL_SESSION"; then ... whatever
  363. #   For KDE_FULL_SESSION property:
  364. #     xprop -root | grep "^KDE_FULL_SESSION" >/dev/null 2>/dev/null
  365. #     if test $? -eq 0; then ... whatever
  366. #
  367. # Additionally there is (since KDE 3.5.7) $KDE_SESSION_UID with the uid
  368. # of the user running the KDE session. It should be rarely needed (e.g.
  369. # after sudo to prevent desktop-wide functionality in the new user's kded).
  370. #
  371. # Since KDE4 there is also KDE_SESSION_VERSION, containing the major version number.
  372. # Note that this didn't exist in KDE3, which can be detected by its absense and
  373. # the presence of KDE_FULL_SESSION.
  374. #
  375. KDE_FULL_SESSION=true
  376. export KDE_FULL_SESSION
  377. xprop -root -f KDE_FULL_SESSION 8t -set KDE_FULL_SESSION true
  378.  
  379. KDE_SESSION_VERSION=4
  380. export KDE_SESSION_VERSION
  381. xprop -root -f KDE_SESSION_VERSION 32c -set KDE_SESSION_VERSION 4
  382.  
  383.  
  384. KDE_SESSION_UID=`id -ru`
  385. export KDE_SESSION_UID
  386.  
  387. # We set LD_BIND_NOW to increase the efficiency of kdeinit.
  388. # kdeinit unsets this variable before loading applications.
  389. LD_BIND_NOW=true /usr/lib/kde4/libexec/start_kdeinit_wrapper +kcminit_startup
  390. if test $? -ne 0; then
  391.   # Startup error
  392.   echo 'startkde: Could not start kdeinit4. Check your installation.'  1>&2
  393.   test -n "$ksplash_pid" && kill "$ksplash_pid" 2>/dev/null
  394.   xmessage -geometry 500x100 "Could not start kdeinit4. Check your installation."
  395.   exit 1
  396. fi
  397.  
  398. # If the session should be locked from the start (locked autologin),
  399. # lock now and do the rest of the KDE startup underneath the locker.
  400. if test -n "$dl"; then
  401.   kwrapper4 kscreenlocker --forcelock &
  402.   # Give it some time for starting up. This is somewhat unclean; some
  403.   # notification would be better.
  404.   sleep 1
  405. fi
  406.  
  407. # finally, give the session control to the session manager
  408. # see kdebase/ksmserver for the description of the rest of the startup sequence
  409. # if the KDEWM environment variable has been set, then it will be used as KDE's
  410. # window manager instead of kwin.
  411. # if KDEWM is not set, ksmserver will ensure kwin is started.
  412. # kwrapper4 is used to reduce startup time and memory usage
  413. # kwrapper4 does not return useful error codes such as the exit code of ksmserver.
  414. # We only check for 255 which means that the ksmserver process could not be
  415. # started, any problems thereafter, e.g. ksmserver failing to initialize,
  416. # will remain undetected.
  417. test -n "$KDEWM" && KDEWM="--windowmanager $KDEWM"
  418. kwrapper4 ksmserver $KDEWM
  419. if test $? -eq 255; then
  420.   # Startup error
  421.   echo 'startkde: Could not start ksmserver. Check your installation.'  1>&2
  422.   test -n "$ksplash_pid" && kill "$ksplash_pid" 2>/dev/null
  423.   xmessage -geometry 500x100 "Could not start ksmserver. Check your installation."
  424. fi
  425.  
  426. # wait if there's any crashhandler shown
  427. while qdbus | grep "^[^w]*org.kde.drkonqi" > /dev/null ; do
  428.     sleep 5
  429. done
  430.  
  431. echo 'startkde: Shutting down...'  1>&2
  432. # just in case
  433. test -n "$ksplash_pid" && kill "$ksplash_pid" 2>/dev/null
  434.  
  435. # Clean up
  436. kdeinit4_shutdown
  437. # KDE3 support
  438. kde3 kdeinit_shutdown 2>/dev/null
  439. kde3 dcopserver_shutdown --wait 2>/dev/null
  440.  
  441. echo 'startkde: Running shutdown scripts...'  1>&2
  442.  
  443. # Run scripts found in $KDEDIRS/shutdown
  444. for prefix in `echo "$libpath" | sed -n -e 's,/lib[^/]*/,/shutdown/,p'`; do
  445.   for file in `ls "$prefix" 2> /dev/null | egrep -v '(~|\.bak)$'`; do
  446.     test -x "$prefix$file" && "$prefix$file"
  447.   done
  448. done
  449.  
  450. unset KDE_FULL_SESSION
  451. xprop -root -remove KDE_FULL_SESSION
  452. unset KDE_SESSION_VERSION
  453. xprop -root -remove KDE_SESSION_VERSION
  454. unset KDE_SESSION_UID
  455.  
  456. echo 'startkde: Done.'  1>&2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement