ff3475
#!/bin/sh
ff3475
#
ff3475
#  DEFAULT KDE STARTUP SCRIPT ( @KDE4WORKSPACE_VERSION@ )
ff3475
#
ff3475
ff3475
if test "x$1" = x--failsafe; then
ff3475
    KDE_FAILSAFE=1 # General failsafe flag
ff3475
    KWIN_COMPOSE=N # Disable KWin's compositing
ff3475
    export KWIN_COMPOSE KDE_FAILSAFE
ff3475
fi
ff3475
ff3475
# When the X server dies we get a HUP signal from xinit. We must ignore it
ff3475
# because we still need to do some cleanup.
ff3475
trap 'echo GOT SIGHUP' HUP
ff3475
ff3475
# we have to unset this for Darwin since it will screw up KDE's dynamic-loading
ff3475
unset DYLD_FORCE_FLAT_NAMESPACE
ff3475
ff3475
qdbus=qdbus
ff3475
ff3475
# See http://bugzilla.redhat.com/537609 , a naive attempt to drop dep 
ff3475
# on xmessage and allow alternatives like zenity.  
ff3475
message() {
ff3475
  xmessage -geometry 500x100 "$1" > /dev/null 2>/dev/null || \
ff3475
    zenity --info --text="$1" > /dev/null 2>/dev/null ||:
ff3475
  return $?
ff3475
}
ff3475
ff3475
# Check if a KDE session already is running and whether it's possible to connect to X
ff3475
kcheckrunning
ff3475
kcheckrunning_result=$?
ff3475
if test $kcheckrunning_result -eq 0 ; then
ff3475
	echo "KDE seems to be already running on this display."
ff3475
        message "KDE seems to be already running on this display." > /dev/null 2>/dev/null
ff3475
	exit 1
ff3475
elif test $kcheckrunning_result -eq 2 ; then
ff3475
	echo "\$DISPLAY is not set or cannot connect to the X server."
ff3475
        exit 1
ff3475
fi
ff3475
ff3475
# Boot sequence:
ff3475
#
ff3475
# kdeinit is used to fork off processes which improves memory usage
ff3475
# and startup time.
ff3475
#
ff3475
# * kdeinit starts klauncher first.
ff3475
# * Then kded is started. kded is responsible for keeping the sycoca
ff3475
#   database up to date. When an up to date database is present it goes
ff3475
#   into the background and the startup continues.
ff3475
# * Then kdeinit starts kcminit. kcminit performs initialisation of
ff3475
#   certain devices according to the user's settings
ff3475
#
ff3475
# * Then ksmserver is started which takes control of the rest of the startup sequence
ff3475
ff3475
# The user's personal KDE directory is usually ~/.kde, but this setting
ff3475
# may be overridden by setting KDEHOME.
ff3475
ff3475
kdehome=$HOME/@KDE_DEFAULT_HOME@
ff3475
test -n "$KDEHOME" && kdehome=`echo "$KDEHOME"|sed "s,^~/,$HOME/,"`
ff3475
ff3475
# see kstartupconfig source for usage
ff3475
mkdir -m 700 -p $kdehome
ff3475
mkdir -m 700 -p $kdehome/share
ff3475
mkdir -m 700 -p $kdehome/share/config
ff3475
cat >$kdehome/share/config/startupconfigkeys <
ff3475
kcminputrc Mouse cursorTheme 'Oxygen_White'
ff3475
kcminputrc Mouse cursorSize ''
ff3475
ksplashrc KSplash Theme Default
ff3475
ksplashrc KSplash Engine KSplashX
ff3475
krandrrc Display ApplyOnStartup false
ff3475
krandrrc Display StartupCommands ''
ff3475
krandrrc [Screen0]
ff3475
krandrrc [Screen1]
ff3475
krandrrc [Screen2]
ff3475
krandrrc [Screen3]
ff3475
kcmfonts General forceFontDPI 0
ff3475
kdeglobals Locale Language '' # trigger requesting languages from KLocale
ff3475
kdeglobals Locale Country ''
ff3475
EOF
ff3475
# read the default KSplash theme to use out of kde-settings
ff3475
if [ -e /usr/share/kde-settings/kde-profile/default/share/config/ksplashrc ]
ff3475
  then eval `grep '^Theme=' /usr/share/kde-settings/kde-profile/default/share/config/ksplashrc`
