Pacman hook, command with argument help

On Fluxbox, I use fbmenugen to generate the root menu. It works great, and now I want a pacman hook to automatically regenerate it whenever I install or uninstall packages.

So far it is registered by pacman, but it will not execute with the option I use in the terminal, which is
fbmenugen -g
This option is necessary for fbmenugen to run.

What I’ve done:

sudo mkdir /etc/pacman.d/hooks
sudo mkdir /etc/pacman.d/hooks.bin

sudo nano /etc/pacman.d/hooks/50-fbmenugen.hook

where I put:

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

[Action]
Description = Regenerate Fluxbox menu when installing or removing packages
When = PostTransaction
Exec = /bin/bash -c fbmenugen -g

When I run
sudo pacman -S htop

what I get in the terminal is:

:: Proceed with installation? [Y/n] y
(1/1) checking keys in keyring                                                                      [##########################################################] 100%
(1/1) checking package integrity                                                                    [##########################################################] 100%
(1/1) loading package files                                                                         [##########################################################] 100%
(1/1) checking for file conflicts                                                                   [##########################################################] 100%
(1/1) checking available disk space                                                                 [##########################################################] 100%
:: Running pre-transaction hooks...
(1/1) Performing snapper pre snapshots for the following configurations...
==> root: 146
:: Processing package changes...
(1/1) reinstalling htop                                                                             [##########################################################] 100%
:: Running post-transaction hooks...
(1/5) Arming ConditionNeedsUpdate...
(2/5) Regenerate Fluxbox menu when installing or removing packages
[!] To generate a new menu, please specify option `-g`.
(3/5) Updating icon theme caches...
(4/5) Updating the desktop file MIME type cache...
(5/5) Performing snapper post snapshots for the following configurations...
==> root: 147

So from what I can tell, everything seems to be OK except for that fbmenugen needs the -g option to function. Htop gets installed, but the menu isn’t regenerated.

I’ve tried all sort of variations with parenthesises and ’ , from what I’ve seen online, but none work.

The question is what I am doing wrong?

Should probably be:

Exec = /bin/bash -c "fbmenugen -g"

Yes, I’ve tried lots of variations, that one included.

This is what I get:

Exec = /bin/bash -c "fbmenugen -g"
: Running post-transaction hooks...
(1/5) Arming ConditionNeedsUpdate...
(2/5) Regenerate Fluxbox menu when installing or removing packages
Can't open '/root/.fluxbox/menu' for write: No such file or directory at /usr/bin/fbmenugen line 615.
error: command failed to execute correctly
(3/5) Updating icon theme caches...
(4/5) Updating the desktop file MIME type cache...
(5/5) Performing snapper post snapshots for the following configurations...
==> root: 149

Strange thing is that it works in the terminal, when I run fbmenugen from there.

In the meantime, I’ll install a text editor where you can see the line count, and see what is in line 615. Should have thought of that first.

this is whats in /usr/sbin/fbmenugen line 615:

open my $fh, '>', $menu_file

a few more surrounding lines:

    my $out_fh = $pipe ? \*STDOUT : do {
        open my $fh, '>', $menu_file
          or die "Can't open '${menu_file}' for write: $!";
        $fh;
    };

It is because the hook is running as root.

OK, it seems to be looking for the root account fluxbox menu to regenerate, while I want it to regenerate the users menu?

Right. See above. pacman hooks run as root.

You could try using sudo to run it as your user.

So that means I can’t write a this hook?
Damn, I’ve been struggling all evening!

I have never tried this but something like this is worth a try:

Exec = /bin/bash -c "sudo -u username fbmenugen -g"

Replace username with your username

If that doesn’t work, you could have it a trigger a user systemd service.

2 Likes

Wow, it friggin’ works!

I run both
sudo pacman -S htop
and
sudo pacman -Rns htop

…and it works smooth as butter!

Many thanks!

1 Like

A side question. Not EOS/Arch related, but out of Linux curiosity.

I did this on Debian a while back, and I was able to tell APT to run xdgmenumaker and write the menu seemingly as non-root.

How did it actually work?

sudo nano /etc/apt/apt.conf.d/00fluxboxmenu

DPkg::Post-Invoke { "/usr/local/bin/xdgmenumaker -f fluxbox > /home/username/.fluxbox/xdg_menu"; };

It looks like you are explicitly writing to the file as opposed to your hook which was letting the script/program decide which file to wrote to.

Thanks, useful to know!
I guess it would be possible to do something similar with pacman, if I should need it one day and look into it?

Yes, I would think that same thing would work with a pacman hook too.

1 Like

Great, useful to know if I should need it one day!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.