From c93a9aa81c349ab085301f21297ee3ff903347b3 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 28 Dec 2012 07:54:19 +0100 Subject: beginning for removing boot flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- bootcleanse.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) mode change 100644 => 100755 bootcleanse.py (limited to 'bootcleanse.py') diff --git a/bootcleanse.py b/bootcleanse.py old mode 100644 new mode 100755 index fa941f9..fef711e --- a/bootcleanse.py +++ b/bootcleanse.py @@ -1,11 +1,16 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +## TODO add support for bootable logical partitions + import os import sys from subprocess import Popen, PIPE +REMOVE_MBR_CODE = False +REMOVE_BOOT_FLAG = False + mbrs = [] for arg in sys.argv[1:]: @@ -30,7 +35,32 @@ while True: exit(128) print('Only ‘yes’ and ‘no’ is valid') +def dd(pipe, i, o, *extra): + cmd = ['sudo', 'dd'] + if i is not None: + cmd += ['if=%s' % i] + if o is not None: + cmd += ['of=%s' % o] + cmd += extra + ch0 = sys.stdin + ch1 = PIPE if (type(pipe) is str) or pipe else sys.stdout + ch2 = PIPE if (type(pipe) is str) or pipe else sys.stderr + if type(pipe) is str: + cmd = ['\'' + a.replace('\'', '\'\\\'\'') + '\'' for a in cmd] + cmd = ' '.join(cmd) + cmd = 'echo -e \'%s\' | %s' % (pipe, cmd) + cmd = ['sudo', 'sh', '-c', cmd] + return Popen(cmd, stdin=ch0, stdout=ch1, stderr=ch2).communicate() for mbr in mbrs: - Popen(['sudo', 'dd', 'if=/dev/zero', 'of=' + mbr, 'bs=440', 'count=1'], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate() + if REMOVE_MBR_CODE: + dd(False, '/dev/zero', mbr, 'bs=440', 'count=1') + if REMOVE_BOOT_FLAG: + p = 0 + status = dd(True, mbr, None, 'bs=1', 'count=1', 'skip=%i' % (446 + 16 * p)) + status = hex(status[0][0] & 127)[2:] + if len(status) == 1: + status = '0' + status + status = '\\x' + status + dd(status, None, mbr, 'bs=1', 'count=1', 'seek=%i' % (446 + 16 * p)) -- cgit v1.2.3-70-g09d2