ff3475
       if [ -n "$Theme" ]
ff3475
         then sed -i -e "s/Default/$Theme/g" $kdehome/share/config/startupconfigkeys
ff3475
       fi
ff3475
fi
ff3475
kstartupconfig4
ff3475
returncode=$?
ff3475
if test $returncode -ne 0; then
ff3475
    message "kstartupconfig4 does not exist or fails. The error code is $returncode. Check your installation."
ff3475
    exit 1
ff3475
fi
ff3475
[ -r $kdehome/share/config/startupconfig ] && . $kdehome/share/config/startupconfig
ff3475
ff3475
# XCursor mouse theme needs to be applied here to work even for kded or ksmserver
ff3475
if test -n "$kcminputrc_mouse_cursortheme" -o -n "$kcminputrc_mouse_cursorsize" ; then
ff3475
    @EXPORT_XCURSOR_PATH@
ff3475
ff3475
    kapplymousetheme "$kcminputrc_mouse_cursortheme" "$kcminputrc_mouse_cursorsize"
ff3475
    if test $? -eq 10; then
ff3475
        XCURSOR_THEME=default
ff3475
        export XCURSOR_THEME
ff3475
    elif test -n "$kcminputrc_mouse_cursortheme"; then
ff3475
        XCURSOR_THEME="$kcminputrc_mouse_cursortheme"
ff3475
        export XCURSOR_THEME
ff3475
    fi
ff3475
    if test -n "$kcminputrc_mouse_cursorsize"; then
ff3475
        XCURSOR_SIZE="$kcminputrc_mouse_cursorsize"
ff3475
        export XCURSOR_SIZE
ff3475
    fi
ff3475
fi
ff3475
ff3475
KRANDRSTARTUP=`which krandrstartup 2>/dev/null` && . $KRANDRSTARTUP
ff3475
ff3475
if test "$kcmfonts_general_forcefontdpi" -ne 0; then
ff3475
    xrdb -quiet -merge -nocpp <
ff3475
Xft.dpi: $kcmfonts_general_forcefontdpi
ff3475
EOF
ff3475
fi
ff3475
ff3475
ff3475
dl=$DESKTOP_LOCKED
ff3475
unset DESKTOP_LOCKED # Don't want it in the environment
ff3475
ff3475
ksplash_pid=
ff3475
if test -z "$dl"; then
ff3475
  # languages as resolved by KLocale, for the splash screens use
ff3475
  # klocale_languages is assembled by kdostartupconfig4 calling KLocale
ff3475
  KLOCALE_LANGUAGES="$klocale_languages"
ff3475
  export KLOCALE_LANGUAGES
ff3475
  # the splashscreen and progress indicator
ff3475
  case "$ksplashrc_ksplash_engine" in
ff3475
    KSplashX)
ff3475
      ksplash_pid=`ksplashx "${ksplashrc_ksplash_theme}" --pid`
ff3475
      ;;
ff3475
    KSplashQML)
ff3475
      ksplash_pid=`ksplashqml "${ksplashrc_ksplash_theme}" --pid`
ff3475
      ;;
ff3475
    None)
ff3475
      ;;
ff3475
    Simple)
ff3475
      ksplash_pid=`ksplashsimple "${ksplashrc_ksplash_theme}" --pid`
ff3475
      ;;
ff3475
    *)
ff3475
      ;;
ff3475
  esac
ff3475
  # no longer needed in the environment
ff3475
  unset KLOCALE_LANGUAGES
