Example #1
0
def initramfs(temproot, extract, to, verbose):
    """
    Extract user initramfs

    @return: bool
    """
    # copy initramfs to /usr/src/linux/usr/initramfs_data.cpio.gz, should we care?
    print green(' * ') + turquoise('initramfs.extract.initramfs ') + 'to ' + to

    # clean previous root
    if os.path.isdir(to):
        from time import strftime
        os.system('mv %s %s-%s ' % (to, to, strftime("%Y-%m-%d-%H-%M-%S")))
    process('mkdir -p %s' % to, verbose)

    # create dir if needed
    if not os.path.isdir(to):
        os.makedirs(to)

    process('cp %s %s/initramfs_data.cpio.gz' % (extract, to), verbose)

    # extract gzip archive
    process('gzip -d -f %s/initramfs_data.cpio.gz' % to, verbose)

    # extract cpio archive
    os.chdir(to)
    os.system('cpio -id < initramfs_data.cpio &>/dev/null')
    os.system('rm initramfs_data.cpio')
Example #2
0
    def import_user_initramfs(self, initramfs_from_cli_or_config):
        """
        Import user initramfs into the kernel

        @return: bool
        """
        kinitramfsdir = self.temp['initramfs']

        # copy initramfs to /usr/src/linux/usr/initramfs_data.cpio.gz, should we care?
        print green(' * ') + turquoise('kernel.import_user_initramfs ') + initramfs_from_cli_or_config
        process('cp %s %s/usr/initramfs_data.cpio.gz' % (initramfs_from_cli_or_config, self.kerneldir), self.verbose)

        # extract gzip archive
        process('gzip -d -f %s/usr/initramfs_data.cpio.gz' % self.kerneldir, self.verbose)

        # clean previous root
        if os.path.isdir(kinitramfsdir):
            from time import strftime
            os.system('mv %s %s-%s ' % (kinitramfsdir, kinitramfsdir, str(strftime("%Y-%m-%d-%H-%M-%S"))))
        process('mkdir -p %s' % kinitramfsdir, self.verbose)

        # copy initramfs to /usr/src/initramfs/
        os.system('cp %s/usr/initramfs_data.cpio %s ' % (self.kerneldir, kinitramfsdir))

        # extract cpio archive
        self.chgdir(kinitramfsdir)
        os.system('cpio -id < initramfs_data.cpio &>/dev/null')
        os.system('rm initramfs_data.cpio')
Example #3
0
    def add_option(self, option):
        """
        Add kernel config option to dotconfig

        @return: bool
        """
        found, option = self.search_option(option)
        if found[1] is '':
            # FIXME check if option is y if yes don't use "" if option arg is string use "" as is
            if file(self.kerneldir+'/.config', 'a').writelines(option[0]+'="'+option[1] + '"'+'\n'):
#            if file(self.kerneldir+'/.config', 'a').writelines(option[0]+'='+option[1] + ''+'\n'):
                print green(' * ') + turquoise('kernel.add_option ') + option + ' to ' + self.kerneldir + '/.config'

                return True
   
        print green(' * ') + turquoise('kernel.add_option ') + option[0] + ' already set'

        return False
Example #4
0
    def remove_option(self, option):
        """
        Remove kernel config option from dotconfig

        @return: bool
        """
        print green(' * ') + turquoise('kernel.remove_option ') + option + ' from ' + self.kerneldir + '/.config'
        os.system('grep -v %s %s > %s' % (option, self.kerneldir+'/.config', self.kerneldir+'/.config.kigen.temp'))

        return os.system('mv %s %s' % (self.kerneldir+'/.config.kigen.temp', self.kerneldir+'/.config'))
Example #5
0
    def make_defconfig(self):
        """
        Kernel command interface for defconfig
        
        @return: bool
        """
        print(green(' * ') + turquoise('kernel.defconfig '))
        self.chgdir(self.kerneldir)
        command = self.build_command('defconfig', self.quiet)

        return os.system(command)
