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

« back to all changes in this revision

Viewing changes to scripts/seed-report

  • Committer: Steve Beattie
  • Date: 2019-02-19 06:18:27 UTC
  • Revision ID: sbeattie@ubuntu.com-20190219061827-oh57fzcfc1u9dlfk
The ubuntu-cve-tracker project has been converted to git.

Please use 'git clone https://git.launchpad.net/ubuntu-cve-tracker' to
get the converted tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
# Copyright 2009-2015 Canonical, Ltd
3
 
# Author: Kees Cook, Jamie Strandboge
4
 
# License: GPLv3
5
 
# Reports source packages in a given seed.
6
 
#
7
 
# DAPPER_EXCLUDE="--src-exclude xorg"
8
 
# HARDY_EXCLUDE="--src-exclude xorg"
9
 
# LUCID_EXCLUDE="--src-exclude xorg,libsdl1.2,pulseaudio,libsndfile,libogg,libvorbis,hal,hal-info"
10
 
#
11
 
# RELEASE=lucid
12
 
# EXCLUDE="$LUCID_EXCLUDE"
13
 
#
14
 
# ### initial setup for a given release
15
 
# sudo apt-get install -y germinate
16
 
# cd /scratch/ubuntu
17
 
# mkdir seeds
18
 
# cd seeds
19
 
# bzr co lp:~ubuntu-core-dev/ubuntu-seeds/ubuntu.$RELEASE
20
 
# bzr co lp:~ubuntu-core-dev/ubuntu-seeds/platform.$RELEASE
21
 
# mkdir -p germinate-output/ubuntu.$RELEASE
22
 
#
23
 
# ### seed output and supported source package generation
24
 
# cd /scratch/ubuntu/seeds/germinate-output-adjusted/ubuntu.$RELEASE/
25
 
# rm -rf *
26
 
# germinate -S file:///scratch/ubuntu/seeds/ -s ubuntu.$RELEASE -m http://us.archive.ubuntu.com/ubuntu/ -d $RELEASE,$RELEASE-updates,$RELEASE-security -a i386 -c main,universe,restricted,multiverse
27
 
# $UCT/scripts/seed-report --debug --release $RELEASE --seed-uri file:///scratch/ubuntu/seeds --germinate-uri file:///scratch/ubuntu/seeds/germinate-output-adjusted $EXCLUDE supported-server,server-ship > /tmp/supported.srcs2
28
 
# diff -u /tmp/supported.srcs /tmp/supported.srcs2
29
 
# cp /tmp/supported.srcs2 /tmp/supported.srcs
30
 
# ### modify seeds and repeat if needed
31
 
#
32
 
# ### how to search details for doing a seed modify...
33
 
# cd /scratch/ubuntu/seeds/germinate-output-adjusted/ubuntu.$RELEASE/rdepends
34
 
# ### for each unwanted source, cd to $SOURCE/ and check seeds:
35
 
# grep ' seed' * | egrep -v '(Desktop|Extra|Education|Documentation|Dvd|Mobile)'
36
 
# cd /scratch/ubuntu/seeds/ubuntu.$RELEASE
37
 
# ### re-arrange seeds
38
 
#
39
 
# ###  specifying a different flavor
40
 
# germinate -S file:///scratch/ubuntu/seeds/ -s ubuntu-core.$RELEASE -m http://us.archive.ubuntu.com/ubuntu -d $RELEASE -a i386 -c main,restricted,universe,multiverse
41
 
# $UCT/scripts/seed-report --debug --release $RELEASE --flavor ubuntu-core
42
 
# --seed-uri file:///scratch/ubuntu/seeds --germinate-uri
43
 
# file:///scratch/ubuntu/seeds/germinate-output-adjusted $EXCLUDE standard >
44
 
# /tmp/supported-core.srcs
45
 
#
46
 
# Useful information
47
 
# FLAVOR        RELEASE                 SEED
48
 
# ubuntu        trusty                  live,server,server-ship,supported
49
 
