2

There was power failure during system upgrade (pacman -Suy). So I have a lot of broken packages. They seems to be fixed on reinstall with force overwriting (e.g pacman -S systemd-sysvcompat--overwrite "*").

So my question is how to apply reinstallation to all broken packages?

3 Answers 3

2

Assuming your broken packages are reported as missing files, you can use Qk to check packages (from man pacman):

-k, --check

Check that all files owned by the given package(s) are present on the system. If packages are not specified or filter flags are not provided, check all installed packages. Specifying this option twice will perform more detailed file checking (including permissions, file sizes, and modification times) for packages that contain the needed mtree file.

So this command should give you the full list of broken packages on your system (the example below is the result on my Arch):

$ pacman -Qk 2>/dev/null | grep -v ' 0 missing files' 
at: 45 total files, 1 missing file
audit: 196 total files, 4 missing files
bind: 413 total files, 3 missing files
blueman: 791 total files, 1 missing file
gdm: 501 total files, 6 missing files
gnome-perl: 71 total files, 18 missing files
gnome-vfs-perl: 61 total files, 27 missing files
gnomecanvas-perl: 39 total files, 17 missing files
gvfs: 324 total files, 1 missing file
hplip: 2294 total files, 72 missing files
mariadb: 354 total files, 1 missing file
nfs-utils: 111 total files, 3 missing files
perl-goo-canvas: 59 total files, 18 missing files
perl-gtk2-imageview: 36 total files, 19 missing files
perl-term-shellui: 21 total files, 6 missing files
polkit: 201 total files, 1 missing file
samba: 976 total files, 1 missing file
syslinux: 237 total files, 2 missing files
systemd: 1891 total files, 1 missing file

Then, this command will print just the package name:

$ pacman -Qk 2>/dev/null | grep -v ' 0 missing files' | cut -d: -f1
at
audit
bind
blueman
gdm
gnome-perl
gnome-vfs-perl
gnomecanvas-perl
gvfs
hplip
mariadb
nfs-utils
perl-goo-canvas
perl-gtk2-imageview
perl-term-shellui
polkit
samba
syslinux
systemd

You can just iterate over that list and reinstall each of them:

pacman -Qk 2>/dev/null | grep -v ' 0 missing files' | cut -d: -f1 |
    while read -r package; do
        pacman -S "$package" --overwrite "*" --noconfirm
    done

Or, if the list isn't too long, you could even do:

pacman -S "$(pacman -Qk 2>/dev/null | grep -v ' 0 missing files' | cut -d: -f1)" \
 --overwrite "*" --noconfirm

Note that I have not tested this and I am taking your word for it that the command will fix your packages. You might also want to run sudo pacman -Qkk 1>/dev/null 2>&1 | grep checksum to check for files that have been modified unexpectedly, as suggested by Tom Yan in the comments.

3
  • 1
    I think a pacman -Qkk 1>/dev/null 2>&1 | grep checksum should at least be run additionally (as root) to see if some files are altered unexpectedly.
    – Tom Yan
    Jul 25, 2021 at 1:27
  • Also, is there even any good reason to 2>/dev/null when -Qk?
    – Tom Yan
    Jul 25, 2021 at 1:32
  • @TomYan on my system, there were loads of No such file or directory errors, presumably one for each missing file, so without redirecting stderr there was too much noise. Good point about checksum.
    – terdon
    Jul 26, 2021 at 8:26
1

You could write a script that loops through all the packages and reinstalls them.

Just save a list of the packages you've currently installed to a text file with

pacman -Qq > packages.txt

and create the script:

nano reinstall.sh

#!/bin/bash
for package in $(cat packages.txt)
do
    pacman -S $package --overwrite "*" --noconfirm
done

after that you can run it with

sudo sh reinstall.sh

Note: you might have to type chmod a+x reinstall.sh to make the script executable first

1
  • 1
    Never use for i in $(cat file) (although it would probably work in this case, it's still bad practice). And you don't need the package list anyway: you can just do sudo pacman -S "$(pacman -Qq)" --overwrite "*" --noconfirm or, of that list is too long: pacman -Qq | while read -r package; do pacman -S "$package" --overwrite "*" --noconfirm; done. Finally, you have a bash shebang in your script, but then you're running it with sh script. That will fail if you have bash-only features. Just do ./reinstall.sh.
    – terdon
    Jul 24, 2021 at 15:35
1

Both answers are useful but neither of them is a complete solution.

Following script helps get rid of errors like this:

 ldconfig: File /usr/lib/libsvn_repos-1.so is empty, not checked.

script:

LANG=en_EN ldconfig 2> err.txt

for file in $(cut -d" " -f3 err.txt)
do
    echo $file
    pacman -S $(pacman -Fq $file) --noconfirm --overwrite "*"
done

pacman -F

Query the files database. This operation allows you to look for packages owning certain files or display files owned by certain packages. Only packages that are part of your sync databases are searched. See File Options below.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.