Example #6
0
    def make_menuconfig(self):
        """
        Kernel command interface for menuconfig
        
        @return: bool
        """
        print green(' * ') + turquoise('kernel.menuconfig ') + self.KV
        self.chgdir(self.kerneldir)
        command = self.build_command('menuconfig', '')

        return os.system(command)
Example #7
0
def print_usage():
    print
    print '  a '+white('Portage')+' kernel|initramfs generator'
    print
    print 'Usage'+':'
    print '      '+white(sys.argv[0])+' <'+green('options')+'|'+turquoise('target')+'>'+' ['+turquoise('parameters')+']'
    print
    print green('Options') + ':'
    print '  --help, -h                 This and examples'
    print '  --nocolor, -n              Do not colorize output'
    print '  --version                  Version'
    print '  --credits                  Credits and license'
    print
    print turquoise('Targets')+':'
    print '  kernel, k                  Build kernel/modules'
    print '  initramfs, i               Build initramfs'
    print
    print turquoise('Parameters')+':'
    print ' '+os.path.basename(sys.argv[0])+' kernel'+'                --help, -h'
    print ' '+os.path.basename(sys.argv[0])+' initramfs'+'             --help, -h'
Example #8
0
    def make_modules_install(self):
        """
        Kernel command interface for modules_install 
        
        @return: bool
        """
        if self.fakeroot[len(self.fakeroot)-1] == '/':
            print(green(' * ') + turquoise('kernel.modules_install ') + self.fakeroot + 'lib/modules')
        else:
            print(green(' * ') + turquoise('kernel.modules_install ') + self.fakeroot + '/lib/modules')
        self.chgdir(self.kerneldir)
        
        # export INSTALL_MOD_PATH 
        os.environ['INSTALL_MOD_PATH'] = self.fakeroot
    
        command = self.build_command('modules_install', self.quiet)
        if self.quiet is '':
            print(command)

        return os.system(command)
Example #9
0
    def make_prepare(self):
        """
        Kernel command interface for prepare
        
        @return: bool
        """
        print(green(' * ') + turquoise('kernel.prepare '))
        self.chgdir(self.kerneldir)
        command = self.build_command('prepare', self.quiet)
        if self.quiet is '':
            print(command)

        return os.system(command)
Example #10
0
    def make_mrproper(self):
        """
        Kernel command interface for mrproper
        
        @return: bool
        """
        print(green(' * ') + turquoise('kernel.mrproper '))
        self.chgdir(self.kerneldir)
        command = self.build_command('mrproper', self.quiet)
        if self.quiet is '':
            print(command)

        return os.system(command)
Example #11
0
def getdotconfig(binary, kerneldir, verbose):

    print green(' * ')+turquoise('kernel.extract.getdotconfig ')+'from '+binary+' to /var/tmp/kigen/dotconfig'

    if not os.path.isfile(kerneldir+'/scripts/extract-ikconfig'):
        print 'err: kernel sources not found'
        sys.exit(2)

    if os.path.isfile('/var/tmp/kigen/dotconfig'):
        from time import strftime
        os.system('mv %s %s-%s ' % ('/var/tmp/kigen/dotconfig', '/var/tmp/kigen/dotconfig', strftime("%Y-%m-%d-%H-%M-%S")))

    os.system('%s %s > /var/tmp/kigen/dotconfig &>/dev/null' % (kerneldir+'/scripts/extract-ikconfig', binary))
Example #12
0
def getdotconfig(binary, kerneldir, libdir, verbose):

    print(green(' * ')+turquoise('tool.extract.kernel.getdotconfig ')+'from '+binary+' to /var/tmp/kigen/dotconfig')

    if not os.path.isfile(binary):
        print(red('error')+': '+binary+' is not a file!')
        sys.exit(2)

    if os.path.isfile('/var/tmp/kigen/dotconfig'):
        from time import strftime
        os.system('mv %s %s-%s ' % ('/var/tmp/kigen/dotconfig', '/var/tmp/kigen/dotconfig', strftime("%Y-%m-%d-%H-%M-%S")))

    os.system('sh %s %s > /var/tmp/kigen/dotconfig 2>/dev/null' % (libdir+'/tools/extract-ikconfig', binary))
