Blame SOURCES/startkde.cmake

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