Date Tags debian

debtree is a fantastic tool to create colorful graphs of package dependencies. One small shortcoming is that the user cannot provide a Packages.gz file directly to be used as repository. Since debtree is based on the excellent apt_pkg library, it is actually not that difficult to convince apt to look in a different location. To change debtree (and apt-get_ default behaviour you just need to create a new apt-get repository and then set the environment variable APT_CONFIG appropriately.

So … imagine you create a repository as :

mkdir -p /tmp/apt/{archives,lists}/partial
cp $yourPackagesfile /tmp/apt/lists
cp $yourstatusfile /tmp/apt/

now you need to create a new apt.conf file that looks like :

APT::Get::List-Cleanup "false";
Dir::Cache /tmp/apt;
Dir::State /tmp/apt;
Dir::State::status /tmp/apt/status;
Dir::Etc::SourceList /tmp/apt/sources.list;

Here I assume that the arch of the Packages list is the same as your host arch. Otherwise you must specify and additional apt parameter like :

APT::Architecture "i386";

Now you’re ready to play with your new repo :

APT_CONFIG=apt.conf apt-get update
APT_CONFIG=apt.conf debtree dpkg

done.

UPDATE

let’s put everything in a bash script ready to use :

$cat debtree.sh 
#!/bin/bash

TMPAPT=$HOME/fakeapt

function init() {
  mkdir -p $TMPAPT/{archives,lists}/partial
  cp $1 $TMPAPT/lists/Packages
  touch $TMPAPT/status

cat > $TMPAPT/apt.conf <<EOF
APT::Architecture "$2";
APT::Get::List-Cleanup "false";
Dir::Cache $TMPAPT;
Dir::State $TMPAPT;
Dir::State::status $TMPAPT/status;
Dir::Etc::SourceList $TMPAPT/sources.list;
EOF

cat > $TMPAPT/sources.list <<EOF
deb file:$TMPAPT/lists/ ./
EOF

  APT_CONFIG=$TMPAPT/apt.conf apt-get update
}

function debtree() {
  APT_CONFIG=$TMPAPT/apt.conf /usr/bin/debtree $@
}

case "$1" in
  init)
    init $3 $2
  ;;
  *)
    debtree $@
  ;;
esac

To use it, first, we need to initialize the fake apt repo, then we can just just debtree normally.

$./debtree.sh init amd64 unstable.packages 
Ign file: ./ Release.gpg
Ign file: ./ Translation-en_US
Ign file: ./ Release
Ign file: ./ Packages
Ign file: ./ Packages
Reading package lists... Done
abate@dev.au:~$./debtree.sh bash
Reading package lists... Done
Building dependency tree... Done
digraph "bash" {
    rankdir=LR;
    node [shape=box];
    "bash" -> "base-files" [color=blue,label="(>= 2.1.12)"];
    "base-files" -> "base-passwd" [color=blue,label="(>= 2.0.3.4)"];
    "base-files" -> "awk" [color=purple,style=bold];
    "awk" -> "Pr_awk" [label="-3-",dir=back,arrowtail=inv,color=green];
    "Pr_awk" [label="...",style=rounded];
    "awk" [shape=octagon];
    "bash" -> "debianutils" [color=blue,label="(>= 2.15)"];
    "debianutils" -> "sensible-utils" [color=blue];
    "bash" -> "dash" [color=purple,style=bold,label="(>= 0.5.5.1-2.2)"];
    "dash" -> "debianutils" [color=blue,label="(>= 2.15)"];
    "dash" -> "dpkg" [color=blue,label="(>= 1.15.0)"];
    "bash" -> "libncurses5" [color=purple,style=bold,label="(>= 5.6+20071006-3)"];
    "libncurses5" -> "libgpm2";
    "bash" -> "bash-completion" [label="(>= 20060301-0)"];
    "bash-completion" -> "bash" [color=blue,label="(>= 3.1dfsg-9)"];
    "bash" [style="setlinewidth(2)"]
    "dpkg" [shape=diamond];
}
I: The following dependencies have been excluded from the graph (skipped):
I: libc6
// Excluded dependencies:
// libc6