ff3475
fi
ff3475
ff3475
# Source scripts found in <localprefix>/env/*.sh and <prefixes>/env/*.sh
ff3475
# (where <localprefix> is $KDEHOME or ~/.kde, and <prefixes> is where KDE is installed)
ff3475
#
ff3475
# This is where you can define environment variables that will be available to
ff3475
# all KDE programs, so this is where you can run agents using e.g. eval `ssh-agent`
ff3475
# or eval `gpg-agent --daemon`.
ff3475
# Note: if you do that, you should also put "ssh-agent -k" as a shutdown script
ff3475
#
ff3475
# (see end of this file).
ff3475
# For anything else (that doesn't set env vars, or that needs a window manager),
ff3475
# better use the Autostart folder.
ff3475
ff3475
libpath=`kde4-config --path lib | tr : '\n'`
ff3475
envpath=/etc/kde/env/
ff3475
ff3475
for prefix in `echo "$libpath" | sed -n -e 's,/lib[^/]*/,/env/,p'` $envpath ; do
ff3475
  for file in "$prefix"*.sh; do
ff3475
    test -r "$file" && . "$file"
ff3475
  done
ff3475
done
ff3475
ff3475
# Set the path for Qt plugins provided by KDE
ff3475
QT_PLUGIN_PATH=${QT_PLUGIN_PATH+$QT_PLUGIN_PATH:}`kde4-config --path qtplugins`
ff3475
export QT_PLUGIN_PATH
ff3475
ff3475
# Set a left cursor instead of the standard X11 "X" cursor, since I've heard
ff3475
# from some users that they're confused and don't know what to do. This is
ff3475
# especially necessary on slow machines, where starting KDE takes one or two
ff3475
# minutes until anything appears on the screen.
ff3475
#
ff3475
# If the user has overwritten fonts, the cursor font may be different now
ff3475
# so don't move this up.
ff3475
#
ff3475
xsetroot -cursor_name left_ptr
ff3475
ff3475
# Get Ghostscript to look into user's KDE fonts dir for additional Fontmap
ff3475
if test -n "$GS_LIB" ; then
ff3475
    GS_LIB=$usr_fdir:$GS_LIB
ff3475
    export GS_LIB
ff3475
else
ff3475
    GS_LIB=$usr_fdir
ff3475
    export GS_LIB
ff3475
fi
ff3475
ff3475
lnusertemp=`kde4-config --path exe --locate lnusertemp`
ff3475
if test -z "$lnusertemp"; then
ff3475
  # Startup error
ff3475
  echo 'startkde: ERROR: Could not locate lnusertemp in '`kde4-config --path exe` 1>&2
ff3475
fi
ff3475
ff3475
# Link "tmp" "socket" and "cache" resources to directory in /tmp
ff3475
# Creates:
ff3475
# - a directory /tmp/kde-$USER and links $KDEHOME/tmp-$HOSTNAME to it.
ff3475
# - a directory /tmp/ksocket-$USER and links $KDEHOME/socket-$HOSTNAME to it.
ff3475
# - a directory /var/tmp/kdecache-$USER and links $KDEHOME/cache-$HOSTNAME to it.
ff3475
# Note: temporary locations can be overriden through the KDETMP and KDEVARTMP
ff3475
# environment variables
ff3475
for resource in tmp cache socket; do
ff3475
    if "$lnusertemp" $resource >/dev/null; then
ff3475
        : # ok
ff3475
    else
ff3475
        echo 'startkde: Call to lnusertemp failed (temporary directories full?). Check your installation.'  1>&2
ff3475
        test -n "$ksplash_pid" && kill "$ksplash_pid" 2>/dev/null
ff3475
        message "Call to lnusertemp failed (temporary directories full?). Check your installation."
ff3475
        exit 1
ff3475
    fi
