diff --git a/check_packages2install b/check_packages2install index 116ed2ec06359b7032dcfcf52bd42cee31d01895..cce6b7bc174b8aecd380d0c3aa2c4f1f604360ed 100755 --- a/check_packages2install +++ b/check_packages2install @@ -21,6 +21,8 @@ # 2021-12-17 v1.7 <axel.hahn@iml.unibe.ch> show non matching packages in section "other" # 2021-12-20 v1.8 <axel.hahn@iml.unibe.ch> show all packages if no filter matched # 2022-06-03 v1.9 <axel.hahn@iml.unibe.ch> call yum with path; shellcheck updates; plugin like package managers +# 2022-06-07 v1.10 <axel.hahn@iml.unibe.ch> fix iPkg2Update on empty package list +# rename package manager functions # ====================================================================== @@ -88,11 +90,17 @@ Get packages that must be updated on this system Licence: GNU GPL 3 ______________________________________________________________________ -Get packages that must be updated on this system ans show found +Get packages that must be updated on this system and show found packages in groups. -For groups and their search filters see files in subdir -check_packages2install-data. +RELATED FILES: +1) For groups and their search filters see files in subdir + check_packages2install-data. +2) In the subdir check_packages2install-pkgmanager are scripts + for supported package managers (with aded ".sh"). + +OUTPUT: +It returns UNKNOWN if package manager is not supported. It returns OK if the system is up to date. It returns WARNING or ERROR if count of found pakackes is greater than @@ -111,13 +119,12 @@ $_self [options] OPTIONS: - -h show this help -w custom warning level; default: $iWarnDefault -c custom critical level; default: $iCriticalDefault PARAMETERS: - None. + -h show this help EOF } @@ -153,7 +160,7 @@ function _detectPkgManager(){ function showFilteredPackages(){ # filtered package view - if [ ! -z "$packages2install" ]; then + if [ -n "$packages2install" ]; then typeset -i iTotal iTotal=$( echo "$packages2install" | wc -l ) typeset -i iFound=0 @@ -194,7 +201,6 @@ function showFilteredPackages(){ # total packages echo Total packages to install: $iTotal - ph.perfadd "updates-available" "$iTotal" ${iWarnLimit} ${iCriticalLimit} fi @@ -224,7 +230,7 @@ fi # load functions for the detected package manager . "${dir_pkg}/${pkgmanager}.sh" || exit 2 -packagemanOut=$( ${pkgmanager}GetUpdates ) +packagemanOut=$( ${pkgmanager}.GetUpdates ) if [ -z "$packagemanOut" ]; then ph.setStatus "critical" @@ -232,9 +238,9 @@ if [ -z "$packagemanOut" ]; then else # generated function names - package manager is prefix - function2install="${pkgmanager}Packages" - _functionExists "${pkgmanager}Status" && functionStatus="${pkgmanager}Status" - _functionExists "${pkgmanager}Critical" && functionCritical="${pkgmanager}Critical" + function2install="${pkgmanager}.getPackageList" + _functionExists "${pkgmanager}.getStatusLine" && functionStatus="${pkgmanager}.getStatusLine" + _functionExists "${pkgmanager}.getCriticalList" && functionCritical="${pkgmanager}.getCriticalList" # count of packages ... to install ... critical (centos only) typeset -i iPkg2Update=0 @@ -242,7 +248,7 @@ else # get list of packages 2 install packages2install=$( $function2install ) - iPkg2Update=$( echo "$packages2install" | wc -l ) + iPkg2Update=$( test -n "$packages2install" && echo "$packages2install" | wc -l ) # custom: status text test -n "$functionStatus" && statusLabel="[$pkgmanager] $( $functionStatus )" @@ -259,6 +265,7 @@ else else ph.setStatusByLimit ${iPkg2Update} ${iWarnLimit} ${iCriticalLimit} fi + ph.perfadd "updates-available" "${iPkg2Update}" "${iWarnLimit}" "${iCriticalLimit}" # set label for status line if [ -z "$statusLabel" ]; then diff --git a/check_packages2install-pkgmanager/apt.sh b/check_packages2install-pkgmanager/apt.sh index b650f3802c33ce4c427b48ebfbf0183852a81a0e..877722d73b49d8d51ed2aca3b8cf98479a352b93 100644 --- a/check_packages2install-pkgmanager/apt.sh +++ b/check_packages2install-pkgmanager/apt.sh @@ -9,27 +9,27 @@ # --------------------------------------------------------------- # ah <axel.hahn@iml.unibe.ch> # 2022-06-03 v1.0 ah first version +# 2022-06-07 v1.1 ah remove text "Nothing to install" +# rename functions # =============================================================== # --------------------------------------------------------------- # command to list of updates -function aptGetUpdates(){ +function apt.getUpdates(){ sudo apt-get -u upgrade --assume-no } # --------------------------------------------------------------- # extract list of packages 2 install # global string packagemanOut output of update lister command -function aptPackages(){ +function apt.getPackageList(){ # detect number of line containing "The following packages will be upgraded:" typeset -i local iStart iStart=$( echo "$packagemanOut" | grep -n '^The following packages will be upgraded:' | cut -f 1 -d ':' ) - if [ $iStart -eq 0 ]; then - echo "Nothing to install" - else + if [ $iStart -gt 0 ]; then # show packages = text starting with 2 spaces below start line # packages are delimited with space -> replace with new line echo "$packagemanOut" | sed -n $iStart,\$p | grep "^\ \ " | sed "s#^\ \ ##g" | tr " " "\n" @@ -39,7 +39,7 @@ function aptPackages(){ # --------------------------------------------------------------- # get status line on apt based systems (debian, ubuntu) # global string packagemanOut output of update lister command -function aptStatus(){ +function apt.getStatusLine(){ echo "$packagemanOut" | grep "upgraded.*installed" } diff --git a/check_packages2install-pkgmanager/pamac.sh b/check_packages2install-pkgmanager/pamac.sh index 279b07308218f5e6c2f78002a3351ed9e87d4206..b5f039f4a4291330f637ced3a518582650235238 100644 --- a/check_packages2install-pkgmanager/pamac.sh +++ b/check_packages2install-pkgmanager/pamac.sh @@ -9,18 +9,19 @@ # --------------------------------------------------------------- # ah <axel.hahn@iml.unibe.ch> # 2022-06-03 v1.0 ah first version +# 2022-06-07 v1.1 ah rename functions # =============================================================== # --------------------------------------------------------------- # command to list of updates -function pamacGetUpdates(){ +function pamac.GetUpdates(){ pamac checkupdates } # --------------------------------------------------------------- # extract list of packages 2 install # global string packagemanOut output of update lister command -function pamacPackages(){ +function pamac.getPackageList(){ echo "$packagemanOut" | grep -- '->' } diff --git a/check_packages2install-pkgmanager/yum.sh b/check_packages2install-pkgmanager/yum.sh index 6e557c647af38016ee029ff71affbe97373e72dc..829abe63f1fdedf2264f375666b1f01483dfb4a0 100644 --- a/check_packages2install-pkgmanager/yum.sh +++ b/check_packages2install-pkgmanager/yum.sh @@ -9,19 +9,21 @@ # --------------------------------------------------------------- # ah <axel.hahn@iml.unibe.ch> # 2022-06-03 v1.0 ah first version +# 2022-06-07 v1.1 ah add sudo for yum --bugfix check-update +# rename functions # =============================================================== # --------------------------------------------------------------- # command to list of updates -function yumGetUpdates(){ +function yum.GetUpdates(){ sudo /usr/bin/yum -y check-update } # --------------------------------------------------------------- # extract list of packages 2 install # global string packagemanOut output of update lister command -function yumPackages(){ +function yum.getPackageList(){ local iStart=3 # detect number of line containing "Obsoleting Packages" typeset -i iEnd=$( echo "$packagemanOut" | grep -n '^Obsoleting Packages' | cut -f 1 -d ':' )-1 @@ -34,16 +36,16 @@ function yumPackages(){ # --------------------------------------------------------------- # get custom status -function yumStatus(){ - if ! /usr/bin/yum --bugfix check-update 2>&1 | grep security; then - echo "Ooops - no output from [/usr/bin/yum --bugfix check-update]" +function yum.getStatusLine(){ + if ! sudo /usr/bin/yum --bugfix check-update 2>&1 | grep security; then + echo "Ooops - no output from [sudo /usr/bin/yum --bugfix check-update]" fi } # --------------------------------------------------------------- # extract count of critical packages # param string text to extract critical counter from -function yumCritical(){ +function yum.getCriticalList(){ local summary="$1" # example outputs: # I No packages needed for security; 223 packages available