Skip to content

Instantly share code, notes, and snippets.

Created January 1, 2019 18:41
Show Gist options
  • Save rugk/af78c111267fb41e86259c0b46fb4a87 to your computer and use it in GitHub Desktop.
Save rugk/af78c111267fb41e86259c0b46fb4a87 to your computer and use it in GitHub Desktop.
old manual notification zenity proxy method for borbbackup-cron-helper
  1. In the borg script you need to set, at least:

    # variable from user where notification should be shown, is usually static

    If it does not work, you may need to set export DISPLAY=:0.

  2. In some cases (e.g. when using Wayland) you may additionally need to allow the user to access your Xorg server. Note that only root should be allowed to do that or a user, who is really only running borg. As the user where the notification should be shown execute: xhost +SI:localuser:<user running borg> This has to be done at each login, as the setting does not persist. Alternatively use su to execute zenity as the user, where the notification should be shown. For this a zenityProxy function is built-in:

    zenityProxy() {
    	if [ -z "$1" ]; then # let script verify this proxy is there
    		return 0 # (true)
    	# execute command as different user
    	su <notification user> -c "zenity $*"

    As this makes use of su, it of course only works for root. If you want to do it in a complicated way, you could use sudo and edit your sudoers file to allow a different user to use sudo. Just make sure, you keep your system secure.

    Or try to get and set the XAUTHORITY variable. In older versions this is been /home/<notification user>/.Xauthority.

    This has been tested with a systemd-enabled distro. Further tests and adjustions are very much appreciated. If you do not want to hardcode the user you can use this function to get all active users. Note that however, in this case, the DBUS_SESSION_BUS_ADDRESS address may be different and you may need to get the correct one for the user. If you want to include all users you can just use the command users. But you may also need to adjust the DBUS_SESSION_BUS_ADDRESS variable (try DBUS_SESSION_BUS_ADDRESS=$( su <notification user> -c 'echo $DBUS_SESSION_BUS_ADDRESS' )).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment