Commit 5c9420f0 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch '5419-update-check-packages2install' into 'master'

add sudo when calling yum

See merge request !20
parents c4e90162 6cd526a7
......@@ -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
......
......@@ -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"
}
......
......@@ -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 -- '->'
}
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment