3 # Wrapper for Debian Security team
4 # Copyright (C) 2002, 2003, 2004, 2006 James Troup <james@nocrew.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 ################################################################################
23 # <aj> neuro: <usual question>?
24 # <neuro> aj: PPG: the movie! july 3!
26 # <aj> (you think you can distract me, and you're right)
31 ################################################################################
33 import commands, os, pwd, re, sys, time
38 ################################################################################
44 re_taint_free = re.compile(r"^['/;\-\+\.\s\w]+$")
46 ################################################################################
48 def usage (exit_code=0):
49 print """Usage: dak security-install ADV_NUMBER CHANGES_FILE[...]
50 Install CHANGES_FILE(s) as security advisory ADV_NUMBER
52 -h, --help show this help and exit
53 -n, --no-action don't do anything
58 ################################################################################
60 def do_upload(changes_files):
63 component_mapping = {}
64 for component in Cnf.SubTree("Security-Install::ComponentMappings").List():
65 component_mapping[component] = Cnf["Security-Install::ComponentMappings::%s" % (component)]
66 uploads = {}; # uploads[uri] = file_list
67 changesfiles = {}; # changesfiles[uri] = file_list
68 package_list = {} # package_list[source_name][version]
69 changes_files.sort(daklib.utils.changes_compare)
70 for changes_file in changes_files:
71 changes_file = daklib.utils.validate_changes_file_arg(changes_file)
77 # Parse the .dak file for the .changes file
78 Upload.pkg.changes_file = changes_file
80 files = Upload.pkg.files
81 changes = Upload.pkg.changes
83 # We have the changes, now return if its amd64, to not upload them to ftp-master
84 if changes["architecture"].has_key("amd64"):
85 print "Not uploading amd64 part to ftp-master\n"
87 if changes["distribution"].has_key("oldstable"):
88 print "Not uploading oldstable-security changes to ftp-master\n"
90 # Build the file list for this .changes file
91 for file in files.keys():
92 poolname = os.path.join(Cnf["Dir::Root"], Cnf["Dir::PoolRoot"],
93 daklib.utils.poolify(changes["source"], files[file]["component"]),
95 file_list.append(poolname)
96 orig_component = files[file].get("original component", files[file]["component"])
97 components[orig_component] = ""
98 # Determine the upload uri for this .changes file
99 for component in components.keys():
100 upload_uri = component_mapping.get(component)
102 upload_uris[upload_uri] = ""
103 num_upload_uris = len(upload_uris.keys())
104 if num_upload_uris == 0:
105 daklib.utils.fubar("%s: No valid upload URI found from components (%s)."
106 % (changes_file, ", ".join(components.keys())))
107 elif num_upload_uris > 1:
108 daklib.utils.fubar("%s: more than one upload URI (%s) from components (%s)."
109 % (changes_file, ", ".join(upload_uris.keys()),
110 ", ".join(components.keys())))
111 upload_uri = upload_uris.keys()[0]
112 # Update the file list for the upload uri
113 if not uploads.has_key(upload_uri):
114 uploads[upload_uri] = []
115 uploads[upload_uri].extend(file_list)
116 # Update the changes list for the upload uri
117 if not changesfiles.has_key(upload_uri):
118 changesfiles[upload_uri] = []
119 changesfiles[upload_uri].append(changes_file)
120 # Remember the suites and source name/version
121 for suite in changes["distribution"].keys():
123 # Remember the source name and version
124 if changes["architecture"].has_key("source") and \
125 changes["distribution"].has_key("testing"):
126 if not package_list.has_key(dsc["source"]):
127 package_list[dsc["source"]] = {}
128 package_list[dsc["source"]][dsc["version"]] = ""
130 if not Options["No-Action"]:
131 answer = yes_no("Upload to files to main archive (Y/n)?")
135 for uri in uploads.keys():
136 uploads[uri].extend(changesfiles[uri])
137 (host, path) = uri.split(":")
138 file_list = " ".join(uploads[uri])
139 print "Uploading files to %s..." % (host)
140 spawn("lftp -c 'open %s; cd %s; put %s'" % (host, path, file_list))
142 if not Options["No-Action"]:
143 filename = "%s/testing-processed" % (Cnf["Dir::Log"])
144 file = daklib.utils.open_file(filename, 'a')
145 for source in package_list.keys():
146 for version in package_list[source].keys():
147 file.write(" ".join([source, version])+'\n')
150 ######################################################################
151 # This function was originally written by aj and NIHishly merged into
152 # 'dak security-install' by me.
154 def make_advisory(advisory_nr, changes_files):
156 updated_pkgs = {}; # updated_pkgs[distro][arch][file] = {path,md5,size}
158 for arg in changes_files:
159 arg = daklib.utils.validate_changes_file_arg(arg)
160 Upload.pkg.changes_file = arg
164 src = Upload.pkg.changes["source"]
165 if src not in adv_packages:
166 adv_packages += [src]
168 suites = Upload.pkg.changes["distribution"].keys()
170 if not updated_pkgs.has_key(suite):
171 updated_pkgs[suite] = {}
173 files = Upload.pkg.files
174 for file in files.keys():
175 arch = files[file]["architecture"]
176 md5 = files[file]["md5sum"]
177 size = files[file]["size"]
178 poolname = Cnf["Dir::PoolRoot"] + \
179 daklib.utils.poolify(src, files[file]["component"])
180 if arch == "source" and file.endswith(".dsc"):
181 dscpoolname = poolname
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": poolname }
189 dsc_files = Upload.pkg.dsc_files
190 for file in dsc_files.keys():
192 if not dsc_files[file].has_key("files id"):
195 # otherwise, it's already in the pool and needs to be
197 md5 = dsc_files[file]["md5sum"]
198 size = dsc_files[file]["size"]
200 if not updated_pkgs[suite].has_key(arch):
201 updated_pkgs[suite][arch] = {}
202 updated_pkgs[suite][arch][file] = {
203 "md5": md5, "size": size,
204 "poolname": dscpoolname }
206 if os.environ.has_key("SUDO_UID"):
207 whoami = long(os.environ["SUDO_UID"])
210 whoamifull = pwd.getpwuid(whoami)
211 username = whoamifull[4].split(",")[0]
214 "__ADVISORY__": advisory_nr,
215 "__WHOAMI__": username,
216 "__DATE__": time.strftime("%B %d, %Y", time.gmtime(time.time())),
217 "__PACKAGE__": ", ".join(adv_packages),
218 "__DAK_ADDRESS__": Cnf["Dinstall::MyEmailAddress"]
221 if Cnf.has_key("Dinstall::Bcc"):
222 Subst["__BCC__"] = "Bcc: %s" % (Cnf["Dinstall::Bcc"])
225 archive = Cnf["Archive::%s::PrimaryMirror" % (daklib.utils.where_am_i())]
226 for suite in updated_pkgs.keys():
227 suite_header = "%s %s (%s)" % (Cnf["Dinstall::MyDistribution"],
228 Cnf["Suite::%s::Version" % suite], suite)
229 adv += "%s\n%s\n\n" % (suite_header, "-"*len(suite_header))
231 arches = Cnf.ValueList("Suite::%s::Architectures" % suite)
232 if "source" in arches:
233 arches.remove("source")
238 adv += " %s was released for %s.\n\n" % (
239 suite.capitalize(), daklib.utils.join_with_commas_and(arches))
241 for a in ["source", "all"] + arches:
242 if not updated_pkgs[suite].has_key(a):
246 adv += " Source archives:\n\n"
248 adv += " Architecture independent packages:\n\n"
250 adv += " %s architecture (%s)\n\n" % (a,
251 Cnf["Architectures::%s" % a])
253 for file in updated_pkgs[suite][a].keys():
254 adv += " http://%s/%s%s\n" % (
255 archive, updated_pkgs[suite][a][file]["poolname"], file)
256 adv += " Size/MD5 checksum: %8s %s\n" % (
257 updated_pkgs[suite][a][file]["size"],
258 updated_pkgs[suite][a][file]["md5"])
262 Subst["__ADVISORY_TEXT__"] = adv
264 adv = daklib.utils.TemplateSubst(Subst, Cnf["Dir::Templates"]+"/security-install.advisory")
265 if not Options["No-Action"]:
266 daklib.utils.send_mail (adv)
268 print "[<Would send template advisory mail>]"
270 ######################################################################
273 global Cnf, Upload, Options
276 Cnf = daklib.utils.get_conf()
278 Arguments = [('h', "help", "Security-Install::Options::Help"),
279 ('n', "no-action", "Security-Install::Options::No-Action")]
281 for i in [ "help", "no-action" ]:
282 Cnf["Security-Install::Options::%s" % (i)] = ""
284 arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
285 Options = Cnf.SubTree("Security-Install::Options")
286 Upload = daklib.queue.Upload(Cnf)
294 advisory_number = arguments[0]
295 changes_files = arguments[1:]
296 if advisory_number.endswith(".changes"):
297 daklib.utils.warn("first argument must be the advisory number.")
299 for file in changes_files:
300 file = daklib.utils.validate_changes_file_arg(file)
301 return (advisory_number, changes_files)
303 ######################################################################
307 answer = daklib.utils.our_raw_input(prompt+" ").lower()
308 if answer == "y" or answer == "n":
311 print "Invalid answer; please try again."
314 ######################################################################
317 if not re_taint_free.match(command):
318 daklib.utils.fubar("Invalid character in \"%s\"." % (command))
320 if Options["No-Action"]:
321 print "[%s]" % (command)
323 (result, output) = commands.getstatusoutput(command)
325 daklib.utils.fubar("Invocation of '%s' failed:\n%s\n" % (command, output), result)
327 ######################################################################
331 (advisory_number, changes_files) = init()
333 if not Options["No-Action"]:
334 print "About to install the following files: "
335 for file in changes_files:
337 answer = yes_no("Continue (Y/n)?")
341 os.chdir(Cnf["Dir::Queue::Accepted"])
342 print "Installing packages into the archive..."
343 spawn("dak process-accepted -pa %s" % (Cnf["Dir::Dak"], " ".join(changes_files)))
344 os.chdir(Cnf["Dir::Dak"])
345 print "Updating file lists for apt-ftparchive..."
346 spawn("dak make-suite-file-list")
347 print "Updating Packages and Sources files..."
348 spawn("apt-ftparchive generate %s" % (daklib.utils.which_apt_conf_file()))
349 print "Updating Release files..."
350 spawn("dak generate-releases")
352 if not Options["No-Action"]:
353 os.chdir(Cnf["Dir::Queue::Done"])
355 os.chdir(Cnf["Dir::Queue::Accepted"])
356 print "Generating template advisory..."
357 make_advisory(advisory_number, changes_files)
359 # Trigger security mirrors
360 spawn("sudo -u archvsync /home/archvsync/signal_security")
362 do_upload(changes_files)
364 ################################################################################
366 if __name__ == '__main__':
369 ################################################################################