From 75a476c2a7164f1f6e172d65f7a53e4ea37c7e67 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Wed, 26 Apr 2017 21:42:47 +1000 Subject: [PATCH] [debian/debsecan_] Code cleanup Signed-off-by: Olivier Mehani --- plugins/debian/debsecan_ | 50 ++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/plugins/debian/debsecan_ b/plugins/debian/debsecan_ index 6b1f69e5..b563116b 100755 --- a/plugins/debian/debsecan_ +++ b/plugins/debian/debsecan_ @@ -74,17 +74,17 @@ MODE=$(echo "$0" | sed 's/.*_//') case "${MODE}" in 'cve') TITLE_ADD="unique " - CUT_FIELD=1 + FIELD=1 ;; 'pkg' | *) TITLE_ADD="package " - CUT_FIELD=2 + FIELD=2 ;; esac if [ "$1" = "config" ] ; then cat < /dev/null) -REMOTE=$(echo "$ALL" | grep 'remotely') -NONREMOTE=$(echo "$ALL" | grep -v 'remotely') +REMOTE=$(echo "$ALL" | grep -w 'remotely') +NONREMOTE=$(echo "$ALL" | grep -wv 'remotely') -HIGH=$(echo "${NONREMOTE}" | grep 'high urgency') -MEDIUM=$(echo "${NONREMOTE}" | grep 'medium urgency') -LOW=$(echo "${NONREMOTE}" | grep 'low urgency') -OTHER=$(echo "${NONREMOTE}" | grep -v 'urgency') -FIXED=$(echo "${ALL}" | grep '(fixed') +HIGH=$(echo "${NONREMOTE}" | grep -w 'high urgency') +MEDIUM=$(echo "${NONREMOTE}" | grep -w 'medium urgency') +LOW=$(echo "${NONREMOTE}" | grep -w 'low urgency') +OTHER=$(echo "${NONREMOTE}" | grep -wv 'urgency') +FIXED=$(echo "${ALL}" | grep -w '(fixed') + +# Arguments: Field offset to aggregate by +count_entries() { + CUT_FIELD=${1} + cut -f "${CUT_FIELD}" -d " "| sort | uniq -c +} case "${MODE}" in 'cve') - remote_count=$(echo "${REMOTE}" | cut -f "${CUT_FIELD}" -d " "| sort | uniq | wc -l) - high_count=$(echo "${HIGH}" | cut -f "${CUT_FIELD}" -d " "| sort | uniq | wc -l) - medium_count=$(echo "${MEDIUM}" | cut -f "${CUT_FIELD}" -d " "| sort | uniq | wc -l) - low_count=$(echo "${LOW}" | cut -f "${CUT_FIELD}" -d " "| sort | uniq | wc -l) - other_count=$(echo "${OTHER}" | cut -f "${CUT_FIELD}" -d " "| sort | uniq | wc -l) - fixed_count=$(echo "${FIXED}" | cut -f "${CUT_FIELD}" -d " "| sort | uniq | wc -l) + remote_count=$(echo "${REMOTE}" | count_entries ${FIELD} | wc -l) + high_count=$(echo "${HIGH}" | count_entries ${FIELD} | wc -l) + medium_count=$(echo "${MEDIUM}" | count_entries ${FIELD} | wc -l) + low_count=$(echo "${LOW}" | count_entries ${FIELD} | wc -l) + other_count=$(echo "${OTHER}" | count_entries ${FIELD} | wc -l) + fixed_count=$(echo "${FIXED}" | count_entries ${FIELD} | wc -l) ;; 'pkg' | *) remote_count=$(echo "${REMOTE}" | wc -l) @@ -169,15 +175,15 @@ CVECOUNTRE="s/^ *\([0-9]\+\) \+\([^ ]\+\)/\2 (\1)/" # The nested $(echo ...)s are needed to yet the newlines cat <