summaryrefslogtreecommitdiff
blob: fe457b654a4f90ae1ea90c6da40e0391407835b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/python

import os, sys, shutil, time, optparse

parser = optparse.OptionParser(
    usage   = '\%prog [-sr] [-S suffix]',
    version = '0.1')

group = optparse.OptionGroup(parser, '<Main Options>')

group.add_option('-s',
                 '--replace-safe',
                 action = 'store_true',
                 help   = 'Replace the old safety kernel',
                 dest = 'replace')

group.add_option('-r',
                 '--recompile',
                 action = 'store_true',
                 help   = 'Recompile the kernel',
                 dest = 'compile')

group.add_option('-S',
                 '--Suffix',
                 help   = 'Additional kernel suffix',
                 dest = 'suffix')

parser.add_option_group(group)

# Parse the command line
(options, args) = parser.parse_args()

src_d = '/usr/src/linux'

config_d = '/home/wrobel/usr/devel/website/config/kernel/' + os.environ['HOSTNAME']

if not os.path.exists(config_d):
    os.makedirs(config_d)

boot_d = '/boot'

norm_kernel = 'kernel'
safe_kernel = 'kernel-safe'

norm_sysmap = 'System.map'
safe_sysmap = 'System.map-safe'

os.chdir(src_d)

shutil.copyfile('.config', config_d + '/kernel-config')

if options.compile:
    os.system('make && make modules_install')

suffix = '-'.join(os.path.basename(os.path.realpath(src_d)).split('-')[1:])

os.chdir(boot_d)

if os.path.exists(norm_kernel):
    norm_kernel_d = os.path.basename(os.path.realpath(norm_kernel))
    os.unlink(norm_kernel)
else:
    norm_kernel_d = 'kernel-unknown'
    
if os.path.exists(norm_sysmap):
    norm_sysmap_d = os.path.basename(os.path.realpath(norm_sysmap))
    os.unlink(norm_sysmap)
else:
    norm_sysmap_d = 'System.map-unknown'

if options.replace:
    if os.path.exists(safe_kernel):
        safe_kernel_d = os.path.realpath(safe_kernel)
        os.unlink(safe_kernel)
        if os.path.exists(safe_kernel_d):
            os.unlink(safe_kernel_d)
    
    if os.path.exists(safe_sysmap):
        safe_sysmap_d = os.path.realpath(safe_sysmap)
        os.unlink(safe_sysmap)
        if os.path.exists(safe_sysmap_d):
            os.unlink(safe_sysmap_d)

    os.symlink(norm_kernel_d, safe_kernel)
    os.symlink(norm_sysmap_d, safe_sysmap)

else:
    if os.path.exists(norm_kernel_d):
        os.unlink(norm_kernel_d)
    if os.path.exists(norm_sysmap_d):
        os.unlink(norm_sysmap_d)
    
new_kernel_d = norm_kernel + '-' + suffix
new_sysmap_d = norm_sysmap + '-' + suffix

if options.suffix:
    new_kernel_d = new_kernel_d + '-' + options.suffix
    new_sysmap_d = new_sysmap_d + '-' + options.suffix

if norm_kernel_d == new_kernel_d:
    new_kernel_d = new_kernel_d + '-' + time.strftime('%Y%m%d')
    new_sysmap_d = new_sysmap_d + '-' + time.strftime('%Y%m%d')

shutil.copyfile(src_d + '/arch/i386/boot/bzImage', new_kernel_d)
shutil.copyfile(src_d + '/System.map', new_sysmap_d)

os.symlink(new_kernel_d, norm_kernel)
os.symlink(new_sysmap_d, norm_sysmap)

print 'Do not forget to commit the kernel config changes to your repository with a useful comment!'