baodrate / snap-sync

Use snapper snapshots to backup to external drive
GNU General Public License v2.0
130 stars 38 forks source link

Doesn't work without sudo #119

Open c-c-6ypo8 opened 9 months ago

c-c-6ypo8 commented 9 months ago

I don't have sudo in my system and I don't want to use it. So my snap-sync tells this after run without arguments:

root is not in the sudoers file.
root is not in the sudoers file.
Exited due to error on line 163.
exit status: 1
command: sudo -u $u DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus notify-send -a $name "$1" "$2" --icon="dialog-$3"
bash line: 171
function name: notify
c-c-6ypo8 commented 9 months ago

Also, even if I added root in sudoers, I get another error at line 163 because users command generates root user because I am logged in as root (because of not using sudo). So, your script doesn't respect non-sudo linux use. Also with sudo use it generates error if the root is logged in (because root cannot connect to DISPLAY to get notification). So I've fixed notify function to:

notify() {
    for u in $(users | tr ' ' '\n' | sort -u); do
        if [ $u != 'root' ]; then # I've added this line
          sudo -u $u DISPLAY=:0 \ 
          DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus \
          notify-send -a $name "$1" "$2" --icon="dialog-$3"
        fi
    done
}

And this variant seems to work properly (with root added to sudoers). But fully no-sudo variant still isn't working.