#!/bin/sh

echo "List of files that might be candidates to be split out"
grep-status -n -sPackage -FMulti-Arch same | \
  grep -Ev -e '-(dev|doc)' | xargs dpkg -L | grep '\/usr\/share\/' | \
  grep -Ev '(copyright|changelog|NEWS|README)' | \
  while read f; do test -f "$f" && printf "$f\0"; done | \
  du -bsch --files0-from -

waste_libs=$(grep-status -n -sPackage -FMulti-Arch same | \
  grep -Ev -e '-(dev|doc)' | xargs dpkg -L | grep '\/usr\/share\/' | \
  while read f; do test -f "$f" && printf "$f\0"; done | \
  du -bc --files0-from - | tail -n 1 | cut -f1)
echo "Approx. installed m-a:same lib waste (w/o -dev,-doc): $waste_libs"

waste_same=$(grep-status -n -sPackage -FMulti-Arch same | \
  xargs dpkg -L | grep '\/usr\/share\/' | \
  while read f; do test -f "$f" && printf "$f\0"; done | \
  du -bc --files0-from - | tail -n 1 | cut -f1)
echo "Approx. installed m-a:same lib waste (w/ -dev,-doc): $waste_same"

inst_same=$(grep-status -n -sPackage -FMulti-Arch same | wc -l)
waste_per_lib=$(echo "scale=2; $waste_same / $inst_same" | bc -l)
echo "Approx. installed m-a:same lib waste per package ($waste_same / $inst_same): $waste_per_lib"

inst_libs=$(grep-status -n -r -sPackage -FSection libs| \
  grep -Ev '(common|data|-bin)'| wc -l)
waste_inst=$(echo "scale=2; $inst_libs * $waste_per_lib" | bc -l)
echo "Approx. predicted lib waste per arch ($inst_libs * $waste_per_lib): $waste_inst"

total_libs=$(grep-aptavail -n -r -sPackage -FSection libs| \
  grep -Ev '(common|data|-bin)'| wc -l)
waste_total=$(echo "scale=2; $total_libs * $waste_per_lib" | bc -l)
echo "Approx. total lib waste per arch ($total_libs * $waste_per_lib): $waste_total"
