#!/bin/bash

# Check whether there are in a single APT list different versions of
# the same package. To do that on all APT lists of history do:
#
#   $ for l in `cat LIST` ; do ./count_distinct.sh $l.bz2 ; done 
#
# Rationale: checks whether the paper "Managing Libre Software
# Distributions under a Product Line Approach" (Herraiz et al.) says
# the true about multiple versions of the same binary
# package. Apparently it does not.

list=$(mktemp -t)
pkgs=$(mktemp -t)
trap "rm -f $list $pkgs" EXIT

if echo "$1" | grep -q -e '\.bz2$' ; then
    bunzip2 -c "$1" > $list
else
    echo "Usage: $0 APT_LIST.bz2"
    exit 2
fi

grep-dctrl -P -e '' -s Package $list > $pkgs
packages_no=$(wc -l < $pkgs)
distinct_no=$(sort -u < $pkgs | wc -l)

echo "packages: $packages_no ; distinct: $distinct_no"
