Home > bash, debian > Manage “recommended” dependencies with apt-get, debfoster and custom script

Manage “recommended” dependencies with apt-get, debfoster and custom script

I use apt-get to install Debian packages. By default apt-get will also install all packages that your desired package depends on or that it recommends.

I find that recommended dependencies are often not actually necessary. I use debfoster to carefully review and selectively remove them, to keep my system light and clean. My approach requires this line in /etc/debfoster.conf:

UseRecommends = no

With this setting, debfoster will ignore recommended dependencies and allow you to decide individually if you want to keep them.

Disclaimer

This approach only makes sense if you know exactly what you are doing. Sometimes the removal of “recommended” dependencies can actually break functionality. If in doubt, tell debfoster to keep (Y) the respective packages or skip (s) the decision.

The prune (p) option offered by debfoster is the most drastic removal type and should be used with extreme caution.

Reinstall recommended dependencies

The ant-rdepends command can help you find out which packages recommend a given package (replace PACKAGE with the name of the package you are interested in):

sudo apt-get install apt-rdepends
apt-rdepends -pr --state-show Installed --state-follow Installed --show Recommends PACKAGE

If you ever remove too much, you can reinstall all dependencies (including the recommended ones) of a package using the following script. Save it for example as /usr/local/bin/install-dependecies.sh and use chmod ugo+x to make it executable.

#!/bin/sh

if [ $# -ne 1 ]; then
  echo "Usage: $(basename $0) package"
  exit 1
fi

package="$1"
header="Package $package depends on:"

df_output=$(debfoster -o UseRecommends=true -d $package)
pkg_list=${df_output#*$header}

if [ "$pkg_list" != "$df_output" ]; then
  sudo apt-get install $pkg_list
else
  echo $df_output
fi

Reference info

Advertisements
Categories: bash, debian
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: