3 import urllib, sys, optparse, re, subprocess
5 kernel_pkg_re = re.compile('^linux-(generic|firmware|headers|image|backports|ec2|source|virtual|preempt)')
6 no_remove_re = re.compile('^bcmwl-|^dkms|^grub|^xserver-xorg-video-intel|bootchart|^openssh-client')
7 no_install_re = re.compile('^ubiquity|^casper|debian-install|^cryptsetup|^dmsetup|^ecryptfs-utils|^parted|^redboot-tools|^tasksel|^aptitude|^os-prober|^devio')
12 Return (options, manifest) tuple.
15 optparser = optparse.OptionParser('''%prog [options] <manifest>
17 Install/remove packages according to a CD build manifest.
18 <manifest> can be a local file or URL.''')
19 optparser.add_option('-k', '--keep-kernel',
20 help='Do not change kernel packages', action='store_true',
21 dest='keep_kernel', default=False)
22 options, args = optparser.parse_args()
25 optparser.error('You need to specify exactly one manifest argument, see --help')
28 return (options, args[0])
34 (options, manifest) = parse_argv()
37 for l in urllib.urlopen(manifest):
39 if options.keep_kernel and kernel_pkg_re.match(pkg):
41 if no_install_re.search(pkg):
43 selection += '%s\tinstall\n' % pkg
45 # add local kernel packages on --keep-kernel
46 dpkg = subprocess.Popen(['dpkg', '--get-selections'],
47 stdout=subprocess.PIPE)
49 pkg, status = l.split()
50 if status != 'install':
52 if options.keep_kernel and kernel_pkg_re.match(pkg):
53 selection += '%s\tinstall\n' % pkg
54 if no_remove_re.search(pkg):
55 selection += '%s\tinstall\n' % pkg
57 # now apply the new selections
58 assert subprocess.call(['dpkg', '--clear-selections']) == 0
59 dpkg = subprocess.Popen(['dpkg', '--set-selections'], stdin=subprocess.PIPE)
60 dpkg.communicate(selection)
61 assert dpkg.returncode == 0
64 subprocess.call(['apt-get', 'dselect-upgrade'])