From 0823c263912e369715b1ee3befa65cb823d2fa31 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Thu, 24 Aug 2023 14:03:16 +0200 Subject: [PATCH] packages2install - fix: count of security packages --- check_packages2install | 8 ++++---- check_packages2install-pkgmanager/yum.sh | 11 +++++++---- docs/20_Checks/check_packages2install.md | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/check_packages2install b/check_packages2install index c78f5b8..f2d8ff0 100755 --- a/check_packages2install +++ b/check_packages2install @@ -24,7 +24,7 @@ # 2022-06-07 v1.10 <axel.hahn@iml.unibe.ch> fix iPkg2Update on empty package list # rename package manager functions # 2022-10-21 v1.11 <axel.hahn@unibe.ch> remove grep: warning: stray \ before white space -# 2023-08-24 v1.12 <axel.hahn@unibe.ch> update help +# 2023-08-24 v1.12 <axel.hahn@unibe.ch> update help; rename to getSecurityCount # ====================================================================== @@ -238,7 +238,7 @@ else # generated function names - package manager is prefix function2install="${pkgmanager}.getPackageList" _functionExists "${pkgmanager}.getStatusLine" && functionStatus="${pkgmanager}.getStatusLine" - _functionExists "${pkgmanager}.getCriticalList" && functionCritical="${pkgmanager}.getCriticalList" + _functionExists "${pkgmanager}.getCriticalList" && functionSecuritycount="${pkgmanager}.getSecurityCount" # count of packages ... to install ... critical (centos only) typeset -i iPkg2Update=0 @@ -252,8 +252,8 @@ else test -n "$functionStatus" && statusLabel="[$pkgmanager] $( $functionStatus )" # custom: get count of critical packages - if [ -n "$functionCritical" ]; then - iPkgCritical=$( $functionCritical "$statusLabel" ) + if [ -n "$functionSecuritycount" ]; then + iPkgCritical=$( $functionSecuritycount "$statusLabel" ) ph.perfadd "updates-security" "${iPkgCritical}" 1 1 fi diff --git a/check_packages2install-pkgmanager/yum.sh b/check_packages2install-pkgmanager/yum.sh index fb5f3e2..956db67 100644 --- a/check_packages2install-pkgmanager/yum.sh +++ b/check_packages2install-pkgmanager/yum.sh @@ -13,7 +13,7 @@ # rename functions # 2022-08-31 v1.2 ah status line depends on os major version # 2023-07-17 v1.3 ah fix hiding obsolete packages -# 2023-08-24 v1.4 ah update getStatusLine() for centos9 +# 2023-08-24 v1.4 ah centos9: update getStatusLine() + # =============================================================== @@ -62,6 +62,7 @@ function yum.getStatusLine(){ local _total; _total=$( echo "${packages2install}" | wc -l ) local _sec; _sec=$( sudo /usr/bin/yum -y --security check-update | grep -v "^Last" | grep -c "." ) + # create a status line like in former yum versions if [ -z "$_sec" ]; then echo "No packages needed for security; ${_total} packages available" else @@ -79,13 +80,15 @@ function yum.getStatusLine(){ # --------------------------------------------------------------- # extract count of critical packages # param string text to extract critical counter from -function yum.getCriticalList(){ +function yum.getSecurityCount(){ local summary="$1" # example outputs: # I No packages needed for security; 223 packages available # II 2 package(s) needed for security, out of 237 available - # III No security updates needed, but 61 updates available << centos 8 stream - echo "$summary" | cut -f 1 -d ' ' | sed "s#[^0-9]##g" + # III No security updates needed, but 61 updates available << centos 8 stream + # IV [yum] No packages needed for security; 223 packages available << centos 9 + # V [yum] 2 package(s) needed for security, out of 237 available << centos 9 + echo "$summary" | cut -f 2 -d ' ' | sed "s#[^0-9]##g" } # --------------------------------------------------------------- diff --git a/docs/20_Checks/check_packages2install.md b/docs/20_Checks/check_packages2install.md index 5b017dd..f8a2b82 100644 --- a/docs/20_Checks/check_packages2install.md +++ b/docs/20_Checks/check_packages2install.md @@ -80,7 +80,7 @@ Each file MUST contain minumum the functions These functions are optional: * [packager].getStatusLine - get custom status line (1st line in output) -* [packager].getCriticalList - extract count of critical packages +* [packager].getSecurityCount - extract count of critical packages from status line ### Define groups -- GitLab