Example #13
0
    def make_modules(self):
        """
        Kernel command interface for modules
        
        @return: bool
        """
        print green(' * ') + turquoise('kernel.modules ') + self.KV
        self.chgdir(self.kerneldir)
        command = self.build_command('modules', self.quiet)
        if self.quiet is '':
            print command

        return os.system(command)
Example #14
0
def print_usage():
    print()
    print('  a '+stdout.white('Portage')+' kernel|initramfs generator')
    print()
    print('Usage'+':')
    print('      '+stdout.white(sys.argv[0])+' <'+stdout.green('options')+'|'+stdout.turquoise('target')+'>'+' ['+stdout.turquoise('parameters')+']')
    print()
    print(stdout.green('Options') + ':')
    print('  --help, -h                 This and examples')
    print('  --nocolor, -n              Do not colorize output')
    print('  --version                  Version')
    print('  --credits                  Credits and license')
    print()
    print(stdout.turquoise('Targets')+':')
    print('  kernel, k                  Build kernel/modules')
    print('  initramfs, i               Build initramfs')
    print('  tool, t                    Handy tools')
    print()
    print(stdout.turquoise('Parameters')+':')
    print(' '+os.path.basename(sys.argv[0])+' kernel'+'                --help, -h')
    print(' '+os.path.basename(sys.argv[0])+' initramfs'+'             --help, -h')
    print(' '+os.path.basename(sys.argv[0])+' tool'+'                  --help, -h')
Example #15
0
    def make_clean(self):
        """
        Kernel command interface for clean
        
        @return: bool
        """
        print green(' * ') + turquoise('kernel.clean ') + self.KV
        self.chgdir(self.kerneldir)
        command = self.build_command('clean', self.quiet)
        if self.quiet is '':
            print command

        return os.system(command)
Example #16
0
    def make_bzImage(self):
        """
        Kernel command interface for bzImage
        
        @return: bool
        """
        print green(' * ') + turquoise('kernel.bzImage ') + self.KV
        self.chgdir(self.kerneldir)
        command = self.build_command('bzImage', self.quiet)
        if self.quiet is '':
            print command

        return os.system(command)
Example #17
0
    def make_oldconfig(self):
        """
        Kernel command interface for oldconfig
        
        @return: bool
        """
        print green(' * ') + turquoise('kernel.oldconfig ') + self.KV
        self.chgdir(self.kerneldir)
        command = self.build_command('oldconfig', '')
        if self.quiet is '':
            print command

        return os.system(command)
Example #18
0
 def copy_config(self, source, dest): #, self.dotconfig, self.kerneldir + '/.config', self.quiet):
     """
     Copy kernel .config file to kerneldir 
     (/usr/src/linux by default)
 
     @arg: string
     @arg: string
     @return: none
     """
     cpv = ''
     if self.quiet is '': cpv = '-v'
     print green(' * ') + turquoise('kernel.copy_config') + ' ' + source + ' -> ' + dest
     if os.path.isfile(source):
         return os.system('cp %s %s %s' % (cpv, source, dest))
     else:
         print red('error: ') + source + " doesn't exist."
         sys.exit(2)
Example #19
0
    def make_oldconfig(self):
        """
        Kernel command interface for oldconfig
        
        @return: bool
        """
        print(green(' * ') + turquoise('kernel.oldconfig '))
        self.chgdir(self.kerneldir)
#        command = self.build_command('oldconfig', '')
        if self.verbose['set'] is True:
            command = 'yes "" 2>/dev/null | ' + self.build_command('oldconfig', '')
            command = command + '; test ${PIPESTATUS[1]} -eq 0'
        else:
            command = 'yes "" 2>/dev/null | ' + self.build_command('oldconfig', self.quiet)
        if self.quiet is '':
            print(command)

        return os.system(command)
