]> piware.de Git - bin.git/blob - install-manifest
postinst-setup: bump postgresql version
[bin.git] / install-manifest
1 #!/usr/bin/python
2
3 import urllib, sys, optparse, re, subprocess
4
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')
8
9 def parse_argv():
10     '''Parse CLI options.
11
12     Return (options, manifest) tuple.
13     '''
14
15     optparser = optparse.OptionParser('''%prog [options] <manifest>
16
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()
23
24     if len(args) != 1:
25         optparser.error('You need to specify exactly one manifest argument, see --help')
26         sys.exit(1)
27
28     return (options, args[0])
29
30 #
31 # main
32 #
33
34 (options, manifest) = parse_argv()
35
36 selection = ''
37 for l in urllib.urlopen(manifest):
38     pkg = l.split()[0]
39     if options.keep_kernel and kernel_pkg_re.match(pkg):
40         continue
41     if no_install_re.search(pkg):
42         continue
43     selection += '%s\tinstall\n' % pkg
44
45 # add local kernel packages on --keep-kernel
46 dpkg = subprocess.Popen(['dpkg', '--get-selections'],
47         stdout=subprocess.PIPE)
48 for l in dpkg.stdout:
49     pkg, status = l.split()
50     if status != 'install':
51         continue
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
56
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
62
63 # commit!
64 subprocess.call(['apt-get', 'dselect-upgrade'])