yum.sh 1.78 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# ===============================================================
#
# PACKAGE MANAGER: YUM
# CentOS
#
# included by ../check_packages2install
#
# ---------------------------------------------------------------
# ah <axel.hahn@iml.unibe.ch>
# 2022-06-03  v1.0  ah  first version
# ===============================================================


# ---------------------------------------------------------------
# command to list of updates
function yumGetUpdates(){
    sudo /usr/bin/yum -y check-update
}

# ---------------------------------------------------------------
# extract list of packages 2 install
# global  string  packagemanOut  output of update lister command
function yumPackages(){
    local iStart=3
    # detect number of line containing "Obsoleting Packages"
    typeset -i iEnd=$( echo "$packagemanOut" | grep -n '^Obsoleting Packages' | cut -f 1 -d ':' )-1

    local sEnd=$iEnd
    test "$iEnd" = "-1" && sEnd='$'

    echo "$packagemanOut" | sed -n ${iStart},${sEnd}p
}

# ---------------------------------------------------------------
# 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]"
  fi
}

# ---------------------------------------------------------------
# extract count of critical 
# param  string  text to extract critical counter from
function yumCritical(){
  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"
}

# ---------------------------------------------------------------