File: check.sh

package info (click to toggle)
incus 6.0.5-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,788 kB
  • sloc: sh: 16,313; ansic: 3,121; python: 457; makefile: 337; ruby: 51; sql: 50; lisp: 6
file content (45 lines) | stat: -rw-r--r-- 1,184 bytes parent folder | download | duplicates (3)
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
# Miscellaneous test checks.

check_dependencies() {
    # shellcheck disable=SC2039,3043
    local dep missing
    missing=""

    for dep in "$@"; do
        if ! command -v "$dep" > /dev/null 2>&1; then
            [ "$missing" ] && missing="$missing $dep" || missing="$dep"
        fi
    done

    if [ "$missing" ]; then
        echo "Missing dependencies: $missing" >&2
        exit 1
    fi
}

check_empty() {
    if [ "$(find "${1}" 2> /dev/null | wc -l)" -gt "1" ]; then
        echo "${1} is not empty, content:"
        find "${1}"
        false
    fi
}

check_empty_table() {
    # The profiles table will never be empty since the `default` profile cannot
    # be deleted.
    if [ "$2" = 'profiles' ]; then
        if [ -n "$(sqlite3 "${1}" "SELECT * FROM ${2} WHERE name != 'default';")" ]; then
            echo "DB table ${2} is not empty, content:"
            sqlite3 "${1}" "SELECT * FROM ${2} WHERE name != 'default';"
            return 1
        fi
        return 0
    fi

    if [ -n "$(sqlite3 "${1}" "SELECT * FROM ${2};")" ]; then
        echo "DB table ${2} is not empty, content:"
        sqlite3 "${1}" "SELECT * FROM ${2};"
        return 1
    fi
}