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 "$@"