6 ms·
I've often encountered dependency issues on Ubuntu. One time, while dealing with NVidia/CUDA, running `apt-get -y install cuda` complained about some missing de
by paskozdilar 4y ago
I've often encountered dependency issues on Ubuntu. One time, while dealing with NVidia/CUDA, running `apt-get -y install cuda` complained about some missing dependency. I recursively went through the error messages and installed every missing dependency manually, and it worked, but it took me a long time and a lot of typing.
Then I wrote a script that does that automatically:
#!/usr/bin/env bash
main() {
local package="$1"
if [ -z "$package" ]
then
echo "usage: $0 PACKAGE"
exit 1
fi
install_package "$package"
}
install_package() {
local package="$1"
local subpackage
if sudo apt-get -y install "$package"
then exit 0
else
sudo apt-get -y install "$package" \
|& grep '^ ' \
| sed 's/[^:]*:[^:]*: //;s/ .*//;' \
| {
while read subpackage
do install_package "$subpackage"
done
}
sudo apt-get -y install "$package" \
&& echo "SUCCESS: $package" \
|| echo "FAILURE: $package"
fi
}
main "$@"
- mikewhy 4y agoCurious, what's the difference with this and `apt-get --fix-broken install`?
- paskozdilar 4y agoHonestly, I have no idea. If I recall correctly, I think there were some situations where --fix-broken did nothing for me, but the script did. I don't remember it nearly well enough to guarantee, though. One difference I'm sure about is that the script marks all recursively installed dependencies as manually installed, which may not be favorable (e.g. if you wanted to remove the top-level package, all the dependencies would not be removed automatically).