# ubuntu        trusty                  minimal (original Ubuntu Core)
50
 
# ubuntu        utopic                  live,server,server-ship,supported
51
 
# ubuntu-core   utopic                  minimal
52
 
# ubuntu-core   vivid                   system-image
53
 
# ubuntu-touch  trusty-vivid            touch
54
 
# Handy options:
55
 
# * Everything on the server CD
56
 
#   --flavor ubuntu --release <release> server-ship
57
 
# * Everything in the default install (excluded seeds may need to be updated)
58
 
#   --flavor ubuntu --release trusty server-ship dns-server,lamp-server,print-server,samba-server,postgresql-server,mail-server,tomcat-server,virt-host
59
 
# * Everything in the default install plus openssh-server
60
 
#   --flavor ubuntu --release trusty server-ship dns-server,lamp-server,print-server,samba-server,postgresql-server,mail-server,tomcat-server,virt-host,openssh-server
61
 
#
62
 
import sys, os
63
 
import optparse
64
 
import urllib2
65
 
 
66
 
default_release = 'dapper'
67
 
default_flavor = 'ubuntu'
68
 
default_seed_uri = 'http://people.canonical.com/~ubuntu-archive/seeds'
69
 
default_germinate_uri = 'http://people.canonical.com/~ubuntu-archive/germinate-output'
70
 
 
71
 
parser = optparse.OptionParser('''%prog [OPTIONS] seed-wanted [seed-excluded]
72
 
Eg:
73
 
 
74
 
# See all source packages on server CD for trusty
75
 
$ seed-report ... --release trusty server-ship
76
 
 
77
 
# See all source packages in default install + openssh on trusty (server-ship
78
 
# excluding all optional package sets except openssh-server)
79
 
$ seed-report ... --release trusty server-ship dns-server,lamp-server,print-server,samba-server,postgresql-server,mail-server,tomcat-server,virt-host
80
 
 
81
 
Note: specified seeds to exclude do not recurse
82
 
''')
83
 
parser.add_option("--binaries", help="Show binary packages instead of source packages", action='store_true')
84
 
parser.add_option("--debug", help="Show debugging details", action='store_true')
85
 
parser.add_option("--release", help="Which release to examine (default: %s)" % (default_release), action='store', default=default_release)
86
 
parser.add_option("--flavor", help="Which flavor to examine (default: %s)" % (default_flavor), action='store', default=default_flavor)
87
 
parser.add_option("--src-exclude", help="Exclude a specific source package from the report", action='store')
88
 
parser.add_option("--seed-uri", help="Where to load seed STRUCTURE from (default: %s)" % (default_seed_uri), action='store', metavar="URI", default=default_seed_uri)
89
 
parser.add_option("--germinate-uri", help="Where to load germinate output from (default: %s)" % (default_germinate_uri), action='store', metavar="URI", default=default_germinate_uri)
90
 
(opt, args) = parser.parse_args()
91
 
 
92
 
if len(args)<1:
93
 
    parser.print_help()
94
 
    sys.exit(1)
95
 
 
96
 
wanted = args[0]
97
 
try:
98
 
    excluded = args[1].split(',')
99
 
except:
100
 
    excluded = []
101
 
 
102
 
if opt.src_exclude:
103
 
    opt.src_exclude = opt.src_exclude.split(',')
104
 
 
105
 
def load_structure(structure, path):
106
 
    for line in urllib2.urlopen(os.path.join(path,"STRUCTURE")):
107
 
        line = line.strip()
108
 
        if line.startswith('#'):
109
 
            continue
110
 
        elif line.startswith('include '):
111
 
            load_structure(structure, os.path.join(os.path.dirname(path),line.split(' ',1)[1]))
112
 
        elif line.startswith('feature '):
113
 
            pass
114
 
        else:
115
 
            try:
116
 
                name, values = line.split(':',1)
117
 
            except:
118
 
                print >>sys.stderr, "Failed to process '%s'" % (line)
