#!/bin/bash

# Author: Kees Cook <kees@ubuntu.com>
# Copyright (C) 2005-2008 Canonical Ltd.
#
# This script is distributed under the terms and conditions of the GNU General
# Public License, Version 2 or later. See http://www.gnu.org/copyleft/gpl.html
# for details.

# Reports a terse numeric of CVEs that need attention for supported packages.

TABLE=$(./scripts/ubuntu-table -s "$@")
for category in ${CATEGORY:-SUPPORTED}
do
  if [ "x$category" = "xuniverse" ]; then
    filter="-v '(SUPPORTED|PARTNER)'"
  else
    filter=$category
  fi

  for prio in critical high medium low
  do
    # make sure we don't count each CVE more than once by sorting on unique CVE id
    COUNT=$(echo "$TABLE" | grep $filter | grep ' '"$prio"'$' | cut -d" " -f1 | sort -u | wc -l)
    OUT="$OUT$COUNT "
  done
  if [ -n "$OUT" ]; then
    COUNT=$(echo "$TABLE" | grep $filter | cut -d" " -f2 | cut -d: -f1 | sort -u | wc -l)
    OUT="$OUT$COUNT"
  fi
  echo "$OUT"
done
