Estimate installed size of pacman repository

Some time ago on #artix IRC channel popped up a question on how to get the installed size of all packages in given repository and I together with other people on the channel created a one liner in shell to do exactly that.

But before I have to mention that Pacman prints the “Installed size” value when we try to install packages. So one way is to try to install all packages but this can also include dependencies and may require some pacman magic which I am not aware of. I forgot to mention, this method may require root access or sudo privileges which is not good enough for me.

There was also one more brute-force idea which consisted of downloading of all packages and checking their uncompressed sizes and counting this value somehow.This is way too brutal.

The basic idea behind this script is based on the fact that pacman prints the installed size value when we run pacman -Si "package"and as such it can be automated with bit of skill and luck.

$ pacman -Si pacman
Repository      : system
Name            : pacman
Version         : 5.2.2-1
Description     : A library-based package manager with dependency support
Architecture    : x86_64
URL             : https://www.archlinux.org/pacman/
Licenses        : GPL
Groups          : base-devel
Provides        : libalpm.so=12-64
Depends On      : bash  glibc  libarchive  curl  gpgme  artix-mirrorlist  artix-keyring  archlinux-mirrorlist  archlinux-keyring
Optional Deps   : perl-locale-gettext: translation support in makepkg-template
Conflicts With  : None
Replaces        : None
Download Size   : 838,79 KiB
Installed Size  : 4538,70 KiB
Packager        : Artix Build Bot <jenkins@artixlinux.org>
Build Date      : Št  2. júl 2020, 00:28:07
Validated By    : MD5 Sum  SHA-256 Sum  Signature

So all we need to do is get this information out of this output. This can be done with few commands or some smart awk or whatever you are good at using. The tricky part is to get the actual size because it has different prefixes we need a bit smarter tool to count formatted sizes like numfmt (this tool is truly great and I am happy it was recommended to me after I use awk script which I stole from something else) or some smart awk.

After adding a bit of counting magic and formating the result into human readable format I thought “I am done” (how foolish of me).
During the creation of this script I did not realize i was working with my local locale and thus the number formatting was totally messed up and I reflected this mess with few sed replacements in the script which made a mess when run in universal locale LC_ALL=C.

Well, I do not wish to write about every little change which I made and everything which was done, if you wish for a bit more detail you can only regret since you probably do not have logs from that channel.

So here is the final script, which is a bit of shell magic and I know that it can be improved, but it is good enough to run it from time to time and just for fun.

$ export LC_ALL=C && pacman -Sl system | cut -d" " -f2 | xargs pacman -Si | grep -i "installed size" | cut -d: -f2 | sed "s/\s//;s/ //;s/B//;s/i//" | numfmt --from=iec | paste -sd+ - | bc | numfmt --to=iec-i -- && export LC_ALL=

Example output:

2.9Gi

This script as it is written here will show the installed size of all packages in Artix system repository. It can be adapted to show some other package group or repository.

The result is nice and it works just fine, for me that is. As a bonus I learnt some nice utilities a way to use them, for me this was a win.

That is enough of my rumbling.

Articles from blogs I follow:

KDE e.V. AGM at Akademy

The Annual General Meeting (AGM) of KDE e.V., the association that supports the KDE community financially and organizationally, has been announced. As usual, it takes place at Akademy – online again this year, and the AGM is on monday june 21st, the longe…

via [bobulate] May 10, 2021

I try not to make unlikable software (and features)

I am writing to you from The Sky. On my flight today, I noticed an example of “unlikable” software — something I’ve been increasingly aware of recently — inspiring me to pull out my laptop and write. On this plane, there are displays in the back of each seat…

via Drew DeVault's blog May 8, 2021

About Logging

TL;DR: This post also talks about the problems I faced while working on my logging. To log to syslog from within my containers that do not support configuring a remote syslog server, I had syslog-ng expose a unix domain socket and mounte…

via PapaTutuWawa's Blog April 16, 2021

Generated by openring