Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is it necessary to hardcode the user name and ID in the script for root? #15

Open
pmav99 opened this issue Jan 30, 2021 · 2 comments
Open

Comments

@pmav99
Copy link

pmav99 commented Jan 30, 2021

In the readme it is mentioned that in order to use the script for root you must hardcode the user name and the user id.

I think it is not really necessary to hardcode them. Is there something wrong with:

user_name=$(id -un)
user_id=$(id -u)
user_group=$(id -g)

echo "${user_name}"
echo "${user_id}"
echo "${user_group}"
@phuhl
Copy link
Owner

phuhl commented Feb 2, 2021

Hi @pmav99, really I put that snippet into the README because it was a pain for me to get it to work and when I did, I didn't spend much time on perfecting it. If the solution you propose actually works, it certainly is superior to hardcoding. I will try it, thanks for the heads up!

@phuhl
Copy link
Owner

phuhl commented Feb 18, 2021

Hi @pmav99, does the suggestion you made work for you?

I just tried this script:

#!/bin/bash

USERNAME=$(id -un)
USERID=$(id -u)
USERGROUP=$(id -g)

export XAUTHORITY=/home/$USERNAME/.Xauthority
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$USERID/bus

if [ "$(/usr/bin/id -u)" != "$USERID" ] ; then
    sudo -u $USERNAME XAUTHORITY=/home/$USERNAME/.Xauthority DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$USERID/bus /usr/bin/notify-send.py "$@"
else
    /usr/bin/notify-send.py "$@"
fi

Running sudo allUserNotifySend test gives me an error, that there is no such thing as /run/user/0/bus, which makes sense, I guess.
So it clearly does not work on my system. Am I doing it wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants