How do I prevent apt/apt-get from cancellng download of multiple packages if one of them can't be found

Viewed 154

I am trying to write a package install script for Ubntu which is based on apt-get with a list of packages as parameter (like xargs -a ./packages_list.txt sudo apt-get -y -f -m install or sudo apt-get -y -f -m install $(cat packages_list.txt)).

It might happen that one of the packages in the list in packages_list.txt can't be found by apt. In this case that package should be ignored but all other should be installed.

So what I expect e.g. from the command sudo apt-get -y -f -m install curl wget apt-transport-https xargs dos2unix vim is that if xargs can't be found/downloaded by apt, curl, wget, apt-transport-https, dos2unix and vim still get installed.

But what actually is happening that I get the message (in German) E: xargs kann nicht gefunden werden. ("E: xargs can't be found.") and the rest of the list, e.g. apt-transport-https, does not get installed.

My understanding is, that -m (or --ignore-missing) should prevent this behavior. But this is not the case.

So how can I achieve that all other packages in apt's parameter list still get installed?

1 Answers

A while read loop to install the packages from list on by one:

export DEBIAN_FRONTEND=noninteractive
while IFS= read -r package; do sudo apt -y install "$package"; done < packages_list.txt

If some packages fails to be installed the installation process will continue.

without looping:

xargs apt list 2>/dev/null < packages_list.txt | \
awk -F'/' '/\//{print $1}' | xargs sudo apt install -y
Related