Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

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

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?

question from:https://stackoverflow.com/questions/65883060/how-do-i-prevent-apt-apt-get-from-cancellng-download-of-multiple-packages-if-one

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...