119
 
                raise
120
 
            name = name.strip()
121
 
            seeds.add(name)
122
 
            structure.setdefault(name, [])
123
 
            for item in values.strip().split():
124
 
                structure[name].append(item)
125
 
                seeds.add(item)
126
 
 
127
 
def get_germinate(seed_name, depth=0, skip=[], recurse=True):
128
 
    def read_seed_file(fn):
129
 
        listening = 0
130
 
        for line in urllib2.urlopen(fn):
131
 
            if line.startswith('-'):
132
 
                if listening:
133
 
                    break
134
 
                listening = 1
135
 
                continue
136
 
            if listening:
137
 
                bin, src, otherstuff = line.split('|',2)
138
 
                bin = bin.strip()
139
 
                src = src.strip()
140
 
 
141
 
                if opt.src_exclude and src in opt.src_exclude:
142
 
                    if opt.debug:
143
 
                        print >>sys.stderr, 'excluded src %s (binary %s)' % (src, bin)
144
 
                    continue
145
 
 
146
 
                bins.add(bin)
147
 
                srcs.add(src)
148
 
 
149
 
    bins = set()
150
 
    srcs = set()
151
 
 
152
 
    if seed_name in skip:
153
 
        if opt.debug:
154
 
            print >>sys.stderr, 'skipped seed %s' % (seed_name)
155
 
        return bins, srcs
156
 
 
157
 
    if opt.debug:
158
 
        print >>sys.stderr, "%swant '%s'" % ("  " * depth, seed_name)
159
 
    if seed_name not in loaded:
160
 
        filename = '%s/%s.%s/%s' % (opt.germinate_uri, opt.flavor, opt.release, seed_name)
161
 
        if opt.debug:
162
 
            print >>sys.stderr, "%s reading '%s'" % ("  " * depth, seed_name)
163
 
        read_seed_file(filename)
164
 
        loaded.add(seed_name)
165
 
 
166
 
    if recurse:
167
 
        for seed in structure[seed_name]:
168
 
            if seed in loaded:
169
 
                continue
170
 
            recursive_bins, recursive_srcs = get_germinate(seed, depth+1)
171
 
            bins = bins.union(recursive_bins)
172
 
            srcs = srcs.union(recursive_srcs)
173
 
 
174
 
    return bins, srcs
175
 
 
176
 
# Track which seeds we've already fetched
177
 
seeds = set()
178
 
structure = dict()
179
 
load_structure(structure, '%s/%s.%s' % (opt.seed_uri, opt.flavor, opt.release))
180
 
 
181
 
loaded = set()
182
 
 
183
 
wanted_bins = set()
184
 
wanted_srcs = set()
185
 
for seed in wanted.split(','):
186
 
    bins, srcs = get_germinate(seed)
187
 
    wanted_bins = wanted_bins.union(bins)
188
 
    wanted_srcs = wanted_srcs.union(srcs)
189
 
 
190
 
loaded = set()
191
 
 
192
 
excluded_bins = set()
193
 
excluded_srcs = set()
194
 
for exclude in excluded:
195
 
    bins, srcs = get_germinate(exclude, recurse=False)
196
 
    excluded_bins = excluded_bins.union(bins)
197
 
    excluded_srcs = excluded_srcs.union(srcs)
198
 
    if opt.debug:
199
 
        for src in excluded_srcs:
200
 
            print >>sys.stderr, '\texcluded src %s (from %s)' % (src, exclude)
201
 
        for bin in excluded_bins:
202
 
            print >>sys.stderr, '\texcluded bin %s (from %s)' % (bin, exclude)
203
 
 
204
 
out_bins = wanted_bins.difference(excluded_bins)
205
 
out_srcs = wanted_srcs.difference(excluded_srcs)
206
 
if opt.binaries:
207
 
    for bin in sorted(out_bins):
208
 
        print bin
209
 
else:
210
 
    for src in sorted(out_srcs):
211
 
        print src