~ubuntu-security/ubuntu-cve-tracker/master

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/sh
# Copyright (C) 2009-2011 Canonical, Ltd.
# Author: Jamie Strandboge <jamie@canonical.com>
# License: GPLv3

set -e

help() {
    cat <<EOM
Usage: mass-cve-edit -p <package> -r <release> -s <state> [-v <version>] CVE...

  -p    source package name (REQUIRED)
  -r    comma delineated list of Ubuntu releases (REQUIRED)
  -s    state of package (eg 'pending' or 'released') (REQUIRED)
  -v    version of source package (for use with 'pending' or 'released')
  -d    directory (eg 'retired'. Defaults to 'active')
EOM
}

rel=
pkg=
ver=
state=
dryrun="no"
dir="active"
while getopts "hnd:p:r:s:v:" opt
do
    case "$opt" in
        d) dir="$OPTARG";;
        n) dryrun="yes";;
        p) pkg="$OPTARG";;
        r) rel="$OPTARG";;
        s) state="$OPTARG";;
        v) ver="$OPTARG";;
        h) help ; exit 0;;
        ?) help;;
    esac
done
shift $((OPTIND - 1))

if [ -z "$1" ] || [ -z "$pkg" ] || [ -z "$rel" ] || [ -z "$state" ]; then
    help
    exit 1
fi

if [ "$state" = "released" ]; then
    if [ -z "$ver" ]; then
        echo "-v <version> is required with '$state'"
        exit 1
    fi
fi

sed_args="-i"
if [ "$dryrun" = "yes" ]; then
    sed_args=""
fi

state_str="$state"
if [ ! -z "$ver" ]; then
    state_str="$state_str ($ver)"
fi

for c in "$@"; do
    echo "$c... "
    if [ ! -f "$dir/$c" ]; then
        echo "skipped ($dir/$c does not exist)"
        continue
    fi
    for p in $(echo "$pkg" | sed 's/,/ /g'); do
        for r in $(echo "$rel" | sed 's/,/ /g'); do
            sed $sed_args "s#${r}_${p}: .*#${r}_${p}: $state_str#" "$dir/$c" || {
                echo "ERROR ($dir/$c not updated)"
                continue
            }
            echo "  ${r}_${p} updated"
        done
    done
done

exit 0