You are not logged in.
Hi
I need a aplm hook at every time who upgrades nginx-mainline it should rebuild the package nginx-mainline-mod-dav-ext from AUR
and restart nginx-mainline after rebuild nginx-mainline-mod-dav-ext.
How does it look the hook? I have no idea.
#Here should stay the right code....
[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *
[Action]
Depends = coreutils
When = PostTransaction
Exec = /usr/bin/syncThx
Last edited by Morta (2022-10-21 18:09:45)
Offline
[Trigger]
Operation = Upgrade
Type = Package
Target = nginx-mainline
[Action]
Description = Rebuild nginx-mainline-mod-dav-ext after upgrade nginx
When = PostTransaction
Depends = nginx-mainline
Exec = /usr/bin/yay -Syu nginx-mainline-mod-dav-extIs this correct?
Offline
Could someone move the thread to forums pacman issues?
Offline
Moved, by request. In the future, please feel free to use the report link on the thread to make the request. Moderators are notified of the request and we can respond immediately rather than having to stumble upon it.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way
Offline
Thx for moving. How I can test if my hook works properly?
Offline
you should see the line "Rebuild nginx-mainline-mod-dav-ext after upgrade nginx" in the log/output on a relevant update.
Your hook will not work as is for a multitude of reasons, starting with the fact that you don't have an interactive prompt while running an interactive command, continuing with makepkg refusing to run as root but a hook will run as root and ending on the fact that I doubt it's a very good idea to start a new pacman transaction while one is in active progress.
It's not generally a good idea to try and install packages this way, I'd use the hook to e.g. create a file in the /tmp directory and then have a follow-up/alias that checks whether such a file exists and on it's existence runs
yay -Sya nginx-mainline-mod-dav-ext --rebuildas your normal user, e.g.
sudo pacman -Syu
[ -f /tmp/nginx_update ] && yay -Sya --rebuild nginx-mainline-mod-dav-ext && rm /tmp/nginx_updateLast edited by V1del (2022-10-24 15:22:11)
Online
you should see the line "Rebuild nginx-mainline-mod-dav-ext after upgrade nginx" in the log/output on a relevant update.
Your hook will not work as is for a multitude of reasons, starting with the fact that you don't have an interactive prompt while running an interactive command, continuing with makepkg refusing to run as root but a hook will run as root and ending on the fact that I doubt it's a very good idea to start a new pacman transaction while one is in active progress.
It's not generally a good idea to try and install packages this way, I'd use the hook to e.g. create a file in the /tmp directory and then have a follow-up/alias that checks whether such a file exists and on it's existence runs
yay -Sya nginx-mainline-mod-dav-ext --rebuildas your normal user, e.g.
sudo pacman -Syu [ -f /tmp/nginx_update ] && yay -Sya --rebuild nginx-mainline-mod-dav-ext
How I can make a hook running as normal user?
I appreciate your inputs.
Can you post a full example of a hook which is working like this?
Thx
Offline
You shouldn't manipulate the pacman database while a pacman database operation is in progress. Any hook that intends to install a package will fail by definition of what a hook is. So you need to separate the database operation (installing the package) from the trigger (identifying when to invoke the package installation). So you'd change the hook to simply create the trigger file e.g.
[Trigger]
Operation = Upgrade
Type = Package
Target = nginx-mainline
[Action]
Description = Rebuild nginx-mainline-mod-dav-ext after upgrade nginx
When = PostTransaction
Depends = nginx-mainline
Exec = /usr/bin/touch /tmp/nginx_updateand then run a script as I mentioned it from your normal user (see also my edit).
Last edited by V1del (2022-10-24 15:22:50)
Online
Ok thx.
My script looks like this
cat nginx-rebuild.sh
#/bin/bash
sudo -u morta yay -Sya --rebuild nginx-mainline-mod-dav-ext --rebuild
sudo pacman -Syu
[ -f /tmp/nginx_update ] && yay -Sya --rebuild nginx-mainline-mod-dav-extMy problems:
- It's ask me if they should remove dependencies (Yes it should but I have to prompt)
- The hook will build the dir /tmp/nginx_update but ther is no pkg file which build by the script. Should not the hook also execute the script?
Last edited by Morta (2022-10-24 16:23:35)
Offline
- The hook will build the dir /tmp/nginx_update but ther is no pkg file which build by the script. Should not the hook also execute the script?
No, because you don't want this running while pacman is in the middle of an operation. That's why you want the hook just to create the trigger file in /tmp. You also don't want this running as root.
I've never used yay, but doesn't your script try to build the package twice, while updating packages from the official repos in between? You almost certainly shouldn't have/need sudo in this script. Don't you just want the final line?
You could use something to monitor for the trigger file and rebuild the package when it appears. You'd run that as an unprivileged user, so you wouldn't be trying to build anything as root. (Me, I'd run it as a user who wasn't in wheel, but you're using yay, so you presumably like to live dangerously.)
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline
OK
1. I create the hook
2. I create a bash script /opt/nginx-rebuild.sh with following context
[ -f /tmp/nginx_update ] && yay -Sya --rebuild nginx-mainline-mod-dav-ext3. sudo chmod a+x the script
4. Make a systemd service and timer which checks the script
[Unit]
Description=Rebuild nginx-mainline with DAV
[Service]
Restart=always
RestartSec=60s
ExecStart=/opt/nginx-rebuild.sh
[Install]
WantedBy=multi-user.targetOk?
Thanks for reply and your inputs
Last edited by Morta (2022-11-01 18:30:27)
Offline
You'd want an user service if you intend for that approach: https://wiki.archlinux.org/title/Systemd/User
I'd personally make a wrapper script/alias around pacman where you pass all arguments to the script to pacman and then explicitly run yay after pacman completed, e.g.
#!/bin/bash
sudo pacman $@
[ -f /tmp/nginx_update ] && yay -Sya --rebuild nginx-mainline-mod-dav-ext && sudo rm /tmp/nginx_updateLast edited by V1del (2022-11-01 19:22:02)
Online
I edited the script like above
and added to nginx-rebuild.service following
[Unit]
Description=Rebuild nginx-mainline with WebDAV
[Service]
Restart=always
RestartSec=60s
ExecStart=/opt/nginx-rebuild.sh
User=morta
Group=wheel
[Install]
WantedBy=multi-user.targetAll ok?
Offline
Should work, try it out, there are some differences between an user service and a system service invoked with a specific user, but I'm assuming they might be of cosmetic nature in this particular case, I'd still rather do an user service which would be placing the service under /etc/systemd/user/ and dropping the explicit user like so
[Unit]
Description=Rebuild nginx-mainline with WebDAV
[Service]
Restart=always
RestartSec=60s
ExecStart=/opt/nginx-rebuild.sh
[Install]
WantedBy=default.targetand doing
systemctl --user enable rebuldNginx.service --nowwith your normal user ... You'd also have to run the yay command with --no-confirm if you want to do it that way.
Online
[Unit]
Description=Rebuild nginx-mainline with WebDAV
[Service]
ExecStart=/opt/nginx-rebuild.sh
[Install]
WantedBy=default.targetI edited to this one
Offline
[morta@5erver systemd]$ systemctl enable --user nginx-rebuild.service --now
Created symlink /home/morta/.config/systemd/user/default.target.wants/nginx-rebuild.service → /etc/xdg/systemd/user/nginx-rebuild.service.Looks good...
Offline
#!/bin/bash sudo pacman $@ [ -f /tmp/nginx_update ] && yay -Sya --rebuild nginx-mainline-mod-dav-ext && sudo rm /tmp/nginx_update
Would you mind explaining what the pacman line does when the script is invoked by the user service without arguments?
How does the service get permission for the sudo in this kind of case?
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline
That script isn't intended for a service but for running as a pacman wrapper in place of normal pacman, all behaviour and outputs will be the same as pacman, safe for the fact that it will automatically trigger a yay run after a temp file exists, and will also handle that the same way as if you'd normally run yay.
I'm not a big fan of automatically doing installs/manipulations, this would give you the normal interactive approach while "remembering" to trigger a specific circumstancial rebuild.
Last edited by V1del (2022-11-02 09:03:33)
Online
That script isn't intended for a service but for running as a pacman wrapper in place of normal pacman, all behaviour and outputs will be the same as pacman, safe for the fact that it will automatically trigger a yay run after a temp file exists, and will also handle that the same way as if you'd normally run yay.
I'm not a big fan of automatically doing installs/manipulations, this would give you the normal interactive approach while "remembering" to trigger a specific circumstancial rebuild.
Thanks for that explanation. This thread had me rather confused.
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline