Hi everyone,
I updated the script to be more resiliant. It now expects arrays for all additional parameters and sets the --min-mtime "14 days ago"
by default.
Git Clone URL: | https://aur.archlinux.org/paccache-hook.git (read-only, click to copy) |
---|---|
Package Base: | paccache-hook |
Description: | A configurable hook to cleanup the pacman package cache using paccache |
Upstream URL: | None |
Keywords: | cleanup hook paccache pacman |
Licenses: | BSD |
Conflicts: | pacman-cleanup-hook |
Submitter: | Skycoder42 |
Maintainer: | Skycoder42 |
Last Packager: | Skycoder42 |
Votes: | 47 |
Popularity: | 2.08 |
First Submitted: | 2019-03-23 10:57 (UTC) |
Last Updated: | 2024-09-09 18:45 (UTC) |
Hi everyone,
I updated the script to be more resiliant. It now expects arrays for all additional parameters and sets the --min-mtime "14 days ago"
by default.
@bhe69 Thanks for the workaround. I won't be able to test it as it turns out i am runnning out of space so i ended up using installed_keep=0
.
For your question on How did you get the "debug output" of ./paccache-hook.sh ?
,
set -x
at start in .sh file. https://stackoverflow.com/questions/36273665/what-does-set-x-do@kageyama thanks for the analysis. Out of interest: How did you get the "debug output" of ./paccache-hook.sh ?
Looking into the info document of date and time I found a workaround: Instead of using "14 days ago" we can use "-14 days". The fuzzy analysis of time also accepts "-14days". No spaces, no problems.
uninstalled_extra_args=--min-mtime=-14days
works like a charm :-)
@bhe69, you are right. I have the same config and its not working.
uninstalled_extra_args="'--min-mtime=14 days ago'"
This is silently failing. This is what gets ran. ->
[phoenix@ArchLinux ~]$ paccache -duk0 \'--min-mtime=14 days ago\'
==> no candidate packages found for pruning
This is how it should behave actually ->
[phoenix@ArchLinux ~]$ paccache -duk0 '--min-mtime=14 days ago'
==> finished dry run: 994 candidates (disk space saved: 5.21 GiB)
The problem is that, uninstalled_extra_args="--min-mtime=14 days ago"
needs to passed as a single string, but if we quote it ourselves like this uninstalled_extra_args="'--min-mtime=14 days ago'"
, that quotation ('
) gets preserved and gets passed as string to pacache command. It can be seen here ->
[phoenix@ArchLinux ~]$ ./paccache-hook.sh
+ . /home/phoenix/paccache-hook.conf
++ extra_args=-v
++ cache_dirs=()
++ installed=true
++ installed_keep=3
++ installed_move_to=
++ uninstalled=true
++ uninstalled_keep=0
++ uninstalled_extra_args=''\''--min-mtime=14 days ago'\'''
++ uninstalled_move_to=
+ paccache -duk0 -v ''\''--min-mtime=14' days 'ago'\'''
==> no candidate packages found for pruning
But if we don't quote it and keep it like this uninstalled_extra_args="--min-mtime=14 days ago"
, then it gets passed as split arguments, this is what gets ran ->
[phoenix@ArchLinux ~]$ ./paccache-hook.sh
+ . /home/phoenix/paccache-hook.conf
++ extra_args=-v
++ cache_dirs=()
++ installed=true
++ installed_keep=3
++ installed_move_to=
++ uninstalled=true
++ uninstalled_keep=0
++ uninstalled_extra_args='--min-mtime=14 days ago'
++ uninstalled_move_to=
+ paccache -duk0 -v --min-mtime=14 days ago
==> no candidate packages found for pruning
In BOTH cases, paccache is failing silently.
https://aur.archlinux.org/cgit/aur.git/tree/paccache-hook.sh?h=paccache-hook#n25 needs to contain either "$uninstalled_extra_args"
or array expansion or maybe the developer knows someway.
@escorares yes, but I also have uninstalled_keep=0 and my issue are the uninstalled packages.
@bhe69,
Your config has installed_keep=2
.
For me removal of uninstalled packages is not working. Can anybody give me some pointers what I'm doing wrong?
I set up paccache-hook.conf as follows:
[bhe@box ~]$ cat /etc/paccache-hook.conf
extra_args=-v
cache_dirs=()
installed=true
installed_keep=2
installed_extra_args=
installed_move_to=
uninstalled=true
uninstalled_keep=0
uninstalled_extra_args="'--min-mtime=14 days ago'"
uninstalled_move_to=
Alsa-plugins was uninstalled more than 14 days ago, and still is uninstalled: [2024-04-16T22:57:10+0200] [ALPM] removed alsa-plugins (1:1.2.7.1-2)
[bhe@box ~]$ sudo pacman -Q alsa-plugins
error: package 'alsa-plugins' was not found
Still the package file is in cache, even though mtime is way more than "14 days ago":
[bhe@box ~]$ stat /var/cache/pacman/pkg/alsa-plugins-1\:1.2.7.1-2-x86_64.pkg.tar.zst
File: /var/cache/pacman/pkg/alsa-plugins-1:1.2.7.1-2-x86_64.pkg.tar.zst
Size: 89425 Blocks: 176 IO Block: 4096 regular file
Device: 1,10 Inode: 562135 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2023-11-06 23:12:07.899236660 +0100
Modify: 2023-03-03 10:08:08.000000000 +0100
Change: 2023-11-06 23:12:03.082474118 +0100
Birth: 2023-11-06 23:12:03.029139722 +0100
Has anybody an idea why this is not working?
I lost cache of uninstalld package because of uninstalled_keep=0
and even though i read the comment first, i didn't know any way to prevent it.
as mentioned by @archz, it would be nice to have those as defaults. i personally liked @escorares args, as it would remove cache of uninstalld package after 30 days.
setting uninstalled_keep=1
wil mean the package will be never removed unless explicitly done.
I personally configured paccache-hook.conf
so that if I change my mind and install a package back, it doesn't have to be downloaded again if 30 days haven't passed.
uninstalled_extra_args="'--min-mtime=30 days ago'"
uninstalled_keep=0
can stay since
--min-atime <time>, --min-mtime <time> Keep packages with an atime/mtime that is not older than the time given, **even if this means keeping more than specified through the --keep option.** Accepts arguments according to info "Date input formats", e.g. 30 days ago.
This is great, thank you!
I'd like to offer two suggestions for consideration (in light of a mistake I made):
1) set default uninstalled_keep=1
-> It's safer than 0. The user may need to reinstall a package from their cache in the event of an erroneous uninstall.
2) set default extra_args=-v
-> The hook runs immediately after being installed, and may remove unexpected packages (as it did for me). With verbose logging, the user can easily determine what was removed. I see another user below mentioned they like verbosity off, but it's easier to remove the flag than it is to deal with lost info from a silent execution.
Thanks!
Pinned Comments
Skycoder42 commented on 2019-03-23 11:00 (UTC)
This packages was inspired by pacman-cleanup-hook and builds on top of it by making the hook configurable. For a basic, non-configurable cleanup, check out that one!