#!/bin/bash
SOURCE="$0"
source /usr/lib/elive-tools/functions
#EL_REPORTS="1"
el_make_environment

main(){
    # restart notification daemon to avoid the messages not appear after a while
    if [[ -n "$EROOT" ]] ; then
        # make sure we want it running:
        if [[ -n "$DBUS_SESSION_BUS_ADDRESS" ]] ; then
            DBUS_SESSION_BUS_ADDRESS_file="${DBUS_SESSION_BUS_ADDRESS#unix:path=}"
            if [[ "${DBUS_SESSION_BUS_ADDRESS_file}" = /* ]] && ! test -S "$DBUS_SESSION_BUS_ADDRESS_file" ; then
                el_warning "DBUS_SESSION_BUS_ADDRESS file '$DBUS_SESSION_BUS_ADDRESS_file' does not exist or is not a socket, cannot restart notification-daemon"
                exit 1
            fi

        else
            el_warning "DBUS_SESSION_BUS_ADDRESS variable does not exist, cannot restart notification-daemon"
            exit 1
        fi

        # all good, continue restarting
        if grep -qs "^/usr/lib/notification-daemon/notification-daemon" "$HOME/.e16/startup-applications.list" 2>/dev/null ; then
            kill $(pidof notification-daemon 2>/dev/null ) >/dev/null 2>&1 || true
            LC_ALL=C sleep 0.3
            ( /usr/lib/notification-daemon/notification-daemon & )
            sleep 2
        fi
    fi
}

#
#  MAIN
#
main "$@"

# vim: set foldmethod=marker :
