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 there any way to create a hook to send notice when password is required? #2349

Open
Karmenzind opened this issue Jan 25, 2024 · 3 comments
Labels
Status: Discussion Open Topic is being considered and open for discussion Type: Feature Request

Comments

@Karmenzind
Copy link

If yay is performing a time-consuming building process, I often forget about it. Then I find it has encountered an error because I didn't input the password.

Is there any way to create a hook (e.g. invoke notify-send) to send a notice in this case?

@Karmenzind Karmenzind added Status: Discussion Open Topic is being considered and open for discussion Type: Feature Request labels Jan 25, 2024
@jdholtz
Copy link
Contributor

jdholtz commented Jan 25, 2024

You can use yay -Y --sudoflags "-B" --save for a terminal bell to ring every time sudo prompts. If you want a more custom way of sending a notification or some other notifier, you can write a wrapper around sudo and use that as the sudobin config option.

@jdholtz
Copy link
Contributor

jdholtz commented Jul 7, 2024

Hey @Karmenzind, does my above comment answer your question?

@Karmenzind
Copy link
Author

Karmenzind commented Jul 9, 2024

Sorry forgot to give feedback. Thanks for your advice. I think the terminal bell might be helpful in common cases (though not to me).

As for the wrapper, I wrote a script and put it in /etc/pam.d/sudo but not working.
Seems that the exit code is returned by notify-send. I tried adding DBUS session variable and still no luck. I was busy then so I gave up. 😢

Oh I fixed the wrapper just now:
image

~ % cat /etc/pam.d/sudo
#%PAM-1.0
auth            optional pam_exec.so /usr/local/bin/sudo_notify.sh
auth            include         system-auth
account         include         system-auth
session         include         system-auth

~ % cat /usr/local/bin/sudo_notify.sh
#!/usr/bin/env bash

export DISPLAY=:0
eval $(dbus-launch --sh-syntax)
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
# if ! [[ -f $DBUS_SESSION_BUS_ADDRESS ]]; then
#     export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME i3)/environ | cut -d= -f2-)
# fi

notify-send "Sudo Alert" "Please enter your password to proceed."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Discussion Open Topic is being considered and open for discussion Type: Feature Request
Projects
None yet
Development

No branches or pull requests

2 participants