From 45b02b302ec3491224c582d650e385a0dbd9c0f0 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Thu, 16 Jan 2025 18:26:57 +1100 Subject: [PATCH] pacman_unrequired_packages: new plugin Heavily based on pacman_pending_updates --- plugins/other/pacman_unrequired_packages | 81 ++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 plugins/other/pacman_unrequired_packages diff --git a/plugins/other/pacman_unrequired_packages b/plugins/other/pacman_unrequired_packages new file mode 100755 index 00000000..6b72710d --- /dev/null +++ b/plugins/other/pacman_unrequired_packages @@ -0,0 +1,81 @@ +#!/bin/sh + +: <<=cut + +=head1 NAME + +pacman_unrequired_packages - Plugin to monitor packages no longer required. + +=head1 APPLICABLE SYSTEMS + +All systems with pacman as their package manager. + +=head1 CONFIGURATION + +The plugin needs no additional configuration and works out of the box. + +=head1 INTERPRETATION + +This plugin will draw one block: the number of packages no longer required. + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=head1 VERSION + + 1.0.0 + +=head1 AUTHOR + +Olivier Mehani +Bert Peters (pacman_pending_updates) + +=head1 LICENSE + +GPLv2 + +=cut + +case $1 in + config) + cat <<'EOM' +graph_args --base 1000 -l 0 +graph_title Unrequired packages +graph_vlabel packages +graph_category security +unrequired.label unrequired +unrequired.info Current number of unrequired packages. They can be removed with `pacman -Rsn $(pacman -Qdtq).` +unrequired.draw AREA +EOM + ;; + + autoconf) + if hash pacman >/dev/null 2>&1; then + echo yes + else + echo "no (pacman not found)" + fi + ;; + + *) + unrequired="$(pacman -Qdtq)" + exitcode=$? + if [ "$exitcode" = 0 ]; then + if [ -n "$unrequired" ]; then + echo "unrequired.value $(echo "$unrequired" | wc -l)" + echo "unrequired.extinfo $(echo "$unrequired" | paste -s -d,)" + else + echo "unrequired.value 0" + fi + elif [ "$exitcode" = 1 ]; then + # "pacman" returns the exitcode 1 if no matching package is found + echo "unrequired.value 0" + else + echo "unrequired.value U" + fi + ;; +esac + +exit 0