Skip to content
Snippets Groups Projects
Commit 7efe01f8 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

add function for desktop notification

parent a6465e40
Branches
No related tags found
1 merge request!101Desktop notification
......@@ -82,6 +82,11 @@ function j_init(){
j_requireBinary "tee"
j_requireBinary "touch"
# for notify-send in j_notify()
if [ -n "$SUDO_USER" ]; then
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u $SUDO_USER)/bus
fi
# j_read
}
......@@ -419,6 +424,30 @@ function _getFqdn(){
# echo "INFO: FQDN is [$FQDN]"
}
# show a desktop notification using notify-send
# param string summary (aka title)
# param string message text
# paran integer optional: exitcode; if set it adds a prefix OK or ERRROR on summary and sets urgency on error
function j_notify(){
local _summary="IML BACKUP :: $1"
local _body="$2"
local _rc="$3"
local _urgency="normal"
if [ -n "$DBUS_SESSION_BUS_ADDRESS" ]; then
if [ -n "$_rc" ]; then
if [ "$_rc" = "0" ]; then
_summary="OK: ${_summary}"
else
_summary="ERROR: ${_summary}"
_urgency="critical"
fi
fi
su "$SUDO_USER" -c "notify-send --urgency=${_urgency} '${_summary}' '${_body}'"
fi
}
# ------------------------------------------------------------
# check if it was startet with a given user
# This is skipped if MS windows was detected with "mingw".
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment