summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'z-distfiles/scripts-gw/kernel-recompile')
-rwxr-xr-xz-distfiles/scripts-gw/kernel-recompile111
1 files changed, 87 insertions, 24 deletions
diff --git a/z-distfiles/scripts-gw/kernel-recompile b/z-distfiles/scripts-gw/kernel-recompile
index 65632f9..da1221f 100755
--- a/z-distfiles/scripts-gw/kernel-recompile
+++ b/z-distfiles/scripts-gw/kernel-recompile
@@ -1,50 +1,113 @@
#!/usr/bin/python
-import os, sys, shutil
+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']
-os.makedirs(config_d)
-norm_kernel = '/boot/kernel'
-safe_kernel = '/boot/kernel-safe'
+if not os.path.exists(config_d):
+ os.makedirs(config_d)
-norm_sysmap = '/boot/System.map'
-safe_sysmap = '/boot/System.map-safe'
+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')
-os.system('make && make modules_install')
+if options.compile:
+ os.system('make && make modules_install')
suffix = '-'.join(os.path.basename(os.path.realpath(src_d)).split('-')[1:])
-if os.path.exists(safe_kernel):
- safe_kernel_d = os.path.realpath(safe_kernel)
- os.unlink(safe_kernel_d)
- os.unlink(safe_kernel)
-
-if os.path.exists(safe_sysmap):
- safe_sysmap_d = os.path.realpath(safe_sysmap)
- os.unlink(safe_sysmap_d)
- os.unlink(safe_sysmap)
+os.chdir(boot_d)
+if os.path.exists(norm_kernel):
+ norm_kernel_d = os.path.basename(os.path.realpath(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))
+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)
+
+if os.path.exists(norm_kernel):
+ os.unlink(norm_kernel)
+if os.path.exists(norm_kernel):
+ os.unlink(norm_sysmap)
-norm_kernel_d = os.path.realpath(norm_kernel)
-norm_sysmap_d = os.path.realpath(norm_sysmap)
+new_kernel_d = norm_kernel + '-' + suffix
+new_sysmap_d = norm_sysmap + '-' + suffix
-os.symlink(safe_kernel, norm_kernel_d)
-os.symlink(safe_sysmap, norm_sysmap_d)
+if options.suffix:
+ new_kernel_d = new_kernel_d + '-' + options.suffix
+ new_sysmap_d = new_sysmap_d + '-' + options.suffix
-new_kernel_d = 'kernel-' + suffix
-new_sysmap_d = 'System.map-' + 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(norm_kernel, new_kernel_d)
-os.symlink(norm_sysmap, 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!'