Blame SOURCES/startkde.cmake

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