1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 14:16:00 +00:00

[deborphan] Cleanup and add POD doc

Signed-off-by: Olivier Mehani <shtrom@ssji.net>
This commit is contained in:
Olivier Mehani 2016-10-29 16:08:19 +11:00
parent 4a206ac9fd
commit 5cfc73c3c8

View file

@ -1,36 +1,57 @@
#!/bin/bash #!/bin/bash
#
# Plugin to monitor the number of orphaned packages on the : << =cut
# system (using deborphan). Might work on section distib, who knows...
# =head1 NAME
# Based on the debsecan plugin by Nicolas Bouthors. 2016-09-02
# deborphan - Monitor orphaned Debian packages
# Olivie Mehani <shtrom@ssji.net>
# =head1 APPLICABLE SYSTEMS
# Licence : GPLv2
# Debian-ish systems with deborphan installed.
#%# family=auto
#%# capabilities=autoconf =head1 CONFIGURATION
None needed.
=head1 AUTHOR
Olivier Mehani <shtrom+munin@ssji.net>
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 # Auto enable if we have deborphan only
if [ "$1" = "autoconf" ] ; then if [ "$1" = "autoconf" ] ; then
if [ -x /usr/bin/deborphan ]; then if which deborphan >/dev/null; then
echo yes echo yes
else else
echo no echo "no (deborphan is missing)"
fi fi
exit 0 exit 0
fi fi
# Fail if we don't have deborphan # 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 exit 1
fi fi
OUT=`mktemp -t deborphan.XXXXXX` OUT=$(mktemp -t munin-deborphan.XXXXXX)
deborphan --show-section --guess-all | sed 's/\//_/' | sort > ${OUT} 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 if [ "$1" = "config" ]; then
cat <<EOF cat <<EOF
@ -53,12 +74,12 @@ EOF
else else
for cat in ${CATEGORIES}; do for cat in ${CATEGORIES}; do
TMP=`mktemp -t deborphan.XXXXXX` TMP=$(mktemp -t munin-deborphan.XXXXXX)
sed -n "s/${cat} *//p" ${OUT} > ${TMP} TMPFILES="${TMPFILES} $TMP"
echo "${cat}.value `cat ${TMP} | wc -l`" sed -n "s/${cat} \+//p" "${OUT}" > "${TMP}"
echo "${cat}.extinfo `echo $(cat ${TMP})`" echo "${cat}.value $(wc -l < "${TMP}")"
rm ${TMP} # shellcheck disable=SC2005 disable=SC2046
# echo is not useless here: we want everything on one line
echo "${cat}.extinfo $(echo $(cat "${TMP}"))"
done done
fi fi
rm -f ${OUT}