#!/bin/sh
# File: apt-summary
# Location: /usr/bin
# Author: bgstack15@gmail.com
# Startdate: 2020-09-22
# Title: Apt summarizer
# Purpose: Facilitate listing source repos for packages
# History:
# Usage:
# Reference:
#    https://bgstack15.wordpress.com/2020/09/22/apt-show-repositories-for-currently-installed-packages/
# Improve:
# Documentation:
# Dependencies:
#    devuan-req: apt-cache

apt-cache policy $( dpkg -l | awk '$1 ~ /^ii/ {print $2}' ) | awk '/^[^ ]+:$/{gsub(":$","",$0);a=$0;b="";c=""} /\*\*\*/ {b=$2} $1 > "100" {c=$2"/"$3} $1 == "100" {print a,b,c}' | \
{
   if test -n "${SUMMARIZE}" || echo " ${@} " | grep -qE -e ' -s ' ;
   then
      awk '$NF ~ /:\/\// {x[$NF]++} END {for(i in x) print i": "x[i]}'
   else
      cat
   fi
}
