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

Pacman hook #33

Open
dbrgn opened this issue May 12, 2020 · 9 comments
Open

Pacman hook #33

dbrgn opened this issue May 12, 2020 · 9 comments

Comments

@dbrgn
Copy link
Collaborator

dbrgn commented May 12, 2020

This hook runs reboot-arch-btw when linux is upgraded:

danilo@x2000:~$ cat /usr/share/libalpm/hooks/99-reboot-arch-btw.hook
[Trigger]
Type = Package
Target = linux
Operation = Upgrade

[Action]
Description = Check whether a reboot is required
Depends = reboot-arch-btw
When = PostTransaction
Exec = /usr/bin/reboot-arch-btw

Unfortunately DBUS cannot be accessed from the hook right now:

hook

@rnestler
Copy link
Owner

Hmm. That is probably because it will run as root which won't have access to the dbus session of the user.

@rnestler
Copy link
Owner

But I should definitely fix the panic 🙂

@rnestler
Copy link
Owner

@dbrgn Can you try setting $DBUS_SESSION_BUS_ADDRESS to something like unix:path=/run/user/1000/bus where 1000 is your UID?

@dbrgn
Copy link
Collaborator Author

dbrgn commented May 14, 2020

We can't set env vars in the hook files. Someone on Arch IRC suggested to either hardcode the UID (or make it configurable), or to try to detect users with an active login session (could maybe be detected through DBUS as well).

@emansom
Copy link

emansom commented Nov 21, 2022

Checking for D-Bus service presence of rfjakob/systembus-notify, and utilizing it to alert the user when available would resolve this issue.

@rnestler
Copy link
Owner

rnestler commented Dec 4, 2022

I found a solution:

/etc/pacman.d/scripts/reboot-arch-btw-hook.sh

#!/bin/bash

sudo -u $SUDO_USER DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$SUDO_UID/bus /usr/bin/reboot-arch-btw

/etc/pacman.d/hooks/99-reboot-arch-btw.hook

[Trigger]
Operation = Upgrade
Type = Package
Target = *

[Action]
Description = Check whether a reboot is required
Depends = reboot-arch-btw
When = PostTransaction
Exec = /etc/pacman.d/scripts/reboot-arch-btw-hook.sh

This works perfectly fine if you run upgrades with sudo pacman -Syu. If you run upgrades in a cron job or similar you probably need to hard-code the user-name and user-id in the script above.

Edit: If you hardcode it, it also works as a one-liner in the .hook file:
Exec = /usr/bin/sudo -u your-user DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/your-uid/bus /usr/bin/reboot-arch-btw

@dbrgn
Copy link
Collaborator Author

dbrgn commented Dec 5, 2022

@rnestler great, it works! I'm not sure if this is something that could be part of the AUR package? (Or maybe just a separate package that depends on reboot-arch-btw.)

@rnestler
Copy link
Owner

rnestler commented Dec 5, 2022

great, it works! I'm not sure if this is something that could be part of the AUR package? (Or maybe just a separate package that depends on reboot-arch-btw.)

It's hard to write it in a generic way such that it works for all use cases.

Something like this might work:

#!/bin/bash

# go through all logged in users and check if we find a D-BUS bus for them
for user in $(users|tr ' ' '\n'|sort -u); do
    uid=$(id -u "$user")
    if [[ -f "/run/user/$uid/bus" ]]; then
        /usr/bin/sudo -u "$user" DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$UID/bus /usr/bin/reboot-arch-btw
        exit 0
    fi
done

# if not run with notifications disabled
/usr/bin/reboot-arch-btw --disable-notification

@rnestler
Copy link
Owner

rnestler commented Dec 5, 2022

Checking for D-Bus service presence of rfjakob/systembus-notify, and utilizing it to alert the user when available would resolve this issue.

@emansom This looks interesting as well, but I don't use systembus-notify myself, so PR welcome :)

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

3 participants