You are not logged in.

#1 2017-03-01 14:33:49

linux_dream
Member
Registered: 2015-05-17
Posts: 45

[Solved]Creating a packman hook

Hello people,
In order to remove all but the currently installed and the previously used cache, I want to create a hook for pacman (as suggested in the Arch Wiki) to run paccache -rkv2 in the PostTransaction phase.
So I have created the file /etc/pacman.d/hooks/remove_old_cache.hook in which I wrote in:

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

[Action]
Description = Keep the last cache and the currently installed.
When = PostTransaction
Exec = paccache -rvk2

However, when I do for example sudo pacman -Syu and upgrade my system, nothing about removing cache is displayed. So I think the hook doesn't work. Is there anything wrong with it?

Last edited by linux_dream (2017-03-02 19:56:28)

Offline

#2 2017-03-01 14:38:16

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [Solved]Creating a packman hook

Doesn't Operation = Remove mean that the hook will only be triggered when you remove a package?


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#3 2017-03-01 14:40:24

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 12,977

Re: [Solved]Creating a packman hook

Operation = Remove

I think that is only triggered by pacman -R .

Try removing something small that's easy to re-install to verify if i'm correct.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#4 2017-03-01 14:41:32

linux_dream
Member
Registered: 2015-05-17
Posts: 45

Re: [Solved]Creating a packman hook

slithery wrote:

Doesn't Operation = Remove mean that the hook will only be triggered when you remove a package?

That makes sense, thanks a lot. I added the Operation = Install and Operation = Upgrade lines. I'll keep you up to date with how this goes.

Offline

#5 2017-03-01 14:43:09

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,426
Website

Re: [Solved]Creating a packman hook

There is an "Upgrade" operation you can specify if you want this to run during an upgrade. You can specify multiple operations (one per line) if you want the hook to be triggered by multiple scenarios.

EDIT: Too slow

Last edited by WorMzy (2017-03-01 14:43:23)


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#6 2017-03-01 14:53:14

linux_dream
Member
Registered: 2015-05-17
Posts: 45

Re: [Solved]Creating a packman hook

Ok I get

:: Running post-transaction hooks...
(1/2) Keep the last cache and the currently installed.
call to execv failed (No such file or directory)

I modified paccache to /usr/bin/paccache. I'll let you know how it goes.

Edit: Works fine! Thank you all.

Last edited by linux_dream (2017-03-01 19:36:44)

Offline

#7 2017-03-01 20:14:07

philo
Member
Registered: 2015-01-26
Posts: 267

Re: [Solved]Creating a packman hook

paccache -rvk2

Are the flags correct?

Last edited by philo (2017-03-01 20:14:58)

Offline

#8 2017-03-01 20:44:41

linux_dream
Member
Registered: 2015-05-17
Posts: 45

Re: [Solved]Creating a packman hook

philo wrote:
paccache -rvk2

Are the flags correct?

Hmm you're right, I think it should be paccache -vk2. The above command returned no error though.

Offline

#9 2017-03-02 08:43:50

linux_dream
Member
Registered: 2015-05-17
Posts: 45

Re: [Solved]Creating a packman hook

Very strange. When I type

paccache -dvk2

in a terminal, I get that there's no candidate packages found for pruning which is normal because I accidentally removed all the cache.
Now when putting

Exec = paccache -vk2

in the hook file, I get:

(2/5) Keep the last cache and the currently installed.
==> ERROR: no operation specified (use -h for help)
error: command failed to execute correctly

So in the hook file the command fails to work? Any idea why?

Offline

#10 2017-03-02 09:12:01

a821
Member
Registered: 2012-10-31
Posts: 381

Re: [Solved]Creating a packman hook

linux_dream wrote:

So in the hook file the command fails to work? Any idea why?

because you didn't specify an operation...

Offline

#11 2017-03-02 09:15:35

linux_dream
Member
Registered: 2015-05-17
Posts: 45

Re: [Solved]Creating a packman hook

a821 wrote:
linux_dream wrote:

So in the hook file the command fails to work? Any idea why?

because you didn't specify an operation...

Ah I thought -k was an operation. Ok so -rvk2 (remove operation, verbose, keep the last 2 cache).
Edit: But this brings out the post of Philo who asked whether these flags were correct. Are they?

Last edited by linux_dream (2017-03-02 09:16:30)

Offline

#12 2017-03-02 13:01:38

philo
Member
Registered: 2015-01-26
Posts: 267

Re: [Solved]Creating a packman hook

You may get some inspiration from the examples of commands given for paccache in:

https://wiki.archlinux.org/index.php/Pa … kage_cache

Offline

#13 2017-03-02 13:04:35

linux_dream
Member
Registered: 2015-05-17
Posts: 45

Re: [Solved]Creating a packman hook

philo wrote:

You may get some inspiration from the examples of commands given for paccache in:

https://wiki.archlinux.org/index.php/Pa … kage_cache

Done. So what I had done, i.e. paccache -rvk2 looks fine to me. I just tried paccache -rvk 2 (with a space) and this yielded the same result. So I still can't find anything wrong now. Am I missing something?

Offline

#14 2017-03-02 13:18:05

rdeckard
Wiki Maintainer
Registered: 2015-01-28
Posts: 137

Re: [Solved]Creating a packman hook

Can you post the entire updated hook?

Here is a hook I created to do something similar and it works:

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

[Action]
Description = Cleaning pacman cache...
When = PostTransaction
Exec = /usr/bin/paccache -r 

Last edited by rdeckard (2017-03-02 13:19:37)

Offline

#15 2017-03-02 14:41:56

linux_dream
Member
Registered: 2015-05-17
Posts: 45

Re: [Solved]Creating a packman hook

rdeckard wrote:

Can you post the entire updated hook?

Here is a hook I created to do something similar and it works:

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

[Action]
Description = Cleaning pacman cache...
When = PostTransaction
Exec = /usr/bin/paccache -r 

Mine also works, hence my question to Philo as to why he asks whether the flags are correct and whether I'm missing something.
Here it goes:

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

[Action]
Description = Keep the last cache and the currently installed.
When = PostTransaction
Exec = /usr/bin/paccache -rvk2

Offline

#16 2017-03-02 15:28:03

philo
Member
Registered: 2015-01-26
Posts: 267

Re: [Solved]Creating a packman hook

@linux_dream

Sorry for bringing confusion since you have now something that works well.

Offline

#17 2017-03-02 15:58:48

rdeckard
Wiki Maintainer
Registered: 2015-01-28
Posts: 137

Re: [Solved]Creating a packman hook

Oh ok, edit the thread title to mark as [Solved]. I'm going to link this thread to that tip in the wiki since we now have two examples posted. smile

Offline

#18 2017-03-02 19:57:01

linux_dream
Member
Registered: 2015-05-17
Posts: 45

Re: [Solved]Creating a packman hook

Thanks for all guys! Done rdeckard.

Offline

Board footer

Powered by FluxBB