yum.sh 1.92 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
# ===============================================================
#
# PACKAGE MANAGER: YUM
# CentOS
#
# included by ../check_packages2install
#
# ---------------------------------------------------------------
# ah <axel.hahn@iml.unibe.ch>
# 2022-06-03  v1.0  ah  first version
12
13
# 2022-06-07  v1.1  ah  add sudo for yum --bugfix check-update
#                       rename functions
14
15
16
17
18
# ===============================================================


# ---------------------------------------------------------------
# command to list of updates
19
function yum.getUpdates(){
20
21
22
23
24
25
    sudo /usr/bin/yum -y check-update
}

# ---------------------------------------------------------------
# extract list of packages 2 install
# global  string  packagemanOut  output of update lister command
26
function yum.getPackageList(){
27
28
    local iStart=3
    # detect number of line containing "Obsoleting Packages"
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
29
30
    typeset -i local iEnd
    iEnd=$( echo "$packagemanOut" | grep -n '^Obsoleting Packages' | cut -f 1 -d ':' )-1
31
32
33
34
35
36
37
38
39

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

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

# ---------------------------------------------------------------
# get custom status
40
function yum.getStatusLine(){
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
41
  if ! sudo /usr/bin/yum --bugfix check-update 2>&1 | grep security; then
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
42
    echo "No security updates needed and no updates available"
43
44
45
46
  fi
}

# ---------------------------------------------------------------
47
# extract count of critical packages
48
# param  string  text to extract critical counter from
49
function yum.getCriticalList(){
50
51
52
53
54
55
56
57
58
  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"
}

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