I'm using arch linux.
Is there a way to list optional dependencies of all installed packages? And if yes, can I filter this list to see only the missing (not installed) packages?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityThere is a nice utility in the AUR-Repository (aur/pacdep).
pacdep has a lot of options - just one example - find out optional packages for "thunar-archive-plugin":
> pacdep -oppp thunar-archive-plugin
[...]
Optional dependencies: 6.16 MiB
extra/file-roller 3.89 MiB
extra/kdeutils-ark 1.12 MiB
community/xarchiver 1.16 MiB
[...]
The output above means that none of the optional packages are installed. After installing "xarchiver" the output looks like
[...]
Optional dependencies: 6.16 MiB
local: 1.16 MiB
xarchiver 1.16 MiB
sync: 5.01 MiB
extra/file-roller 3.89 MiB
extra/kdeutils-ark 1.12 MiB
[...]
I found (the first part of) this answer on
http://mywaytoarch.tumblr.com/post/34979742718/easily-list-package-dependencies
You can use expac to query alpm data (pacman database).
Something like:
awk 'NF>=2' <(expac "%n %O") > optdeps
will print a list of all the installed packages on your machine, and the optdepends
for each, to a file called optdeps
. You could then sort this against a list of installed optdepends packages.
See man expac
for the complete list of options.
This is not exactly efficient, but will find what you want (in COLOR!):
pacman -Q > /tmp/paccache
for pkg in $(awk '{print $1}' /tmp/paccache) ; do
echo -n "$pkg => ";
for dep in $(pacman -Qi $pkg | awk -F: '/Optional Deps/{gsub(/[\<\>=].*/,"");print $NF;}' ) ; do
grep -q "$dep" /tmp/paccache && COLOR=32 ; echo -en "\e[1;${COLOR:-31}m${dep}\e[0;m " ; unset COLOR ;
done
echo
done
||
instead of &&
after the grep
, and then parentheses around the rest of the line?
pacman -Qi xmms2 | sed -n '/^Optional/,$p' | sed '/^Required/q' | head -n -1 | cut -c19- | cut -d: -f1
This should do the trick:
comm -23 <(expac -l"\n" "%o" | sort -u) <(expac -l"\n" "%n\n%S" | sort -u)
First input to comm
lists all optional dependencies, second input all installed packages and their 'provide' attributes. Both lists are sorted and contain each element only once due to sort -u
. Then only lines are shown that are contained in the first but not in the second list.
(edited to incorporate @Archemar's suggestion)
expac
).
Jun 6 at 12:34
Though I've had to notice that @DarkHeart's solution doesn't really work, it inspired me to make a working one. (no colours, though)
I'm using package-query, a similar tool instead of expac which was suggested by @jasonwryan, because I've had it already installed (it's a dependency of yaourt). It should be trivial to change this to use expac instead.
The listing of all optional dependencies is mostly done by the call to package-query. The first for-loop removes the explanations, so just the package names for the optional dependencies remain; the second for-loop removes the already installed dependencies in its first line before printing the results in the second one.
#!/usr/bin/perl
use strict;
use warnings;
my %deps;
for (`package-query -Q -f'%n %O'`) {
$deps{ (/^(\S+)/)[0] } = [/(\S+):/g];
}
my @pkgs = keys %deps;
for my $pkg (@pkgs) {
my @missing_deps = grep { !($_ ~~ @pkgs) } @{ $deps{$pkg} };
print "$pkg => @missing_deps\n" if @missing_deps;
}
I tried only in GNU sed but
yay -Qi | sed -n '/Optional Deps/{:l s/.* \([a-zA-Z0-9.\-]\+\):.*/\1/p; n; /Required By/!bl}'
this worked(Use sort/uniq as you like).
Sometimes you have to work backwards... first find all non-optional depends, then cross-reference with full list, then use uniq. This will generate a list of installed optional depends.
Find all installed
pacman -Q
Find all non-optional:
pacman -Qent
Unique entries must therefore be optional:
(pacman -Q; pacman -Qent) | sort | uniq -u
Generate list of missing optional depends with descriptions, not pretty, but it works.
pacman -Q > /tmp/paccache; for pkg in $(awk '{print $1}' /tmp/paccache); do pacman -Qi $pkg | grep "^Optional Deps" | grep -v None >/dev/null && echo $pkg >> /tmp/hasdeps; done
for pkg in $(awk '{print $1}' /tmp/hasdeps); do echo -ne "Package: $pkg ___ "; (pacman -Qi $pkg | sed -n '/^Optional/,$p' | sed '/^Required/q' | head -n -1) | grep -v installed; echo ___; done | grep -v "___ ___" | sed -e 's/Optional Deps/ /' -e 's/___//' | sed -e 's/ \+/ /g'
For optional dependencies:
pacman --sync --info [PACKAGE] | grep --extended-regex "^Optional Deps|^ " | sed -e "s|Optional Deps : ||" -e "s| ||" | cut --delimiter=':' --fields=1 | sed "s| |\n|g"
For both required and optional dependencies:
pacman --sync --info [PACKAGE] | grep --extended-regex "^Depends On|^Optional Deps|^ " | sed -e "s|Depends On : ||" -e "s|Optional Deps : ||" -e "s| ||" | cut --delimiter=':' --fields=1 | sed "s| |\n|g" | sort
pacman -Qi | grep "Optional Deps" | grep -v None | grep -v installed