apt.sh 1.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
# ===============================================================
#
# PACKAGE MANAGER: APT
# Debian, Ubuntu
#
# 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  remove text "Nothing to install"
#                       rename functions
14
15
16
17
18
# ===============================================================


# ---------------------------------------------------------------
# command to list of updates
19
function apt.getUpdates(){
20
21
22
23
24
25
    sudo apt-get -u upgrade --assume-no
}

# ---------------------------------------------------------------
# extract list of packages 2 install
# global  string  packagemanOut  output of update lister command
26
function apt.getPackageList(){
27
28
29
30
31

    # 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 ':' )

32
    if [ $iStart -gt 0 ]; then
33
34
35
36
37
38
39
40
41
        # 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"
    fi
}

# ---------------------------------------------------------------
# get status line on apt based systems (debian, ubuntu)
# global  string  packagemanOut  output of update lister command
42
function apt.getStatusLine(){
43
44
45
46
  echo "$packagemanOut" | grep "upgraded.*installed"
}

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