#!/bin/sh

PATH=/sbin:/usr/sbin:/bin:/usr/bin
NAME="kde-cheatcodes"

if [ -r /etc/default/distro ]; then
    . /etc/default/distro
fi

. /lib/lsb/init-functions
. /lib/init/fll

if [ -r /etc/default/fll-locales ]; then
    . /etc/default/fll-locales
fi

FLL_LIVE_USER_HOME=$(getent passwd ${FLL_LIVE_USER} | cut -d \: -f 6)

###
# cheatcode handling
###
for param in $(cat /proc/cmdline); do
   case "${param}" in
      flldebug=*)
          if [ "${param#flldebug=}" = "${NAME}" ] || [ "${param#flldebug=}" = "all" ]; then
              fll_redirect
          fi
          ;;
      nointro)
          NOINTRO="nointro"
          ;;
   esac
done

no_intro() {
    if [ -z "${NOINTRO}"  ] ; then
        [ ! -f ${FLL_LIVE_USER_HOME}/.kde/Autostart/${FLL_DISTRO_NAME}.desktop ] && sudo -u ${FLL_LIVE_USER} ln -sf "${FLL_LIVE_USER_HOME}/Desktop/${FLL_DISTRO_NAME}.desktop" \
            "${FLL_LIVE_USER_HOME}/.kde/Autostart/"
    elif [ -e "${FLL_LIVE_USER_HOME}/.kde/Autostart/${FLL_DISTRO_NAME}.desktop" ]; then
        # toram + persistency
        rm -f "${FLL_LIVE_USER_HOME}/.kde/Autostart/${FLL_DISTRO_NAME}.desktop"
    fi
}

do_start() {
    if [ -f ${FLL_LIVE_USER_HOME}/Desktop/${FLL_DISTRO_NAME}.desktop  ]; then
        no_intro
    fi
}

case "${1}" in
    start)
        log_daemon_msg "${NAME}"
        do_start
        log_end_msg "${?}"
        ;;
    stop)
        ;;
    restart|force-reload)
        echo "Error: argument '${1}' not supported" >&2
        exit 3
        ;;
    *)
        echo "Usage: ${NAME} {start|stop}" >&2
        exit 3
        ;;
esac

