Skip to content
Snippets Groups Projects
Commit bd9befb3 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

task-4888 show filtered overview of packages

parent 9dc1ce7e
Branches
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
# 2020-03-11 v1.4 <axel.hahn@iml.unibe.ch> add -c -w limits; added perfdata (yum) # 2020-03-11 v1.4 <axel.hahn@iml.unibe.ch> add -c -w limits; added perfdata (yum)
# 2021-05-11 v1.4 <axel.hahn@iml.unibe.ch> added centos8 support # 2021-05-11 v1.4 <axel.hahn@iml.unibe.ch> added centos8 support
# 2021-08-20 v1.5 <martin.gasser@iml.unibe.ch> bug fixing - missing sudo in yum command # 2021-08-20 v1.5 <martin.gasser@iml.unibe.ch> bug fixing - missing sudo in yum command
# 2021-12-16 v1.6 <axel.hahn@iml.unibe.ch> show filtered overview
# ====================================================================== # ======================================================================
...@@ -25,6 +26,8 @@ ...@@ -25,6 +26,8 @@
typeset -i iCount=0 typeset -i iCount=0
tmpfile=/tmp/packages2install.log tmpfile=/tmp/packages2install.log
cronfile=/etc/cron.d/system-updater cronfile=/etc/cron.d/system-updater
MYhost="localhost"
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# functions # functions
...@@ -44,7 +47,62 @@ function showAutoupdate(){ ...@@ -44,7 +47,62 @@ function showAutoupdate(){
echo Autoupdate OFF echo Autoupdate OFF
fi fi
} }
# execute a local or a remote command
function _exec(){
if [ ${MYhost} = "localhost" ]; then
eval "$1"
else
${MYsshprefix}${MYhost} "$1"
fi
}
function detectPkgManager(){
local _list="apt yum pamac"
local out=$( _exec "which $_list 2>/dev/null" )
for mypkg in $_list
do
echo "$out" | grep "/$mypkg" > /dev/null && echo $mypkg
done
}
# Debian like Linux
# - Debian 11
function pkgApt(){
local sum=$( _exec "sudo apt-get -u upgrade --assume-no" )
# detect number of line containing "The following packages will be upgraded:"
typeset -i local iStart=$( echo "$sum" | grep -n '^The following packages will be upgraded:' | cut -f 1 -d ':' )
if [ $iStart -eq 0 ]; then
echo "Nothing to install"
else
# show packages = text starting with 2 spaces below start line
# packages are delimited with space -> replace with new line
echo "$sum" | sed -n $iStart,\$p | grep "^\ \ " | sed "s#^\ \ ##g" | tr " " "\n"
fi
}
# Arch Linux, Manjaro
function pkgPamac(){
_exec "pamac checkupdates | grep -- '->'"
}
# RedHat like Linux
# - Centos 8
function pkgYum(){
local sum=$( _exec "sudo dnf check-update" )
local iStart=3
# detect number of line containing "Obsoleting Packages"
typeset -i iEnd=$( echo "$sum" | grep -n '^Obsoleting Packages' | cut -f 1 -d ':' )-1
local sEnd=$iEnd
test "$iEnd" = "-1" && sEnd='$'
echo "$sum" | sed -n ${iStart},${sEnd}p
# echo "show lines ${iStart} -> ${sEnd}"
}
# check updates with apt and exit script # check updates with apt and exit script
function checkApt(){ function checkApt(){
# bug #2818 # bug #2818
...@@ -116,31 +174,70 @@ function checkYum(){ ...@@ -116,31 +174,70 @@ function checkYum(){
# main # main
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# set default / override from command line params # set default / override from command line params
typeset -i iWarnLimit=` ph.getValueWithParam 1 w "$@"` typeset -i iWarnLimit=` ph.getValueWithParam 1 w "$@"`
typeset -i iCriticalLimit=` ph.getValueWithParam 200 c "$@"` typeset -i iCriticalLimit=` ph.getValueWithParam 200 c "$@"`
typeset -i bFound=0
# ----- try package manager apt # ----- try package manager apt
if [ `which apt-get 2>/dev/null` ]; then pgkman=$( detectPkgManager )
bFound=1 case $pgkman in
checkApt "apt")
fi pkgstatus=$( checkApt )
pkgsum=$( pkgApt )
# ----- try package manager yum ;;
if [ `which yum 2>/dev/null` ]; then "pamac")
bFound=1 pkgstatus=""
checkYum pkgsum=$( pkgPamac )
fi ;;
"yum")
pkgstatus=$( checkYum )
pkgsum=$( pkgYum )
;;
*)
ph.abort "UNKNOWN: package manager [$pgkman] was not detected or is not supported yet."
;;
esac
echo "$pkgstatus"
# filtered package view
if [ ! -z "$pkgsum" ]; then
typeset -i iTotal=$( echo "$pkgsum" | wc -l )
typeset -i iFound=0
# show filtered view
for filterfile in $( ls -1 $0-data/*txt | sort )
do
filtername=$( echo $filterfile | rev | cut -f 1 -d "/" | rev | sed "s#.txt\$##g" )
filterdata=$( cat ${filterfile} | grep "^[a-zA-Z]" )
out=$( echo "$pkgsum" | _filterPkg "${filterdata}" )
typeset -i iCount=$( echo "$out" | grep "." | wc -l )
test $iCount -ne 0 && (
echo --- $( echo "$filtername" | sed "s#MYfilter##g" ): $iCount
echo "$out" | nl; echo
)
iFound=$iFound+$iCount
done
# show count of non matching packages
typeset -i iOther=$iTotal-$iFound
if [ $iFound -eq 0 ]; then
echo "No package matched a group filter."
else
echo "Other packages: $iOther"
fi
# total packages
echo Total packages to update [$pgkman]: $iTotal
echo
if [ $bFound -eq 0 ]; then
ph.abort "UNKNOWN: package manager is not supported yet. I only know apt and yum so far."
fi fi
showAutoupdate showAutoupdate
ph.exit ph.exit
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
basesystem
centos
kernel
linux
ubuntu
\ No newline at end of file
openssh
openssl
samba
sssd
\ No newline at end of file
java
python
php
ruby
node
r-
\ No newline at end of file
apache2
httpd
haproxy
tomcat
\ No newline at end of file
couchdb
mariadb
mysql
openldap
postgresql
sqlite
\ No newline at end of file
git
httrack
icinga
opencpu
shibboleth
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment