diff --git a/jobhelper.sh b/jobhelper.sh index d413db4805b6960279b378b270847d0f22779bc3..02271ef1b026e8a192549cbcbd477178dc3dfe00 100755 --- a/jobhelper.sh +++ b/jobhelper.sh @@ -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".