3 # Wrapper for Debian Security team
4 # Copyright (C) 2002 James Troup <james@nocrew.org>
5 # $Id: amber,v 1.3 2002-06-08 00:15:53 troup Exp $
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 ################################################################################
24 # <aj> neuro: <usual question>?
25 # <neuro> aj: PPG: the movie! july 3!
27 # <aj> (you think you can distract me, and you're right)
32 ################################################################################
34 import commands, pwd, os, string, sys, time;
38 ################################################################################
44 ################################################################################
46 def usage (exit_code=0):
47 print """Usage: amber ADV_NUMBER CHANGES_FILE[...]
48 Install CHANGES_FILE(s) as security advisory ADV_NUMBER
50 -h, --help show this help and exit
51 -n, --no-action don't do anything
56 ################################################################################
58 def do_upload(changes_files):
61 component_mapping = {};
62 for component in Cnf.SubTree("Amber::ComponentMappings").List():
63 component_mapping[component] = Cnf["Amber::ComponentMappings::%s" % (component)];
64 uploads = {}; # uploads[uri] = file_list;
65 for changes_file in changes_files:
66 changes_file = utils.validate_changes_file_arg(changes_file);
72 # Parse the .katie file for the .changes file
73 Katie.pkg.changes_file = changes_file;
75 files = Katie.pkg.files;
76 changes = Katie.pkg.changes;
77 # Build the file list for this .changes file
78 for file in files.keys():
79 poolname = os.path.join(Cnf["Dir::Root"], Cnf["Dir::PoolRoot"],
80 utils.poolify(changes["source"], files[file]["component"]),
82 file_list.append(poolname);
83 orig_component = files[file].get("original component", files[file]["component"]);
84 components[orig_component] = "";
85 file_list.append(changes_file);
86 # Determine the upload uri for this .changes file
87 for component in components.keys():
88 upload_uri = component_mapping.get(component);
90 upload_uris[upload_uri] = "";
91 num_upload_uris = len(upload_uris.keys());
92 if num_upload_uris == 0:
93 utils.fubar("%s: No valid upload URI found from components (%s)."
94 % (changes_file, string.join(components.keys(), ", ")));
95 elif num_upload_uris > 1:
96 utils.fubar("%s: more than one upload URI (%s) from components (%s)."
97 % (changes_file, string.join(upload_uris.keys(), ", "),
98 string.join(components.keys(), ", ")));
99 upload_uri = upload_uris.keys()[0];
100 # Update the file list for the upload uri
101 if not uploads.has_key(upload_uri):
102 uploads[upload_uri] = [];
103 uploads[upload_uri].extend(file_list);
104 # Remember the suites
105 for suite in changes["distribution"].keys():
108 if len(suites.keys()) == 1 and suites.has_key("oldstable"):
109 print "Advisory only for 'oldstable'; not uploading elsewhere.";
112 if not Options["No-Action"]:
113 answer = yes_no("Upload to files to main archive (Y/n)?");
117 for uri in uploads.keys():
118 (host, path) = string.split(uri, ":");
119 file_list = string.join(uploads[uri]);
120 print "Uploading files to %s..." % (host);
121 spawn("lftp -c 'open %s; cd %s; put %s'" % (host, path, file_list));
125 ################################################################################
127 # Next two functions originally written by aj and NIHishly merged into
130 def join_with_commas_and(list):
131 if len(list) == 0: return "nothing";
132 if len(list) == 1: return list[0];
133 return string.join(list[:-1], ", ") + " and " + list[-1];
135 ######################################################################
137 def make_advisory(advisory_nr, changes_files):
139 updated_pkgs = {}; # updated_pkgs[distro][arch][file] = {path,md5,size}
141 for arg in changes_files:
142 arg = utils.validate_changes_file_arg(arg);
143 Katie.pkg.changes_file = arg;
147 src = Katie.pkg.changes["source"];
148 if src not in adv_packages:
149 adv_packages = adv_packages + [src];
151 suites = Katie.pkg.changes["distribution"].keys();
153 if not updated_pkgs.has_key(suite):
154 updated_pkgs[suite] = {};
156 files = Katie.pkg.files;
157 for file in files.keys():
158 arch = files[file]["architecture"];
159 md5 = files[file]["md5sum"];
160 size = files[file]["size"];
161 poolname = Cnf["Dir::PoolRoot"] + \
162 utils.poolify(src, files[file]["component"]);
163 if arch == "source" and file[-4:] == ".dsc":
164 dscpoolname = poolname;
166 if not updated_pkgs[suite].has_key(arch):
167 updated_pkgs[suite][arch] = {}
168 updated_pkgs[suite][arch][file] = {
169 "md5": md5, "size": size,
170 "poolname": poolname };
172 dsc_files = Katie.pkg.dsc_files;
173 for file in dsc_files.keys():
175 if not dsc_files[file].has_key("files id"):
178 # otherwise, it's already in the pool and needs to be
180 md5 = dsc_files[file]["md5sum"];
181 size = dsc_files[file]["size"];
183 if not updated_pkgs[suite].has_key(arch):
184 updated_pkgs[suite][arch] = {};
185 updated_pkgs[suite][arch][file] = {
186 "md5": md5, "size": size,
187 "poolname": dscpoolname };
189 if os.environ.has_key("SUDO_UID"):
190 whoami = string.atol(os.environ["SUDO_UID"]);
192 whoami = os.getuid();
193 whoamifull = pwd.getpwuid(whoami);
194 username = string.split(whoamifull[4], ",")[0];
197 "__ADVISORY__": advisory_nr,
198 "__WHOAMI__": username,
199 "__DATE__": time.strftime("%B %d, %Y", time.gmtime(time.time())),
200 "__PACKAGE__": string.join(adv_packages,", ")
204 archive = Cnf["Archive::%s::PrimaryMirror" % (utils.where_am_i())];
205 for suite in updated_pkgs.keys():
206 suite_header = "%s %s (%s)" % (Cnf["Dinstall::MyDistribution"],
207 Cnf["Suite::%s::Version" % suite], suite);
208 adv = adv + "%s\n%s\n\n" % (suite_header, "-"*len(suite_header));
210 arches = Cnf.ValueList("Suite::%s::Architectures" % suite);
211 if "source" in arches:
212 arches.remove("source");
214 arches.remove("all");
217 adv = adv + " %s was released for %s.\n\n" % (
218 string.capitalize(suite), join_with_commas_and(arches));
220 for a in ["source", "all"] + arches:
221 if not updated_pkgs[suite].has_key(a):
225 adv = adv + " Source archives:\n\n";
227 adv = adv + " Architecture independent packages:\n\n";
229 adv = adv + " %s architecture (%s)\n\n" % (a,
230 Cnf["Architectures::%s" % a]);
232 for file in updated_pkgs[suite][a].keys():
233 adv = adv + " http://%s/%s%s\n" % (
234 archive, updated_pkgs[suite][a][file]["poolname"], file);
235 adv = adv + " Size/MD5 checksum: %8s %s\n" % (
236 updated_pkgs[suite][a][file]["size"],
237 updated_pkgs[suite][a][file]["md5"]);
239 adv = string.rstrip(adv);
241 Subst["__ADVISORY_TEXT__"] = adv;
243 adv = utils.TemplateSubst(Subst, Cnf["Dir::Templates"]+"/amber.advisory");
244 if not Options["No-Action"]:
245 utils.send_mail (adv, "");
247 print "[<Would send template advisory mail>]";
249 ######################################################################
252 global Cnf, Katie, Options;
255 Cnf = utils.get_conf();
257 Arguments = [('h', "help", "Amber::Options::Help"),
258 ('n', "no-action", "Amber::Options::No-Action")];
260 for i in [ "help", "no-action" ]:
261 Cnf["Amber::Options::%s" % (i)] = "";
263 arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
264 Options = Cnf.SubTree("Amber::Options")
265 Katie = katie.Katie(Cnf);
273 advisory_number = arguments[0];
274 changes_files = arguments[1:];
275 if advisory_number[-8:] == ".changes":
276 utils.warn("first argument must be the advisory number.");
278 for file in changes_files:
279 file = utils.validate_changes_file_arg(file);
280 return (advisory_number, changes_files);
282 ######################################################################
286 answer = string.lower(utils.our_raw_input(prompt+" "));
287 if answer == "y" or answer == "n":
290 print "Invalid answer; please try again.";
293 ######################################################################
296 if Options["No-Action"]:
297 print "[%s]" % (command);
299 (result, output) = commands.getstatusoutput(command);
301 utils.fubar("Invocation of '%s' failed:\n%s\n" % (command, output), result);
303 ######################################################################
307 (advisory_number, changes_files) = init();
309 if not Options["No-Action"]:
310 print "About to install the following files: "
311 for file in changes_files:
312 print " %s" % (file);
313 answer = yes_no("Continue (Y/n)?");
317 os.chdir(Cnf["Dir::Queue::Accepted"]);
318 print "Installing packages into the archive...";
319 spawn("%s/katie -pa %s" % (Cnf["Dir::Katie"], string.join(changes_files)));
320 os.chdir(Cnf["Dir::Katie"]);
321 print "Updating file lists for apt-ftparchive...";
323 print "Updating Packages and Sources files...";
324 spawn("apt-ftparchive generate %s" % (utils.which_apt_conf_file()));
325 print "Updating Release files...";
328 if not Options["No-Action"]:
329 os.chdir(Cnf["Dir::Queue::Done"]);
331 os.chdir(Cnf["Dir::Queue::Accepted"]);
332 print "Generating template advisory...";
333 make_advisory(advisory_number, changes_files);
335 do_upload(changes_files);
337 ################################################################################
339 if __name__ == '__main__':
342 ################################################################################