#!/bin/bash

# Orphan
# Lists all packages installed that do not exist in the apt cache. Takes bloody
# ages to do so. Can be made (much) faster by removing packages from the
# 'available' set as they are found, probably best done with a rewrite in
# python.

awkprog='/^Package:/ { printf "%s ", $2 }
         /^Version:/ { print $2 }'

while read name version
do
        version=$( grep-status -n -s version  -X --field=package $name )
        grep-dctrl -q  -X --field=Package $name  --and  -X --field=Version $version  /var/lib/apt/lists/*_Packages || echo $name
done < <(
        grep-status --show-field=Package,Version  -r --field=status ^install | awk "$awkprog" | sort
        )