ff3475
done
ff3475
ff3475
# In case of dcop sockets left by a previous session, cleanup
ff3475
#dcopserver_shutdown
ff3475
ff3475
echo 'startkde: Starting up...'  1>&2
ff3475
ff3475
# Make sure that D-Bus is running
ff3475
# D-Bus autolaunch is broken
ff3475
if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
ff3475
    eval `dbus-launch --sh-syntax --exit-with-session`
ff3475
fi
ff3475
if $qdbus >/dev/null 2>/dev/null; then
ff3475
    : # ok
ff3475
else
ff3475
    echo 'startkde: Could not start D-Bus. Can you call qdbus?'  1>&2
ff3475
    test -n "$ksplash_pid" && kill "$ksplash_pid" 2>/dev/null
ff3475
    message "Could not start D-Bus. Can you call qdbus?"
ff3475
    exit 1
ff3475
fi
ff3475
ff3475
ff3475
# Mark that full KDE session is running (e.g. Konqueror preloading works only
ff3475
# with full KDE running). The KDE_FULL_SESSION property can be detected by
ff3475
# any X client connected to the same X session, even if not launched
ff3475
# directly from the KDE session but e.g. using "ssh -X", kdesu. $KDE_FULL_SESSION
ff3475
# however guarantees that the application is launched in the same environment
ff3475
# like the KDE session and that e.g. KDE utilities/libraries are available.
ff3475
# KDE_FULL_SESSION property is also only available since KDE 3.5.5.
ff3475
# The matching tests are:
ff3475
#   For $KDE_FULL_SESSION:
ff3475
#     if test -n "$KDE_FULL_SESSION"; then ... whatever
ff3475
#   For KDE_FULL_SESSION property:
ff3475
#     xprop -root | grep "^KDE_FULL_SESSION" >/dev/null 2>/dev/null
ff3475
#     if test $? -eq 0; then ... whatever
ff3475
#
ff3475
# Additionally there is (since KDE 3.5.7) $KDE_SESSION_UID with the uid
ff3475
# of the user running the KDE session. It should be rarely needed (e.g.
ff3475
# after sudo to prevent desktop-wide functionality in the new user's kded).
ff3475
#
ff3475
# Since KDE4 there is also KDE_SESSION_VERSION, containing the major version number.
ff3475
# Note that this didn't exist in KDE3, which can be detected by its absense and
ff3475
# the presence of KDE_FULL_SESSION.
ff3475
#
ff3475
KDE_FULL_SESSION=true
ff3475
export KDE_FULL_SESSION
ff3475
xprop -root -f KDE_FULL_SESSION 8t -set KDE_FULL_SESSION true
ff3475
ff3475
KDE_SESSION_VERSION=4
ff3475
export KDE_SESSION_VERSION
ff3475
xprop -root -f KDE_SESSION_VERSION 32c -set KDE_SESSION_VERSION 4
ff3475
ff3475
KDE_SESSION_UID=`id -ru`
ff3475
export KDE_SESSION_UID
ff3475
ff3475
XDG_CURRENT_DESKTOP=KDE
ff3475
export XDG_CURRENT_DESKTOP
ff3475
ff3475
# At this point all the environment is ready, let's send it to kwalletd if running
ff3475
if test -n "$PAM_KWALLET_LOGIN" ; then
ff3475
  env | socat STDIN UNIX-CONNECT:$PAM_KWALLET_LOGIN
ff3475
fi
ff3475
ff3475
@KDE4_LIBEXEC_INSTALL_DIR@/start_kdeinit_wrapper +kcminit_startup
ff3475
if test $? -ne 0; then
ff3475
  # Startup error
ff3475
  echo 'startkde: Could not start kdeinit4. Check your installation.'  1>&2
ff3475
  test -n "$ksplash_pid" && kill "$ksplash_pid" 2>/dev/null
ff3475
  message "Could not start kdeinit4. Check your installation."
ff3475
  exit 1
