File opensnitch-ui-actions of Package opensnitch
#!/bin/bash
#
# opensnitch-ui-actions wrapper
#
# Author: munix9@googlemail.com
# License: GPL-3.0-only
#
export TEXTDOMAIN="opensnitch-ui-actions"
export TEXTDOMAINDIR="/usr/share/locale"
_mode="$1"
_xdg_desktop="/etc/xdg/autostart/opensnitch_ui.desktop"
_home_desktop="$HOME/.config/autostart/opensnitch_ui.desktop"
_t () {
local t="${1:-???}"
echo "$(gettext -s "$t")"
}
notify_info () {
local m="${1:-???}"
local a="$2"
m="$(_t "$m")"
[[ -n $a ]] && m+="\n<i>$a</i>"
notify-send -u normal -i opensnitch-ui "$(_t "OpenSnitch info")" "$m"
exit 0
}
notify_warn () {
local m="${1:-???}"
local a="$2"
m="$(_t "$m")"
[[ -n $a ]] && m+="\n<i>$a</i>"
notify-send -u critical -i opensnitch-ui "$(_t "OpenSnitch warning")" "$m"
exit 1
}
case "$_mode" in
*-local-daemon)
systemctl -q status opensnitchd.service >/dev/null 2>&1
[[ $? -eq 4 ]] && notify_warn "The local OpenSnitch daemon is not installed!"
;;
esac
case "$_mode" in
check-ui-autostart)
_ms="enabled"
grep -qs "^Hidden=true" "$_home_desktop"
[[ $? -ne 0 ]] && _ms="disabled"
notify_info "The OpenSnitch UI autostart is ${_ms}."
;;
enable-ui-autostart)
rm -f "$_home_desktop"
notify_info "The OpenSnitch UI autostart is enabled."
;;
disable-ui-autostart)
mkdir -p "$(dirname "$_home_desktop")" && \
sed -e 's/^Hidden=false.*/Hidden=true/g' "$_xdg_desktop" > "$_home_desktop"
grep -qs "^Hidden=true" "$_home_desktop"
[[ $? -eq 0 ]] && notify_info "The OpenSnitch UI autostart is disabled."
notify_warn "The OpenSnitch UI autostart could not be disabled!"
;;
check-local-daemon)
_ms="enabled"
systemctl -q is-active opensnitchd.service
[[ $? -ne 0 ]] && _ms="disabled"
notify_info "The local OpenSnitch daemon is ${_ms}."
;;
enable-local-daemon)
xdg-su -c 'systemctl -q enable --now opensnitchd.service'
systemctl -q is-active opensnitchd.service
[[ $? -eq 0 ]] && notify_info "The local OpenSnitch daemon is enabled."
_ms="$(systemctl status opensnitchd.service)"
notify_warn "The local OpenSnitch daemon could not be enabled!" "$_ms"
;;
disable-local-daemon)
xdg-su -c 'systemctl -q disable --now opensnitchd.service'
systemctl -q is-active opensnitchd.service
[[ $? -ne 0 ]] && notify_info "The local OpenSnitch daemon is disabled."
_ms="$(systemctl status opensnitchd.service)"
notify_warn "The local OpenSnitch daemon could not be disabled!" "$_ms"
;;
*)
_ms="Missing option/action!"
[[ -n $_mode ]] && _ms="Invalid option/action '$_mode'!"
notify_warn "$_ms"
;;
esac