Example #20
0
def initramfs(temproot, compress, into, verbose):
    """
    Compress user initramfs

    @return: bool
    """
    print green(' * ')+turquoise('initramfs.compress.initramfs ')+'from '+compress+' into '+into

    if os.path.isfile(into):
        from time import strftime
        os.system('mv %s %s-%s ' % (into, into, strftime("%Y-%m-%d-%H-%M-%S")))

    if not os.path.isdir(os.path.dirname(into)):
        os.makedirs(os.path.dirname(into))

    process_pipe('echo | cpio --quiet -o -H newc -F %s/initramfs_data.cpio' % os.path.dirname(into), verbose)
    os.chdir(compress)
    process_pipe('find . -print | cpio --quiet -o -H newc --append -F %s/initramfs_data.cpio' % os.path.dirname(into), verbose) 
    process('gzip %s/initramfs_data.cpio' % os.path.dirname(into), verbose)
    process('mv %s/initramfs_data.cpio.gz %s' % (os.path.dirname(into), into), verbose)
Example #21
0
def initramfs(temproot, extract, to, verbose):
    """
    Extract user initramfs

    @return: bool
    """
    # copy initramfs to /usr/src/linux/usr/initramfs_data.cpio.gz, should we care?
    print(green(' * ') + turquoise('tool.extract.initramfs ') + 'to ' + to)

    # clean previous root
    if os.path.isdir(to):
        from time import strftime
        os.system('mv %s %s-%s ' % (to, to, strftime("%Y-%m-%d-%H-%M-%S")))
    else:
        process('mkdir -p %s' % to, verbose)

    # create dir if needed
    if not os.path.isdir(to):
        os.makedirs(to)

    # check if binary is gzip or xz format
    ret = gziporxz(extract, verbose)
    if ret is ':(':
        print(red('error') + ': don\'t know the format of %s' % extract)

    if ret is 'gzip':
        process('cp %s %s/initramfs_data.cpio.gz' % (extract, to), verbose)
        # extract gzip archive
        process('gzip -d -f %s/initramfs_data.cpio.gz' % to, verbose)

    elif ret is 'xz':
        process('cp %s %s/initramfs_data.cpio.xz' % (extract, to), verbose)
        process('unxz %s/initramfs_data.cpio.xz' % to, verbose)

    # extract cpio archive
    os.chdir(to)
    os.system('cpio -id < initramfs_data.cpio 2>/dev/null')
    os.system('rm initramfs_data.cpio')
Example #22
0
 def enable_dotconfig_initramfs(self):
     kinitramfsdir = self.temp['initramfs']
     print green(' * ') + turquoise('kernel.enable_dotconfig_initramfs ') + 'CONFIG_INITRAMFS_SOURCE="'+kinitramfsdir+'"'
     # FIXME or not? actually let make oldconfig deal with it
     # this sets possible twice CONFIG_INITRAMFS_SOURCE= which oldconfig can cleanup
     file(self.kerneldir + '/.config', 'a').writelines('CONFIG_INITRAMFS_SOURCE="'+kinitramfsdir+'"\n')
Example #23
0
    def remove_dotconfig_initramfs(self):
        print green(' * ') + turquoise('kernel.remove_dotconfig_initramfs ') + 'INITRAMFS'
        # FIXME this one bugs
#        process_redir('grep -v INITRAMFS %s > %s'% (self.kerneldir + '/.config', self.kerneldir + '/.config.kigen.temp'), self.verbose)
        os.system('grep -v CONFIG_INITRAMFS_SOURCE %s > %s' % (self.kerneldir + '/.config', self.kerneldir + '/.config.kigen.temp'))
        process('mv %s %s' % (self.kerneldir + '/.config.kigen.temp',  self.kerneldir + '/.config'), self.verbose)