From 4a206ac9fde652787ba0fcafb15e54e9481aabab Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sat, 3 Sep 2016 14:09:37 +1000 Subject: [PATCH 1/4] [deborphan] New plugin counting orphaned packages in all sections Signed-off-by: Olivier Mehani --- plugins/system/deborphan | 64 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 plugins/system/deborphan diff --git a/plugins/system/deborphan b/plugins/system/deborphan new file mode 100755 index 00000000..19eafee2 --- /dev/null +++ b/plugins/system/deborphan @@ -0,0 +1,64 @@ +#!/bin/bash +# +# Plugin to monitor the number of orphaned packages on the +# system (using deborphan). Might work on section distib, who knows... +# +# Based on the debsecan plugin by Nicolas Bouthors. 2016-09-02 +# +# Olivie Mehani +# +# Licence : GPLv2 +# +#%# family=auto +#%# capabilities=autoconf + +# Auto enable if we have deborphan only +if [ "$1" = "autoconf" ] ; then + if [ -x /usr/bin/deborphan ]; then + echo yes + else + echo no + fi + exit 0 +fi + +# Fail if we don't have deborphan +if [ ! -x /usr/bin/deborphan ]; then + exit 1 +fi + +OUT=`mktemp -t deborphan.XXXXXX` +deborphan --show-section --guess-all | sed 's/\//_/' | sort > ${OUT} + +CATEGORIES="$(sed 's/ .*//' ${OUT} | uniq)" + +if [ "$1" = "config" ]; then + cat < ${TMP} + echo "${cat}.value `cat ${TMP} | wc -l`" + echo "${cat}.extinfo `echo $(cat ${TMP})`" + rm ${TMP} + done +fi + +rm -f ${OUT} From 5cfc73c3c8b5efede38bb60710caa3b2bfe3beaa Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sat, 29 Oct 2016 16:08:19 +1100 Subject: [PATCH 2/4] [deborphan] Cleanup and add POD doc Signed-off-by: Olivier Mehani --- plugins/system/deborphan | 71 ++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/plugins/system/deborphan b/plugins/system/deborphan index 19eafee2..e063de53 100755 --- a/plugins/system/deborphan +++ b/plugins/system/deborphan @@ -1,36 +1,57 @@ #!/bin/bash -# -# Plugin to monitor the number of orphaned packages on the -# system (using deborphan). Might work on section distib, who knows... -# -# Based on the debsecan plugin by Nicolas Bouthors. 2016-09-02 -# -# Olivie Mehani -# -# Licence : GPLv2 -# -#%# family=auto -#%# capabilities=autoconf + +: << =cut + +=head1 NAME + +deborphan - Monitor orphaned Debian packages + +=head1 APPLICABLE SYSTEMS + +Debian-ish systems with deborphan installed. + +=head1 CONFIGURATION + +None needed. + +=head1 AUTHOR + +Olivier Mehani +Based on the debsecan plugin by Nicolas Bouthors. 2016-09-02 + +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut # Auto enable if we have deborphan only if [ "$1" = "autoconf" ] ; then - if [ -x /usr/bin/deborphan ]; then + if which deborphan >/dev/null; then echo yes else - echo no + echo "no (deborphan is missing)" fi exit 0 fi # Fail if we don't have deborphan -if [ ! -x /usr/bin/deborphan ]; then +if ! which deborphan >/dev/null; then + echo "deborphan is missing" >&2 exit 1 fi -OUT=`mktemp -t deborphan.XXXXXX` -deborphan --show-section --guess-all | sed 's/\//_/' | sort > ${OUT} +OUT=$(mktemp -t munin-deborphan.XXXXXX) +TMPFILES=$OUT +trap 'rm -f $TMPFILES' EXIT +deborphan --show-section --guess-all | sed 's/\//_/' | sort > "${OUT}" -CATEGORIES="$(sed 's/ .*//' ${OUT} | uniq)" +CATEGORIES="$(awk '{print $1}' "${OUT}" | uniq)" if [ "$1" = "config" ]; then cat < ${TMP} - echo "${cat}.value `cat ${TMP} | wc -l`" - echo "${cat}.extinfo `echo $(cat ${TMP})`" - rm ${TMP} + TMP=$(mktemp -t munin-deborphan.XXXXXX) + TMPFILES="${TMPFILES} $TMP" + sed -n "s/${cat} \+//p" "${OUT}" > "${TMP}" + echo "${cat}.value $(wc -l < "${TMP}")" + # shellcheck disable=SC2005 disable=SC2046 + # echo is not useless here: we want everything on one line + echo "${cat}.extinfo $(echo $(cat "${TMP}"))" done fi - -rm -f ${OUT} From ddbb4782ecb7d82e13e0fecd389f6dabde3acb9d Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sat, 5 Nov 2016 21:48:55 +1100 Subject: [PATCH 3/4] [deborphan] Don't use tempfiles, and other fixes Signed-off-by: Olivier Mehani --- plugins/system/deborphan | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/plugins/system/deborphan b/plugins/system/deborphan index e063de53..0fe38591 100755 --- a/plugins/system/deborphan +++ b/plugins/system/deborphan @@ -30,6 +30,9 @@ GPLv2 =cut +# shellcheck disable=SC1090 +. "$MUNIN_LIBDIR/plugins/plugin.sh" + # Auto enable if we have deborphan only if [ "$1" = "autoconf" ] ; then if which deborphan >/dev/null; then @@ -46,12 +49,9 @@ if ! which deborphan >/dev/null; then exit 1 fi -OUT=$(mktemp -t munin-deborphan.XXXXXX) -TMPFILES=$OUT -trap 'rm -f $TMPFILES' EXIT -deborphan --show-section --guess-all | sed 's/\//_/' | sort > "${OUT}" +OUT=$(deborphan --show-section --guess-all | sort) -CATEGORIES="$(awk '{print $1}' "${OUT}" | uniq)" +CATEGORIES="$(echo "${OUT}" | awk '{print $1}' | uniq)" if [ "$1" = "config" ]; then cat < "${TMP}" - echo "${cat}.value $(wc -l < "${TMP}")" - # shellcheck disable=SC2005 disable=SC2046 - # echo is not useless here: we want everything on one line - echo "${cat}.extinfo $(echo $(cat "${TMP}"))" + for CAT in ${CATEGORIES}; do + CATFIELD=$(clean_fieldname "${CAT}") + CATDATA=$(echo "${OUT}" | sed -n "s#${CAT} \+##p") + echo "${CATFIELD}.value $(echo "${CATDATA}" | wc -l)" + echo "${CATFIELD}.extinfo $(echo "${CATDATA}" | tr '\n' ' ')" done fi From 000c97ccece6cd644f642085cbda1dc40ae35742 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sat, 5 Nov 2016 21:51:10 +1100 Subject: [PATCH 4/4] [deborphan] No longer dependent on bashisms Signed-off-by: Olivier Mehani --- plugins/system/deborphan | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/system/deborphan b/plugins/system/deborphan index 0fe38591..10d5ac44 100755 --- a/plugins/system/deborphan +++ b/plugins/system/deborphan @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh : << =cut