File: check-version.sh

package info (click to toggle)
systemd 259-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 105,132 kB
  • sloc: ansic: 726,480; xml: 121,118; python: 36,740; sh: 35,016; cpp: 946; makefile: 273; awk: 102; lisp: 13; sed: 1
file content (36 lines) | stat: -rwxr-xr-x 1,002 bytes parent folder | download | duplicates (9)
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
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -eu
set -o pipefail

# Note: 'grep ... >/dev/null' instead of just 'grep -q' is used intentionally
#       here, since 'grep -q' exits on the first match causing SIGPIPE being
#       sent to the sender.

BINARY="${1:?}"
VERSION="${2:?}"
export SYSTEMD_LOG_LEVEL=info

if [[ ! -x "$BINARY" ]]; then
    echo "$BINARY is not an executable"
    exit 1
fi

# --version prints something. Also catches case where args are ignored.
if ! "$BINARY" --version | grep . >/dev/null; then
    echo "$(basename "$BINARY") --version output is empty"
    exit 2
fi

# no --version output to stderr
if "$BINARY" --version 2>&1 1>/dev/null | grep .; then
    echo "$(basename "$BINARY") --version prints to stderr"
    exit 3
fi

# project version appears in version output
out="$("$BINARY" --version)"
if ! grep -F "$VERSION" >/dev/null <<<"$out"; then
    echo "$(basename "$BINARY") --version output does not match '$VERSION': $out"
    exit 4
fi