Skip to content

Instantly share code, notes, and snippets.

@rusty-snake
Last active October 22, 2020 10:34
Show Gist options
  • Save rusty-snake/042e7df8545a987fd368d2b02e1c3782 to your computer and use it in GitHub Desktop.
Save rusty-snake/042e7df8545a987fd368d2b02e1c3782 to your computer and use it in GitHub Desktop.
firejail_blacklist_violation_notify.sh - Notifications on blacklist violations, useful for debugging
#!/usr/bin/env bash
# Copyright © 2019,2020 rusty-snake
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
function usage {
echo "Usage:"
echo -e "\tNOTIFY_TOOL=\"<ZENITY|KDIALOG|NOTIFY-SEND>\" $0"
}
if [ "$1" == "--help" ] || [ "$1" == "-h" ] || [ "$1" == "-?" ]; then
usage "$@"
exit 0
fi
if [ ! -v "NOTIFY_TOOL" ]; then
printf "Error: \"NOTIFY_TOOL\" not set.\n"
usage "$@"
exit 1
fi
if [ "$NOTIFY_TOOL" == "ZENITY" ]; then
notify_cmd="zenity"
notify_args=(--title "Blacklist violation" --no-wrap --warning --text)
elif [ "$NOTIFY_TOOL" == "KDIALOG" ]; then
notify_cmd="kdialog"
notify_args=(--title "Blacklist violation" --sorry)
elif [ "$NOTIFY_TOOL" == "NOTIFY-SEND" ]; then
notify_cmd="notify-send"
notify_args=(--icon "dialog-warning" "Blacklist violation")
else
printf "Error: Invalid value for NOTIFY_TOOL.\n"
usage "$@"
exit 1
fi
journalctl --grep="blacklist violation - sandbox" --output=json --follow | jq --unbuffered ".MESSAGE" | xargs -L1 -P0 "$notify_cmd" "${notify_args[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment