aboutsummaryrefslogtreecommitdiff
path: root/scripts/validate-archive
blob: 2d1406608b02be3e3719e8208c09317f3a799839 (plain)
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/sh

set -e
set -u

fatal () {
    echo "$@" >&2
    exit 1
}

archive="$1"
shift

if ! [ -f "$archive" ]; then
    fatal "No such file: $archive"
fi


ok=0

for item in "$@"; do
    oIFS="$IFS"; IFS=':'
    set -- $item
    m="$1"
    v="$2"
    IFS="$oIFS"
    case "$m" in
        sha1|sha256|md5)
            printf "$m: $archive: "
            sum=`${m}sum "$archive" | awk '{print $1}'`
            if [ "$sum" = "$v" ]; then
                echo "OK"
            else
                echo "FAILED (got:$sum, expected:$v)"
                ok=1
            fi
        ;;
        size)
            printf "$m: $archive: "
            size=`stat -c '%s' "$archive"`
            if [ "$size" = "$v" ]; then
                echo "OK"
            else
                echo "FAILED (got:$size, expected:$v)"
                ok=1
            fi
        ;;
        *)
            fatal "Unsupported method: $m"
        ;;
    esac
done

exit $ok