ff3475
fi
ff3475
ff3475
# finally, give the session control to the session manager
ff3475
# see kdebase/ksmserver for the description of the rest of the startup sequence
ff3475
# if the KDEWM environment variable has been set, then it will be used as KDE's
ff3475
# window manager instead of kwin.
ff3475
# if KDEWM is not set, ksmserver will ensure kwin is started.
ff3475
# kwrapper4 is used to reduce startup time and memory usage
ff3475
# kwrapper4 does not return useful error codes such as the exit code of ksmserver.
ff3475
# We only check for 255 which means that the ksmserver process could not be
ff3475
# started, any problems thereafter, e.g. ksmserver failing to initialize,
ff3475
# will remain undetected.
ff3475
test -n "$KDEWM" && KDEWM="--windowmanager $KDEWM"
ff3475
# If the session should be locked from the start (locked autologin),
ff3475
# lock now and do the rest of the KDE startup underneath the locker.
ff3475
KSMSERVEROPTIONS=""
ff3475
test -n "$dl" && KSMSERVEROPTIONS=" --lockscreen"
ff3475
kwrapper4 ksmserver $KDEWM $KSMSERVEROPTIONS
ff3475
if test $? -eq 255; then
ff3475
  # Startup error
ff3475
  echo 'startkde: Could not start ksmserver. Check your installation.'  1>&2
ff3475
  test -n "$ksplash_pid" && kill "$ksplash_pid" 2>/dev/null
ff3475
  message "Could not start ksmserver. Check your installation."
ff3475
fi
ff3475
ff3475
wait_drkonqi=`kreadconfig --file startkderc --group WaitForDrKonqi --key Enabled --default true`
ff3475
ff3475
if test x"$wait_drkonqi"x = x"true"x ; then
ff3475
    # wait for remaining drkonqi instances with timeout (in seconds)
ff3475
    wait_drkonqi_timeout=`kreadconfig --file startkderc --group WaitForDrKonqi --key Timeout --default 900`
ff3475
    wait_drkonqi_counter=0
ff3475
    while $qdbus | grep "^[^w]*org.kde.drkonqi" > /dev/null ; do
ff3475
        sleep 5
ff3475
        wait_drkonqi_counter=$((wait_drkonqi_counter+5))
ff3475
        if test "$wait_drkonqi_counter" -ge "$wait_drkonqi_timeout" ; then
ff3475
            # ask remaining drkonqis to die in a graceful way
ff3475
            $qdbus | grep 'org.kde.drkonqi-' | while read address ; do
ff3475
                $qdbus "$address" "/MainApplication" "quit"
ff3475
            done
ff3475
            break
ff3475
        fi
ff3475
    done
ff3475
fi
ff3475
ff3475
echo 'startkde: Shutting down...'  1>&2
ff3475
# just in case
ff3475
test -n "$ksplash_pid" && kill "$ksplash_pid" 2>/dev/null
ff3475
ff3475
# Clean up
ff3475
kdeinit4_shutdown
ff3475
# KDE3 support
ff3475
kde3 kdeinit_shutdown 2>/dev/null
ff3475
kde3 dcopserver_shutdown --wait 2>/dev/null
ff3475
ff3475
echo 'startkde: Running shutdown scripts...'  1>&2
ff3475
ff3475
# Run scripts found in $KDEDIRS/shutdown
ff3475
shutdownpath=/etc/kde/shutdown/
ff3475
for prefix in `echo "$libpath" | sed -n -e 's,/lib[^/]*/,/shutdown/,p'` $shutdownpath; do
ff3475
  for file in `ls "$prefix" 2> /dev/null | egrep -v '(~|\.bak)$'`; do
ff3475
    test -x "$prefix$file" && "$prefix$file"
ff3475
  done
ff3475
done
ff3475
ff3475
unset KDE_FULL_SESSION
ff3475
xprop -root -remove KDE_FULL_SESSION
ff3475
unset KDE_SESSION_VERSION
ff3475
xprop -root -remove KDE_SESSION_VERSION
ff3475
unset KDE_SESSION_UID
ff3475
ff3475
echo 'startkde: Done.'  1>&2