예제 #1
0
파일: misc.py 프로젝트: kungfoo-linux/kigen
def get_kernel_version(kerneldir):
    """
    Get the kernel version number and nickname

    @arg: string
    @return: string
    """
    # check for linux symlink
    if not os.path.isdir(kerneldir):
        print(red('error')+': no /usr/src/linux found')
        sys.exit(2)

    # best way *here* is to get KV from the sources, not the running KV
    if not os.path.isfile(kerneldir+'/Makefile'):
        # if no /Makefile, that sux big time
        print(red('error')+': no kernel Makefile found')
        sys.exit(2)
    head = []
    nlines = 0
    for line in open(kerneldir+'/Makefile'):
        line = line.replace(' ','')
        head.append(line.rstrip())
        nlines += 1
        if nlines >= 5:
            break
    head = dict(item.split("=") for item in head )

    return head['VERSION']+"."+head['PATCHLEVEL']+"."+head['SUBLEVEL']+head['EXTRAVERSION'], head['NAME']
예제 #2
0
파일: lvm2.py 프로젝트: ac1965/kigen
    def fail(self, step):
        """
        @arg step   string

        @return     exit
        """
        print red('error')+': initramfs.lvm2.'+step+'() failed'
        sys.exit(2)
예제 #3
0
파일: busybox.py 프로젝트: ac1965/kigen
    def fail(self, step):
        """
        @arg step   string

        @return     exit
        """
        print red("error") + ": initramfs.busybox." + step + "() failed"
        sys.exit(2)
예제 #4
0
파일: kernel.py 프로젝트: ac1965/kigen
    def fail(self, step):
        """
        @arg step   string

        @return     exit
        """
        print red('error')+': kernel.'+step+'() failed'
        sys.exit(2)
예제 #5
0
def build_sequence(master_config, temp, verbose):
	"""
	unionfs_fuse build sequence

	@arg master_config	dict
	@arg temp		dict
	@arg verbose		string

	@return: bool
	"""
	zero = int('0')
	ret = True

	if os.path.isfile('%s/unionfs-fuse-%s.tar.bz2' % (utils.get_distdir(temp), str(master_config['unionfs_fuse_ver']))) is not True:
		ret = download(master_config['unionfs_fuse_ver'], temp, verbose)
		if ret is not zero:
			print red('error: ')+'initramfs.unionfs_fuse.download() failed'
			sys.exit(2)

	ret = extract(master_config['unionfs_fuse_ver'], temp, verbose)
	ret = zero # grr, tar thing to not return 0

#	ret = configure(temp['work'] + '/unionfs_fuse/' + master_config['unionfs_fuse_ver'], master_config, temp, verbose)
#	if ret is not zero:
#		print red('error: ')+'initramfs.unionfs_fuse.configure() failed'
#		sys.exit(2)

	# add fuse lib path
	os.system('echo "CPPFLAGS += -static -I%s/include -L%s/lib/.libs" >> %s' % (temp['work'] + '/fuse-' + master_config['fuse_ver'], temp['work'] + '/fuse-' + master_config['fuse_ver'], temp['work'] + '/unionfs-fuse-' + master_config['unionfs_fuse_ver']+'/Makefile'))
	os.system('echo "CPPFLAGS += -static -I%s/include -L%s/lib/.libs" >> %s' % (temp['work'] + '/fuse-' + master_config['fuse_ver'], temp['work'] + '/fuse-' + master_config['fuse_ver'], temp['work'] + '/unionfs-fuse-' + master_config['unionfs_fuse_ver']+'/src/Makefile'))
	os.system('echo "LIB += -static -L%s/lib/.libs -ldl -lrt" >> %s' % (temp['work'] + '/fuse-' + master_config['fuse_ver'], temp['work'] + '/unionfs-fuse-' + master_config['unionfs_fuse_ver']+'/Makefile'))
	os.system('echo "LIB += -static -L%s/lib/.libs -ldl -lrt" >> %s' % (temp['work'] + '/fuse-' + master_config['fuse_ver'], temp['work'] + '/unionfs-fuse-' + master_config['unionfs_fuse_ver']+'/src/Makefile'))

	ret = compile(temp['work'] + '/unionfs-fuse-' + master_config['unionfs_fuse_ver'], master_config, verbose)
	if ret is not zero:
		print red('error: ')+'initramfs.unionfs_fuse.compile() failed'
		sys.exit(2)

# TODO remove manpage rm -rf %s/unionfs_fuse/man % temp['work']

	ret = strip(master_config, temp)
	if ret is not zero:
		print red('error: ')+'initramfs.unionfs_fuse.strip() failed'
		sys.exit(2)

	ret = compress(master_config, temp, verbose)
	if ret is not zero:
		print red('error: ')+'initramfs.unionfs_fuse.compress() failed'
		sys.exit(2)

	ret = cache(temp['work'] + '/unionfs-fuse-' + master_config['unionfs_fuse_ver'], master_config, temp, verbose)
	if ret is not zero:
		print red('error: ')+'initramfs.unionfs_fuse.compress() failed'

	return ret
예제 #6
0
파일: kernel.py 프로젝트: ac1965/kigen
 def chgdir(self, dir):
     """
     Change to directory
 
     @arg: string
     @return: none
     """
     if not os.path.isdir(dir):
         print red('error') + ': ' + 'cannot change dir to ' + dir
         sys.exit(2)
     if not os.getcwd() == dir:
         os.chdir(dir)
예제 #7
0
파일: fuse.py 프로젝트: kungfoo-linux/kigen
def build_sequence(master_config, temp, verbose):
	"""
	fuse build sequence

	@arg: dict
	@arg: dict
	@arg: string
	@return: bool
	"""
	zero = int('0')
	ret = True

	if os.path.isfile('%s/fuse-%s.tar.gz' % (utils.get_distdir(temp), str(master_config['fuse_ver']))) is not True:
		ret = download(master_config['fuse_ver'], temp, verbose)
		if ret is not zero:
			print(red('error: ')+'initramfs.fuse.download() failed')
			sys.exit(2)

	ret = extract(master_config['fuse_ver'], temp, verbose)
	ret = zero # grr, tar thing to not return 0 when success

	ret = configure(temp['work'] + '/fuse-' + master_config['fuse_ver'], master_config, temp, verbose)
	if ret is not zero:
		print(red('error: ')+'initramfs.fuse.configure() failed')
		sys.exit(2)

	ret = compile(temp['work'] + '/fuse-' + master_config['fuse_ver'], master_config, verbose)
	if ret is not zero:
		print(red('error: ')+'initramfs.fuse.compile() failed')
		sys.exit(2)

#	ret = install(temp['work'] + '/fuse-' + master_config['fuse_ver'], master_config, verbose)
#	if ret is not zero:
#		print red('error: ')+'initramfs.fuse.install() failed'
#		sys.exit(2)
#
#	ret = strip(master_config, temp)
#	if ret is not zero:
#		print red('error: ')+'initramfs.fuse.strip() failed'
#		sys.exit(2)
#
#	ret = compress(master_config, temp, verbose)
#	if ret is not zero:
#		print red('error: ')+'initramfs.fuse.compress() failed'
#		sys.exit(2)

	ret = cache(temp['work'] + '/fuse-' + master_config['fuse_ver'], master_config, temp, verbose)
	if ret is not zero:
		print(red('error: ')+'initramfs.fuse.compress() failed')
		sys.exit(2)

	return ret
예제 #8
0
파일: screen.py 프로젝트: r1k0/kigen
    def fail(self, step):
        """
        @arg step   string

        @return     exit
        """
        print(red("error") + ": initramfs.screen." + step + "() failed")
        sys.exit(2)
예제 #9
0
파일: splash.py 프로젝트: r1k0/kigen
    def fail(self, step):
        """
        @arg step   string

        @return     exit
        """
        print(red('error')+': initramfs.splash.'+step+'() failed')
        sys.exit(2)
예제 #10
0
파일: kernel.py 프로젝트: ac1965/kigen
 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)
예제 #11
0
    def fail(self, step):
        """
        Exit

        @arg step   string
        @return     exit
        """
        print(red('error')+': initramfs.dropbear.'+step+'() failed')
        sys.exit(2)
예제 #12
0
def build_sequence(master_config, temp, quiet):
	"""
	iscsi build sequence

	@arg: dict
	@arg: dict
	@arg: string
	@return: bool
	"""
	zero = int('0')
	ret = True

	if os.path.isfile('%s/open-iscsi-%s.tar.gz' % (utils.get_distdir(temp), str(master_config['iscsi_ver']))) is not True:
		ret = download(master_config['iscsi_ver'], temp, quiet)
		if ret is not zero:
			print(red('error: ')+'initramfs.iscsi.download() failed')
			sys.exit(2)

	ret = extract(master_config['iscsi_ver'], temp, quiet)
	ret = zero # grr, tar thing to not return 0

	ret = compile(temp['work'] + '/open-iscsi-' + master_config['iscsi_ver'], master_config, quiet)
	if ret is not zero:
		print(red('error: ')+'initramfs.iscsi.compile() failed')
		sys.exit(2)

# TODO remove manpage rm -rf %s/iscsi/man % temp['work']

	ret = strip(master_config, temp)
	if ret is not zero:
		print(red('error: ')+'initramfs.iscsi.strip() failed')
		sys.exit(2)

	ret = compress(master_config, temp, quiet)
	if ret is not zero: 
		print(red('error: ')+'initramfs.iscsi.compress() failed')
		sys.exit(2)

	ret = cache(temp['work'] + '/open-iscsi-' + master_config['iscsi_ver'], master_config, temp, quiet)
	if ret is not zero: 
		print(red('error: ')+'initramfs.iscsi.compress() failed')
		sys.exit(2)

	return ret
예제 #13
0
파일: screen.py 프로젝트: r1k0/kigen
    def chgdir(self, dir):
        """
        Change to directory

        @arg: string
        @return: none
        """
        if not os.path.isdir(dir):
            print(red("error") + ": " + "cannot change dir to " + dir)
            sys.exit(2)
        if not os.getcwd() == dir:
            os.chdir(dir)
예제 #14
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))
예제 #15
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')
예제 #16
0
파일: luks.py 프로젝트: r1k0/kigen
    def build(self):
        """
        luks build sequence

        @return: bool
        """
        zero = int('0')

        # make sure dev-libs/libgcrypt has static-libs use flag enabled
        if not pkg_has_useflag('dev-libs', 'libgcrypt', 'static-libs'):
            print(red('error')+': utils.pkg_has_useflag("dev-libs", "libgcrypt", "static-libs") failed, remerge libgcrypt with +static-libs')
            sys.exit(2)

        if os.path.isfile('%s/cryptsetup-%s.tar.bz2' % (get_distdir(self.temp), self.luks_ver)) is not True:
            print(green(' * ') + '... luks.download')
            if self.download() is not zero:
                process('rm -v %s/cryptsetup-%s.tar.bz2' % (get_distdir(self.temp), self.luks_ver), self.verbose)
                self.fail('download')

        print(green(' * ') + '... luks.extract')
        self.extract()
        # grr, tar thing to not return 0 when success

        print(green(' * ') + '... luks.configure')
        if self.configure()is not zero: self.fail('configure')

        print(green(' * ') + '... luks.make')
        if self.make() is not zero: self.fail('make')

        print(green(' * ') + '... luks.strip')
        if self.strip() is not zero: self.fail('strip')

        print(green(' * ') + '... luks.compress')
        if self.compress() is not zero: self.fail('compress')

        print(green(' * ') + '... luks.cache')
        if self.cache() is not zero: self.fail('cache')
예제 #17
0
파일: cliparser.py 프로젝트: ac1965/kigen
def cli_parser():

    target = 'none'

    cli = { 'nocache':      '',                 \
            'oldconfig':    True,               \
            'kerneldir':    kerneldir,          \
            'arch':         identify_arch()}

    verbose = { 'std':      '',     \
                'set':      False,  \
                'logfile':  '/var/log/kigen.log'}

    master_conf = {}
    kernel_conf = {}
    modules_conf = {}
    initramfs_conf = {}
    version_conf = {}

    # copy command line arguments
    cliopts = sys.argv

    # parse /etc/kigen/master.conf
    master_conf = etc_parser_master()

    # if not enough parameters exit with usage
    if len(sys.argv) < 2:
        print_usage()
        sys.exit(2)

    # set default kernel sources
    if 'kernel-sources' in master_conf:
        # if set grab value from config file
        cli['kerneldir'] = master_conf['kernel-sources']
    # else: exit

    # @@ cli['KV'] = get_kernel_version(cli['kerneldir'])
    cli['KV'] = get_kernel_utsrelease(cli['kerneldir'])

    # exit if kernel dir doesn't exist
    if not os.path.isdir(cli['kerneldir']):
        print red('error') + ': ' + cli['kerneldir'] + ' does not exist.'
        sys.exit(2)
    # exit if kernel version is not found
    if cli['KV'] is 'none':
        print red('error') + ': ' + cli['kerneldir']+'/Makefile not found'
        sys.exit(2)

    # prevent multiple targets from running
    if 'k' in cliopts and 'i' in cliopts:
        print red('error: ') + 'kigen cannot run multiple targets at once'
        print_usage()
        sys.exit(2)
    elif 'initramfs' in cliopts and 'kernel' in cliopts:
        print red('error: ') + 'kigen cannot run multiple targets at once'
        print_usage()
        sys.exit(2)
    elif 'k' in cliopts and 'initramfs' in cliopts:
        print red('error: ') + 'kigen cannot run multiple targets at once'
        print_usage()
        sys.exit(2)
    elif 'i' in cliopts and 'kernel' in cliopts:
        print red('error: ') + 'kigen cannot run multiple targets at once'
        print_usage()
        sys.exit(2)

    # === parsing for the kernel target ===
    if 'kernel' in sys.argv or 'k' in sys.argv:
        # we found the kernel target
        # parse accordingly
        if 'kernel' in sys.argv:
            target = 'kernel'
            cliopts.remove('kernel')
        if 'k' in sys.argv:
            target = 'kernel'
            cliopts.remove('k')

        # parse 
        kernel_conf = etc_parser_kernel()

        try:
            # parse command line
            opts, args = getopt(cliopts[1:], "idhn", [  \
                                    "help",                     \
                                    "info",                     \
                                    "version",                  \
                                    "credits",                  \
                                    "conf=",                    \
                                    "dotconfig=",               \
                                    "bbconf=",                  \
                                    "rename=",                  \
                                    "initramfs=",               \
                                    "mrproper",                 \
                                    "clean",                    \
                                    "menuconfig",               \
                                    "allyesconfig",             \
                                    "nomodinstall",             \
                                    "fakeroot=",                \
                                    "allnoconfig",              \
                                    "nooldconfig",              \
                                    "oldconfig",                \
                                    "logfile=",                 \
                                    "noboot",                   \
                                    "nosaveconfig",             \
                                    "hostbin",                  \
                                    "fixdotconfig=",             \
                                    "getdotconfig=",            \
                                    "debug"])
        except GetoptError, err:
            print str(err) # "option -a not recognized"
            print_usage()
            sys.exit(2)

        # this has to be taken care before quiet is initialized
        # hence the extra loop, catch --logfile before all
        cli['logfile'] = '/var/log/kigen.log'
        if master_conf['logfile'] != '':
            cli['logfile'] = master_conf['logfile']
        for o, a in opts:
            if o in ("--logfile"):
                cli['logfile'] = a
        # default
        cli['dotconfig']    = master_conf['kernel-sources']+'/.config'
        if kernel_conf['dotconfig'] != '':
            cli['dotconfig'] = kernel_conf['dotconfig']
        cli['rename']       = '/boot/kernel-kigen-'+cli['arch']+'-'+cli['KV']
        if kernel_conf['rename'] != '':
            cli['rename'] = kernel_conf['rename']
        cli['initramfs']    = ''
        cli['info']         = False
        cli['mrproper']     = False
        if kernel_conf['mrproper'] == 'True':
            cli['mrproper'] = True
        cli['menuconfig']   = False
        if kernel_conf['menuconfig'] == 'True':
            cli['menuconfig'] = True
        cli['clean']        = False
        if kernel_conf['clean'] == 'True':
            cli['clean'] = True
        cli['allyesconfig'] = False
        cli['allnoconfig']  = False
        cli['oldconfig']    = False
        if kernel_conf['nooldconfig'] == 'False':
            cli['oldconfig'] = True
        cli['nomodinstall'] = False
        if kernel_conf['nomodinstall'] == 'True':
            cli['nomodinstall'] = True
        cli['fakeroot']     = '/'
        if kernel_conf['fakeroot'] != '':
            cli['fakeroot'] = kernel_conf['fakeroot']
        cli['nocache']      = False
        cli['noboot']       = False
        if kernel_conf['noboot'] == 'True':
            cli['noboot'] = True
#       quiet               = '2>&1 | tee -a ' + logfile # verbose
#       quiet               = '>>' + logfile + ' 2>&1' # quiet + logfile
        verbose['std']      = '>>' + cli['logfile'] + ' 2>&1'
        verbose['set']      = False
        if master_conf['debug'] == 'True':
            verbose['set'] = True
            verbose['std'] = '2>&1 | tee -a ' + cli['logfile']
            verbose['logfile'] = cli['logfile']
        cli['color']        = True
        cli['nosaveconfig'] = False
        if kernel_conf['nosaveconfig'] == 'True':
            cli['nosaveconfig'] = True
#        cli['fixdotconfig'] = False
#        if kernel_conf['fixdotconfig'] == 'True':
#            cli['fixdotconfig'] = True
        cli['fixdotconfig'] = ''
        if kernel_conf['fixdotconfig'] != '':
            cli['fixdotconfig'] = kernel_conf['fixdotconfig']
        cli['getdotconfig'] = ''

        # target options
        for o, a in opts:
            if o in ("-h", "--help"):
                print_usage_kernel(cli, master_conf, kernel_conf)
                sys.exit(0)
            elif o in ("--credits"):
                print_credits()
                sys.exit(0)
            elif o in ("--version"):
                print_version()
                sys.exit(0)
            # have to declare logfile here too
            elif o in ("--logfile="):
                cli['logfile'] = a
                verbose['logfile'] = cli['logfile']
            elif o in ("-d", "--debug"):
#               quiet = '>>' + logfile + ' 2>&1' # logfile
#               quiet = '2>&1 | tee -a ' + logfile # verbose
                verbose['std'] = '2>&1 | tee -a ' + cli['logfile']
                verbose['set'] = True
                verbose['logfile'] = cli['logfile']
            elif o in ("-k", "--dotconfig"):
                cli['dotconfig'] = a
                cli['oldconfig'] = True # make sure .config is ok
            elif o in ("--rename"):
                cli['rename'] = a
            elif o in ("--initramfs"):
                cli['initramfs'] = a
            elif o in ("--mrproper"):
                cli['mrproper'] = True
            elif o in ("--menuconfig"):
                cli['menuconfig'] = True
            elif o in ("--nooldconfig"):
                cli['oldconfig'] = False
            elif o in ("--oldconfig"):
                cli['oldconfig'] = True
            elif o in ("--nomodinstall"):
                cli['nomodinstall'] = True
            elif o in ("--fakeroot"):
#                if os.path.isdir(a):
                 cli['fakeroot'] = a
#                else:
#                    print "%s is not a directory" % a
#                    sys.exit(2)
            elif o in ("--noboot"):
                cli['noboot'] = True
            elif o in ("--nosaveconfig"):
                cli['nosaveconfig'] = True
            elif o in ("--clean"):
                cli['clean'] = True
            elif o in ("--fixdotconfig"):
#                cli['fixdotconfig'] = True
                cli['fixdotconfig'] = a
            elif o in ("--getdotconfig"):
                cli['getdotconfig'] = a
            else:
                assert False, "uncaught option"
예제 #18
0
def cli_parser():

    target = ''

    cli = { 'nocache':      '',                 \
            'oldconfig':    True,               \
            # typically kernel sources are found here
            'kerneldir':    '/usr/src/linux',   \
            'arch':         utils.misc.identify_arch()}

    verbose = { 'std':      '',     \
                'set':      False,  \
                'logfile':  '/var/log/kigen.log'}

    master_conf     = {}
    kernel_conf     = {}
    modules_conf    = {}
    initramfs_conf  = {}
    version_conf    = {}
    url_conf        = {}

    # copy command line arguments
    cliopts = sys.argv

    # parse /etc/kigen/master.conf
    master_conf = etcparser.etc_parser_master()

    # if not enough parameters exit with usage
    if len(sys.argv) < 2:
        usage.print_usage()
        sys.exit(2)

    # set default kernel sources
    if 'kernel-sources' in master_conf:
        # if set grab value from config file
        cli['kerneldir'] = master_conf['kernel-sources']
    # else: exit

    if not 'tool' in cliopts and not 't' in cliopts:
        # don't check for kernel version if we use 'kigen tool'
        cli['KV'], cli['KNAME'] = utils.misc.get_kernel_version(cli['kerneldir'])

        # exit if kernel dir doesn't exist
        if not os.path.isdir(cli['kerneldir']):
            print(stdout.red('error') + ': ' + cli['kerneldir'] + ' does not exist.')
            sys.exit(2)
        # exit if kernel version is not found
        if cli['KV'] is 'none':
            print(stdout.red('error') + ': ' + cli['kerneldir']+'/Makefile not found')
            sys.exit(2)

    # prevent multiple targets from running
    if ('k' in cliopts and 'i' in cliopts)               or \
        ('initramfs' in cliopts and 'kernel' in cliopts) or \
        ('k' in cliopts and 'initramfs' in cliopts)      or \
        ('i' in cliopts and 'kernel' in cliopts)         or \
        ('t' in cliopts and 'kernel' in cliopts)         or \
        ('t' in cliopts and 'initramfs' in cliopts)      or \
        ('tool' in cliopts and 'kernel' in cliopts)      or \
        ('tool' in cliopts and 'initramfs' in cliopts)   or \
        ('tool' in cliopts and 'i' in cliopts)           or \
        ('tool' in cliopts and 'k' in cliopts)           or \
        ('t' in cliopts and 'i' in cliopts)              or \
        ('t' in cliopts and 'k' in cliopts):
        print(stdout.red('error') + ': kigen cannot run multiple targets at once.')
        sys.exit(2)

    # === parsing for the kernel target ===
    if 'kernel' in sys.argv or 'k' in sys.argv:
        # we found the kernel target
        # parse accordingly
        if 'kernel' in sys.argv:
            target = 'kernel'
            cliopts.remove('kernel')
        if 'k' in sys.argv:
            target = 'k'
            cliopts.remove('k')

        # parse 
        kernel_conf = etcparser.etc_parser_kernel()

        try:
            # parse command line
            opts, args = getopt(cliopts[1:], "dhn", [           \
                                    "help",                     \
                                    "version",                  \
                                    "credits",                  \
                                    "conf=",                    \
                                    "dotconfig=",               \
                                    "bbconf=",                  \
                                    "rename=",                  \
                                    "initramfs=",               \
                                    "mrproper",                 \
                                    "clean",                    \
                                    "silentoldconfig",          \
                                    "defconfig",                \
                                    "localmodconfig",           \
                                    "localyesconfig",           \
                                    "menuconfig",               \
                                    "allyesconfig",             \
                                    "nomodules",                \
                                    "nomodinstall",             \
                                    "fakeroot=",                \
                                    "allnoconfig",              \
                                    "nooldconfig",              \
                                    "oldconfig",                \
                                    "logfile=",                 \
                                    "noboot",                   \
                                    "nosaveconfig",             \
                                    "hostbin",                  \
                                    "fixdotconfig=",            \
                                    "module-rebuild",           \
                                    "debug"])
        except GetoptError as err:
            print(str(err)) # "option -a not recognized"
            usage.print_usage()
            sys.exit(2)

        # this has to be taken care before quiet is initialized
        # hence the extra loop, catch --logfile before all
        cli['logfile'] = '/var/log/kigen.log'
        if master_conf['logfile'] != '':
            cli['logfile'] = master_conf['logfile']
        for o, a in opts:
            if o in ("--logfile"):
                cli['logfile'] = a

        # default
        cli['dotconfig']    = master_conf['kernel-sources']+'/.config'
        if kernel_conf['dotconfig'] != '':
            cli['dotconfig'] = kernel_conf['dotconfig']

# FIXME
#        # HACK only use default if we use kigen k
        if not 'tool' in cliopts and not 't' in cliopts:
            cli['rename']       = '/boot/kernel-kigen-'+cli['arch']+'-'+cli['KV']
        else:
            cli['rename']       = ''
        if kernel_conf['rename'] != '':
            cli['rename'] = kernel_conf['rename']

        cli['initramfs']    = ''

        cli['info']         = False

        cli['mrproper']     = False
        if kernel_conf['mrproper'] == 'True':
            cli['mrproper'] = True

        cli['localmodconfig'] = False
        if kernel_conf['localmodconfig'] == 'True':
            cli['localmodconfig'] = True

        cli['localyesconfig'] = False
        if kernel_conf['localyesconfig'] == 'True':
            cli['localyesconfig'] = True

        cli['silentoldconfig'] = False
        if kernel_conf['silentoldconfig'] == 'True':
            cli['silentoldconfig'] = True

        cli['defconfig'] = False
        if kernel_conf['defconfig'] == 'True':
            cli['defconfig'] = True

        cli['menuconfig']   = False
        if kernel_conf['menuconfig'] == 'True':
            cli['menuconfig'] = True

        cli['clean'] = False
        if kernel_conf['clean'] == 'True':
            cli['clean'] = True

        cli['allyesconfig'] = False

        cli['allnoconfig']  = False

        cli['oldconfig']    = False
        if kernel_conf['nooldconfig'] == 'False':
            cli['oldconfig'] = True

        cli['nomodinstall'] = False
        if kernel_conf['nomodinstall'] == 'True':
            cli['nomodinstall'] = True

        cli['nomodules'] = False
        if kernel_conf['nomodules'] == 'True':
            cli['nomodules'] = True
            # No module support implies not installing modules
            cli['nomodinstall'] = True 

        cli['fakeroot']     = '/'
        if kernel_conf['fakeroot'] != '':
            cli['fakeroot'] = kernel_conf['fakeroot']

        cli['nocache']      = False

        cli['noboot']       = False
        if kernel_conf['noboot'] == 'True':
            cli['noboot'] = True

#       quiet               = '2>&1 | tee -a ' + logfile # verbose
#       quiet               = '>>' + logfile + ' 2>&1' # quiet + logfile

        verbose['std']      = '>>' + cli['logfile'] + ' 2>&1'
        verbose['set']      = False

        if master_conf['debug'] == 'True':
            verbose['set'] = True
            verbose['std'] = '2>&1 | tee -a ' + cli['logfile'] + ' ; test ${PIPESTATUS[0]} -eq 0'
            verbose['logfile'] = cli['logfile']

        cli['color']        = True

        cli['nosaveconfig'] = False

        if kernel_conf['nosaveconfig'] == 'True':
            cli['nosaveconfig'] = True

        cli['fixdotconfig'] = ''
        if kernel_conf['fixdotconfig'] != '':
            cli['fixdotconfig'] = kernel_conf['fixdotconfig']
            
        cli['module-rebuild'] = False
        if kernel_conf['module-rebuild'] == 'True':
            cli['module-rebuild'] = True

        # target options
        for o, a in opts:
            if o in ("-h", "--help"):
                usage.print_usage_kernel(cli, master_conf, kernel_conf)
                sys.exit(0)
            elif o in ("--credits"):
                usage.print_credits()
                sys.exit(0)
            elif o in ("--version"):
                usage.print_version()
                sys.exit(0)
            # have to declare logfile here too
            elif o in ("--logfile="):
                cli['logfile'] = a
                verbose['logfile'] = cli['logfile']
            elif o in ("-d", "--debug"):
#               quiet = '>>' + logfile + ' 2>&1' # logfile
#               quiet = '2>&1 | tee -a ' + logfile # verbose
                verbose['std'] = '2>&1 | tee -a ' + cli['logfile'] + ' ; test ${PIPESTATUS[0]} -eq 0'
                verbose['set'] = True
                verbose['logfile'] = cli['logfile']
            elif o in ("-k", "--dotconfig"):
                cli['dotconfig'] = a
                cli['oldconfig'] = True # make sure .config is ok
            elif o in ("--rename"):
                cli['rename'] = a
            elif o in ("--initramfs"):
                cli['initramfs'] = a
            elif o in ("--mrproper"):
                cli['mrproper'] = True
            elif o in ("--localmodconfig"):
                cli['localmodconfig'] = True
            elif o in ("--localyesconfig"):
                cli['localyesconfig'] = True
            elif o in ("--silentoldconfig"):
                cli['silentoldconfig'] = True
            elif o in ("--defconfig"):
                cli['defconfig'] = True
            elif o in ("--menuconfig"):
                cli['menuconfig'] = True
            elif o in ("--nooldconfig"):
                cli['oldconfig'] = False
            elif o in ("--oldconfig"):
                cli['oldconfig'] = True
            elif o in ("--nomodinstall"):
                cli['nomodinstall'] = True
            elif o in ("--nomodules"):
                cli['nomodules'] = True
            elif o in ("--fakeroot"):
#                if os.path.isdir(a):
                 cli['fakeroot'] = a
#                else:
#                    print "%s is not a directory" % a
#                    sys.exit(2)
            elif o in ("--noboot"):
                cli['noboot'] = True
            elif o in ("--nosaveconfig"):
                cli['nosaveconfig'] = True
            elif o in ("--clean"):
                cli['clean'] = True
            elif o in ("--fixdotconfig"):
                cli['fixdotconfig'] = a
#            elif o in ("--getdotconfig"):
#                cli['getdotconfig'] = a
            elif o in ("--module-rebuild"):
                cli['module-rebuild'] = True
            else:
                assert False, "uncaught option"

    # === parsing for the initramfs target ===
    elif 'initramfs' in sys.argv or 'i' in sys.argv:
        # we found the initramfs target
        # parse accordingly
        if 'initramfs' in sys.argv:
            target = 'initramfs'
            cliopts.remove('initramfs')
        if 'i' in sys.argv:
            target = 'i'
            cliopts.remove('i')

        # parse /etc/kigen/initramfs/modules.conf and 
        # /etc/kigen/initramfs/initramfs.conf
        initramfs_conf, modules_conf, version_conf, url_conf = etcparser.etc_parser_initramfs()

        try:
            # parse command line
            opts, args = getopt(cliopts[1:], "hdn", [  \
                                    "dotconfig=",   \
                                    "mrproper",     \
                                    "menuconfig",   \
                                    "allyesconfig", \
                                    "nooldconfig",  \
                                    "defconfig",    \
                                    "oldconfig",    \
                                    "bin-luks",     \
                                    "host-luks",    \
                                    "source-luks",  \
                                    "source-lvm2",  \
                                    "bin-lvm2",     \
                                    "host-lvm2",    \
                                    "bin-dmraid",   \
                                    "host-dmraid",  \
                                    "source-dmraid",\
                                    "iscsi",        \
                                    "logfile=",     \
                                    "bin-evms",     \
                                    "host-evms",    \
                                    "mdadm",        \
                                    "splash=",      \
                                    "sres=",        \
                                    "sinitrd=",     \
                                    "firmware=",    \
                                    "bin-disklabel",\
                                    "host-disklabel",\
                                    "source-disklabel",\
                                    "unionfs-fuse", \
                                    "aufs",         \
                                    "bin-dropbear", \
                                    "host-dropbear",\
                                    "source-dropbear",\
                                    "linuxrc=",     \
                                    "nocache",      \
                                    "nomodules",    \
                                    "noboot",       \
                                    "selinux",      \
                                    "help",         \
                                    "version",      \
                                    "credits",      \
                                    "nosaveconfig", \
                                    "hostbin",      \
                                    "bin-glibc",    \
                                    "host-glibc",   \
                                    "libncurses",   \
                                    "bin-libncurses",\
                                    "host-libncurses",\
                                    "bin-zlib",     \
                                    "host-zlib",    \
                                    "rename=",      \
                                    "plugin=",      \
                                    "rootpasswd=",  \
                                    "hostsshkeys",  \
                                    "ssh-pubkeys",  \
                                    "ssh-pubkeys-file", \
                                    "keymaps=",     \
                                    "source-ttyecho",\
                                    "bin-strace",   \
                                    "host-strace",  \
                                    "source-strace",\
                                    "bin-screen",   \
                                    "host-screen",  \
                                    "source-screen",\
                                    "debugflag",    \
                                    "bin-all",      \
                                    "host-all",     \
                                    "source-all",   \
                                    "bin-busybox",  \
                                    "host-busybox", \
                                    "dynlibs", \
                                    "debug"])
        except GetoptError as err:
            print(str(err)) # "option -a not recognized"
            usage.print_usage()
            sys.exit(2)
    
        # this has to be taken care before quiet is initialized
        # hence the extra loop, catch --logfile before all
        cli['logfile'] = '/var/log/kigen.log'
        if master_conf['logfile'] != '':
            cli['logfile'] = master_conf['logfile']
        for o, a in opts:
            if o in ("--logfile"):
                cli['logfile'] = a

        cli['oldconfig'] = False # too much verbose
        if initramfs_conf['oldconfig'] == 'True':
            cli['oldconfig'] = True

        # default
        cli['dotconfig'] = ''
        if initramfs_conf['dotconfig'] != '':
            cli['dotconfig'] = initramfs_conf['dotconfig']
            cli['oldconfig'] = True # make sure .config is ok

        cli['menuconfig'] = False
        if initramfs_conf['menuconfig'] == 'True':
            cli['menuconfig'] = True

        cli['defconfig'] = False
        if initramfs_conf['defconfig'] == 'True':
            cli['defconfig'] = True

        cli['bin-all'] = False
        if initramfs_conf['bin-all'] == 'True':
            cli['bin-busybox']      = True
            cli['bin-luks']         = True
            cli['bin-lvm2']         = True
            cli['bin-screen']       = True
            cli['bin-disklabel']    = True
            cli['bin-strace']       = True
#            cli['bin-evms']         = True
            cli['bin-glibc']        = True
            cli['bin-libncurses']   = True
            cli['bin-zlib']         = True
            cli['bin-dmraid']       = True
            cli['bin-dropbear']     = True

        cli['source-all'] = False
        if initramfs_conf['source-all'] == 'True':
            cli['source-luks'] = True
            cli['source-lvm2'] = True
            cli['source-screen'] = True
            cli['source-disklabel'] = True
            cli['source-ttyecho'] = True
            cli['source-strace'] = True
            cli['source-dmraid'] = True
            cli['source-dropbear'] = True

        cli['bin-luks'] = False
        if initramfs_conf['bin-luks'] == 'True':
            cli['bin-luks'] = True
            cli['source-luks'] = False

        cli['source-luks'] = False
        if initramfs_conf['source-luks'] == 'True':
            cli['source-luks'] = True
            cli['bin-luks'] = False

        cli['bin-busybox'] = False
        if initramfs_conf['bin-busybox'] == 'True':
            cli['bin-busybox'] = True

        cli['source-lvm2'] = False
        if initramfs_conf['source-lvm2'] == 'True':
            cli['source-lvm2'] = True

        cli['bin-lvm2'] = False
        if initramfs_conf['bin-lvm2'] == 'True':
            cli['bin-lvm2'] = True

        cli['bin-dmraid'] = False
        if initramfs_conf['bin-dmraid'] == 'True':
            cli['bin-dmraid'] = True
        cli['source-dmraid'] = False
        if initramfs_conf['source-dmraid'] == 'True':
            cli['source-dmraid'] = True

#        cli['iscsi'] = False
#        if initramfs_conf['iscsi'] == 'True':
#            cli['iscsi'] = True

        cli['bin-evms'] = False
        if initramfs_conf['bin-evms'] == 'True':
            cli['bin-evms'] = True

#        cli['mdadm'] = False
#        if initramfs_conf['mdadm'] == 'True':
#            cli['mdadm'] = True

        cli['splash'] = ''
        if initramfs_conf['splash'] != '':
            cli['splash'] = initramfs_conf['splash']

        cli['sres'] = '' # 1024x768
        if initramfs_conf['sres'] != '':
            cli['sres'] = initramfs_conf['sres']

        cli['sinitrd'] = '' # a custom initrd.splash file

#        cli['firmware'] = ''

        cli['bin-disklabel'] = False
        if initramfs_conf['bin-disklabel'] == 'True':
            cli['bin-disklabel'] = True

        cli['source-disklabel'] = False
        if initramfs_conf['source-disklabel'] == 'True':
            cli['source-disklabel'] = True

#        cli['unionfs'] = False
#        if initramfs_conf['unionfs'] == 'True':
#           cli['unionfs'] = True

#        cli['aufs'] = False

        cli['linuxrc'] = ''
        if initramfs_conf['linuxrc'] != '':
            cli['linuxrc'] = initramfs_conf['linuxrc']

        cli['bin-dropbear'] = False
        if initramfs_conf['bin-dropbear'] == 'True':
            cli['bin-dropbear'] = True

        cli['source-dropbear'] = False
        if initramfs_conf['source-dropbear'] == 'True':
            cli['source-dropbear'] = True

        cli['nomodules'] = False
        if initramfs_conf['nomodules'] == 'True':
            cli['nomodules'] = True

        cli['nocache'] = False
        if initramfs_conf['nocache'] == 'True':
            cli['nocache'] = True

        cli['noboot'] = False
        if initramfs_conf['noboot'] == 'True':
            cli['noboot'] = True

        cli['selinux']      = False
#       quiet               = '2>&1 | tee -a ' + logfile # verbose
#       quiet               = '>>' + logfile + ' 2>&1' # quiet + logfile
        verbose['std']      = '>>' + cli['logfile'] + ' 2>&1'
        cli['color']        = True
        cli['nosaveconfig'] = False
#        if initramfs_conf['nosaveconfig'] == 'True':
#            cli['nosaveconfig'] = True
        cli['hostbin']      = False
        if initramfs_conf['hostbin'] == 'True':
            cli['hostbin'] = True

        cli['bin-glibc'] = False
        if initramfs_conf['bin-glibc'] == 'True':
            cli['bin-glibc'] = True

        cli['bin-libncurses'] = False
        if initramfs_conf['bin-libncurses'] == 'True':
            cli['bin-libncurses'] = True

        cli['bin-zlib'] = False
        if initramfs_conf['bin-zlib'] == 'True':
            cli['bin-zlib'] = True
# FIXME
#        # HACK setup default only when using kigen i
        if not 'tool' in cliopts and not 't' in cliopts:
            cli['rename'] = '/boot/initramfs-kigen-'+cli['arch']+'-'+cli['KV']
        else:
            cli['rename'] = ''
        if initramfs_conf['rename'] != '':
            cli['rename'] = initramfs_conf['rename']

        cli['plugin'] = ''
        if initramfs_conf['plugin'] != '':
            cli['plugin'] = initramfs_conf['plugin']

        cli['rootpasswd']  = ''
        if initramfs_conf['rootpasswd'] != '':
            cli['rootpasswd'] = initramfs_conf['rootpasswd']

        cli['hostsshkeys']  = False
        if initramfs_conf['hostsshkeys'] == 'True':
            cli['hostsshkeys'] = True

        cli['ssh-pubkeys']  = False
        if initramfs_conf['ssh-pubkeys'] == 'True':
            cli['ssh-pubkeys'] = True

        cli['ssh-pubkeys-file']  = ''
        if initramfs_conf['ssh-pubkeys-file'] != '':
            cli['ssh-pubkeys-file'] = initramfs_conf['ssh-pubkeys-file']

        cli['source-ttyecho'] = False
        if initramfs_conf['source-ttyecho'] == 'True':
            cli['source-ttyecho'] = True

        cli['keymaps'] = 'all'
        if initramfs_conf['keymaps'] != '':
            cli['keymaps'] = initramfs_conf['keymaps']

        cli['bin-strace'] = False
        if initramfs_conf['bin-strace'] == 'True':
            cli['bin-strace'] = True

        cli['source-strace'] = False
        if initramfs_conf['source-strace'] == 'True':
            cli['source-strace'] =True

        cli['bin-screen'] = False
        if initramfs_conf['bin-screen'] == 'True':
            cli['bin-screen'] = True

        cli['source-screen'] = False
        if initramfs_conf['source-screen'] == 'True':
            cli['source-screen'] = True

        cli['dynlibs'] = False
        if initramfs_conf['dynlibs'] == 'True':
            cli['dynlibs'] = True

        cli['debugflag'] = False
        if initramfs_conf['debugflag'] == 'True':
            cli['debugflag']= True

        # tools
        cli['extract']      = ''
        cli['to']           = '/var/tmp/kigen/extracted-initramfs'
        cli['compress']     = ''
        cli['into']         = '/var/tmp/kigen/compressed-initramfs/initramfs_data.cpio.gz'

        verbose['set'] = False
        if master_conf['debug'] == 'True':
            verbose['set'] = True
            verbose['std'] = '2>&1 | tee -a ' + cli['logfile'] + ' ; test ${PIPESTATUS[0]} -eq 0'
            verbose['logfile'] = cli['logfile']
    
        # target options
        for o, a in opts:
            if o in ("-h", "--help"):
                usage.print_usage_initramfs(cli, master_conf, initramfs_conf, modules_conf)
                sys.exit(0)
            elif o in ("--credits"):
                usage.print_credits()
                sys.exit(0)
            elif o in ("--version"):
                usage.print_version()
                sys.exit(0)
            # have to declare logfile here too
            elif o in ("--logfile="):
                cli['logfile'] = a
                verbose['logfile'] = cli['logfile']
            elif o in ("-d", "--debug"):
#               quiet = '>>' + logfile + ' 2>&1' # logfile
#               quiet = '2>&1 | tee -a ' + logfile # verbose
                verbose['std'] = '2>&1 | tee -a ' + cli['logfile'] + ' ; test ${PIPESTATUS[0]} -eq 0'
                verbose['set'] = True
                verbose['logfile'] = cli['logfile']
            elif o in ("--host-all"):
                cli['bin-busybox']      = True
                cli['bin-luks']         = True
                cli['bin-lvm2']         = True
                cli['bin-screen']       = True
                cli['bin-disklabel']    = True
                cli['bin-strace']       = True
#                cli['bin-evms']         = True
                cli['bin-glibc']        = True
                cli['bin-libncurses']   = True
                cli['bin-zlib']         = True
                cli['bin-dmraid']       = True
                cli['bin-dropbear']     = True
            elif o in ("--source-all"):
                cli['source-luks']      = True
                cli['source-lvm2']      = True
                cli['source-disklabel'] = True
                cli['source-screen']    = True
                cli['source-ttyecho']   = True
                cli['source-strace']    = True
                cli['source-dmraid']    = True
                cli['source-dropbear']  = True
            elif o in ("--host-disklabel"):
                cli['bin-disklabel'] = True
                cli['source-disklabel'] = False
            elif o in ("--source-disklabel"):
                cli['bin-disklabel'] = False
                cli['source-disklabel'] = True
            elif o in ("--luks"):
                cli['luks'] = True
# FIXME trigger --keymap=all?
            elif o in ("--host-luks"):
                cli['bin-luks'] = True
                cli['source-luks'] = False
            elif o in ("--source-luks"):
                cli['source-luks'] = True
                cli['bin-luks'] = False
            elif o in ("--source-lvm2"):
                cli['source-lvm2'] = True
                cli['bin-lvm2'] = False
            elif o in ("--host-lvm2"):
                cli['bin-lvm2'] = True
                cli['source-lvm2'] = False
            elif o in ("--host-dmraid"):
                cli['bin-dmraid'] = True
            elif o in ("--source-dmraid"):
                cli['source-dmraid'] = True
            elif o in ("--dotconfig"):
                cli['dotconfig'] = a
                cli['oldconfig'] = True # make sure .config is ok
            elif o in ("--iscsi"):
                cli['iscsi'] = True
            elif o in ("--host-evms"):
                cli['bin-evms'] = True
            elif o in ("--mdadm"):
                cli['mdadm'] = True
            elif o in ("--mrproper"):
                cli['mrproper'] = True
            elif o in ("--menuconfig"):
                cli['menuconfig'] = True
            elif o in ("--nooldconfig"):
                cli['oldconfig'] = False
            elif o in ("--oldconfig"):
                cli['oldconfig'] = True
            elif o in ("--defconfig"):
                cli['defconfig'] = True
            elif o in ("--splash"):
                cli['splash'] = a
            elif o in ("--firmware"):
                if os.path.isdir(a):
                    cli['firmware'] = a
                else:
                    print(("%s is not a directory" % a))
                    sys.exit(2)
            elif o in ("--unionfs-fuse"):
                cli['unionfs'] = True
            elif o in ("--aufs"):
                cli['aufs'] = True
            elif o in ("--linuxrc"):
                cli['linuxrc'] = a
            elif o in ("--sres"):
                cli['sres'] = a
            elif o in ("--sinitrd"):
                cli['sinitrd'] = a
            elif o in ("--nocache"):
                cli['nocache'] = True
            elif o in ("--noboot"):
                cli['noboot'] = True
            elif o in ("--selinux"):
                cli['selinux'] = True
            elif o in ("--host-dropbear"):
                cli['bin-dropbear']     = True
                cli['bin-glibc']        = True    # dropbear needs glibc
                cli['bin-libncurses']   = True    # dropbear needs libncurses
                cli['bin-zlib']         = True    # dropbear needs zlib
            elif o in ("--source-dropbear"):
                cli['source-dropbear']  = True
                cli['bin-glibc']        = True    # dropbear needs glibc
                cli['bin-libncurses']   = True    # dropbear needs libncurses
                cli['bin-zlib']         = True    # dropbear needs zlib
            elif o in ("--host-glibc"):
                cli['bin-glibc'] = True
            elif o in ("--host-libncurses"):
                cli['bin-libncurses'] = True
            elif o in ("--host-zlib"):
                cli['bin-zlib'] = True
            elif o in ("--rename="):
                cli['rename'] = a
            elif o in ("--plugin"):
                cli['plugin'] = a # a is a list
            elif o in ("--rootpasswd="):
                cli['rootpasswd'] = a
            elif o in ("--hostsshkeys"):
                cli['hostsshkeys'] = True
            elif o in ("--ssh-pubkeys"):
                cli['ssh-pubkeys'] = True
            elif o in ("--ssh-pubkeys-file="):
                cli['ssh-pubkeys-file'] = a
            elif o in("--source-ttyecho"):
                cli['source-ttyecho'] = True
            elif o in ("--keymaps"):
                cli['keymaps'] = a
            elif o in ("--host-strace"):
                cli['bin-strace'] = True
                cli['source-strace'] = False
            elif o in ("--source-strace"):
                cli['source-strace'] = True
                cli['bin-strace'] = False
            elif o in ("--host-screen"):
                cli['bin-screen'] = True
                cli['bin-glibc'] = True         # screen needs glibc
                cli['bin-libncurses'] = True    # screen needs libncurses
            elif o in ("--source-screen"):
                cli['source-screen'] = True
                cli['bin-glibc'] = True         # screen needs glibc
                cli['bin-libncurses'] = True    # screen needs libncurses
            elif o in ("--debugflag"):
                cli['debugflag'] = True
            elif o in ("--nomodules"):
                cli['nomodules'] = True
            elif o in ("--host-busybox"):
                cli['bin-busybox'] = True
            elif o in ("--dynlibs"):
                cli['dynlibs'] = True

            else:
                assert False, "uncaught option"

    # === parsing for the tool target ===
    elif 'tool' in sys.argv or 't' in sys.argv:
        # we found the tool target
        # parse accordingly
        if 'tool' in sys.argv:
            target = 'tool'
            cliopts.remove('tool')
        if 't' in sys.argv:
            target = 't'
            cliopts.remove('t')

        # parse all /etc/kigen/ config files
        kernel_conf = etcparser.etc_parser_kernel()
        initramfs_conf, modules_conf, version_conf, url_conf = etcparser.etc_parser_initramfs()

        try:
            # parse command line
            opts, args = getopt(cliopts[1:], "hn", [  \
                                    "help",             \
                                    "extract=",         \
                                    "to=",              \
                                    "compress=",        \
                                    "into=",            \
                                    "getdotconfig=",    \
                                    "rmcache"])
        except GetoptError as err:
            print(str(err)) # "option -a not recognized"
            usage.print_usage()
            sys.exit(2)

        cli['getdotconfig'] = ''
        cli['extract']      = ''
        cli['to']           = '/var/tmp/kigen/extracted-initramfs'
        cli['compress']     = ''
        cli['into']         = '/var/tmp/kigen/compressed-initramfs/initramfs_data.cpio.gz'
        cli['rmcache']      = False

        for o, a in opts:
            if o in ("-h", "--help"):
                usage.print_usage_tool(cli)
                sys.exit(0)
            elif o in ("--getdotconfig"):
                cli['getdotconfig'] = a
            elif o in ("--extract"):
                cli['extract'] = a
            elif o in ("--to"):
                cli['to'] = a
            elif o in ("--compress"):
                cli['compress'] = a
            elif o in ("--into"):
                cli['into'] = a
            elif o in ("--rmcache"):
                cli['rmcache'] = True

            else:
                assert False, "uncaught option"

        if not opts:
            usage.print_usage_tool(cli)
            sys.exit(0)
    # === parsing for NO target ===
    else:
        try:
            opts, args = getopt(cliopts[1:], "hn", [\
                                "help",             \
                                "version",          \
                                "credits"])
        except GetoptError as err:
            print(str(err)) # "option -a not recognized"
            usage.print_usage()
            sys.exit(2)

        # single options
        for o, a in opts:
            if o in ("-h", "--help"):
                usage.print_usage()
                usage.print_examples()
                sys.exit(0)
            elif o in ("--version"):
                usage.print_version()
                sys.exit(0)
            elif o in ("--credits"):
                usage.print_credits()
                sys.exit(0)
            else:
                assert False, "uncaught option"

    if target == '':
        print(stdout.red('error') + ': target not known.')
        sys.exit(2)

###############
#    if not 'tool' in cliopts and not 't' in cliopts:
#        # don't check for kernel version if we use 'kigen tool'
#        cli['KV'], cli['KNAME'] = utils.misc.get_kernel_version(cli['kerneldir'])
#
#        # exit if kernel dir doesn't exist
#        if not os.path.isdir(cli['kerneldir']):
#            print(stdout.red('error') + ': ' + cli['kerneldir'] + ' does not exist.')
#            sys.exit(2)
#        # exit if kernel version is not found
#        if cli['KV'] is 'none':
#            print(stdout.red('error') + ': ' + cli['kerneldir']+'/Makefile not found')
#            sys.exit(2)
###############

    return  master_conf,    \
            kernel_conf,    \
            modules_conf,   \
            initramfs_conf, \
            version_conf,   \
            url_conf,       \
            target,         \
            cli,            \
            verbose
예제 #19
0
    def build(self):
        """
        Build kernel
        """
        zero = int('0')

        print(green(' * ')+'Kernel sources Makefile version '+white(self.KV)+' aka '+white(self.kname))

        # dotconfig provided by config file
        if self.kernel_conf['dotconfig']:
            # backup the previous .config if found
            if os.path.isfile(self.kernel_conf['dotconfig']):
                from time import strftime
                self.copy_config(self.kerneldir + '/.config', self.kerneldir + '/.config-' + str(strftime("%Y-%m-%d-%H-%M-%S")))

            # copy the custom .config if they are not the same
            if self.kernel_conf['dotconfig'] != self.kerneldir + '/.config':
                self.copy_config(self.kernel_conf['dotconfig'], self.kerneldir + '/.config')
        # dot config provided by cli

        if self.dotconfig:
            # backup the previous .config if found
            if os.path.isfile(self.kerneldir + '/.config'):
                from time import strftime
                self.copy_config(self.kerneldir + '/.config', self.kerneldir + '/.config-' + str(strftime("%Y-%m-%d-%H-%M-%S")))

            # copy the custom .config if they are not the same
            if self.dotconfig != self.kerneldir + '/.config':
                self.copy_config(self.dotconfig, self.kerneldir + '/.config')
        # WARN do not use self.dotconfig from now on but use self.kerneldir + '/.config' to point to kernel config

        if (self.mrproper is True) or (self.mrproper == 'True'):
            if self.make_mrproper() is not zero: self.fail('mrproper')
        if (self.clean is True) or (self.clean == 'True' ):
            if self.make_clean() is not zero: self.fail('clean')

        # self.fixdotconfig is a list like : initramfs,selinux,splash,pax
        fixdotconfiglist = self.fixdotconfig.split(',')
        d = {}
        for i in fixdotconfiglist:
            d[i] = ''
            if 'initramfs' in d:
                # PATCH initramfs kernel option
                self.add_option('CONFIG_INITRAMFS_SOURCE='+self.temp['initramfs'])
            if 'selinux' in d:
                # PATCH selinux kernel option
                self.add_option('CONFIG_AUDIT=y')
                self.add_option('CONFIG_AUDITSYSCALL=y')
                self.add_option('CONFIG_AUDIT_TREE=y')
                self.add_option('CONFIG_AUDIT_GENERIC=y')
                self.add_option('CONFIG_SECURITY_NETWORK=y')
                # above required to show SElinux
                self.add_option('CONFIG_SECURITY_SELINUX=y')
            if 'pax' in d:
                # PATCH PaX kernel option
                self.add_option('CONFIG_PAX_EMUTRAP=y')
            if 'splash' in d:
                # PATCH splash support
                self.add_option('CONFIG_FB=y')
                self.add_option('CONFIG_CONNECTOR=y')
                self.add_option('CONFIG_FB_UVESA=y')
                self.add_option('CONFIG_BLK_DEV=y')
                self.add_option('CONFIG_BLK_DEV_RAM=y')
                self.add_option('CONFIG_BLK_DEV_INITRD=y')
                self.add_option('CONFIG_FB_MODE_HELPERS=y')
                self.add_option('CONFIG_FB_TILEBLITTING=n')
                self.add_option('CONFIG_FRAMEBUFFER_CONSOLE=y')
                self.add_option('CONFIG_FB_CON_DECOR=y')
                self.add_option('CONFIG_INPUT_EVDEV=y')
                self.add_option('CONFIG_EXT2_FS=y')
                # FIXME this needs sys-apps/v86d
#                self.add_option('/usr/share/v86d/initramfs')

        # !!! by default don't alter dotconfig
        # !!! only if --fixdotconfig=<feat> is passed
        if (self.initramfs is not '') and (os.path.isfile(self.initramfs)):
            # user provides an initramfs!
            # FIXME do error handling: gzip screws it all like tar
#            if (self.fixdotconfig is True) or (self.kernel_conf['fixdotconfig'] is True):
#                self.add_option('CONFIG_INITRAMFS_SOURCE='+self.temp['initramfs'])
            self.import_user_initramfs(self.initramfs)
        #else:
        #    # ensure previous run with --initramfs have not left INITRAMFS configs if --fixdotconfig
        #    if self.fixdotconfig is True:
        #        self.remove_option('CONFIG_INITRAMFS_SOURCE')

        # initramfs provided by config file only
        elif (self.kernel_conf['initramfs'] is not '') and (self.initramfs is '') and (os.path.isfile(self.initramfs)):
#            if (self.fixdotconfig is True) or (self.kernel_conf['fixdotconfig'] is True):
#                self.add_option('CONFIG_INITRAMFS_SOURCE='+self.temp['initramfs'])
            self.import_user_initramfs(self.kernel_conf['initramfs'])
#        else:
#            if self.fixdotconfig is True:
#                self.remove_option('CONFIG_INITRAMFS_SOURCE')
        elif (self.initramfs is not ''):
            print(red('error: ') + self.initramfs + " is not a file")
            sys.exit(2)
 
        if self.defconfig is True:
            if self.make_defconfig() is not zero: self.fail('defconfig')
        if self.localmodconfig is True:
            if self.make_localmodconfig() is not zero: self.fail('localmodconfig')
        if self.localyesconfig is True:
            if self.make_localyesconfig() is not zero: self.fail('localyesconfig')
        if self.silentoldconfig is True:
            if self.make_silentoldconfig() is not zero: self.fail('silentoldconfig')
        if (self.oldconfig is True):
            if self.make_oldconfig() is not zero: self.fail('oldconfig')
        if (self.menuconfig is True) or (self.menuconfig == 'True'):
            if self.make_menuconfig() is not zero: self.fail('menuconfig')
    
        # check for kernel .config (gotta be sure)
        if os.path.isfile(self.kerneldir+'/.config') is not True: 
            self.fail(self.kerneldir+'/.config'+' does not exist.')

        # prepare
        if self.make_prepare() is not zero: self.fail('prepare')
    
        # bzImage
        if self.make_bzImage() is not zero: self.fail('bzImage')
    
        # modules
        # if --allnoconfig is passed, then modules are disabled
        # same with --nomodules
        if self.allnoconfig is not True and self.nomodules is not True:
            if self.make_modules() is not zero: self.fail('modules')
            if (self.nomodinstall is False) or (self.nomodinstall == 'False'):
                # modules_install
                if self.make_modules_install() is not zero: self.fail('modules_install')
        # save kernel config
        if (self.nosaveconfig is False) or (self.nosaveconfig == 'False'):
            if os.path.isdir('/etc/kernels/'):
                process('cp %s %s' % (self.kerneldir+'/.config', '/etc/kernels/dotconfig-kigen-'+self.arch+'-'+self.KV), self.verbose)
            else:
                process('mkdir /etc/kernels', self.verbose)
                process('cp %s %s' % (self.kerneldir+'/.config', '/etc/kernels/dotconfig-kigen-'+self.arch+'-'+self.KV), self.verbose)
            print(green(' * saved ') + '/etc/kernels/dotconfig-kigen-'+self.arch+'-'+self.KV)
예제 #20
0
파일: usage.py 프로젝트: r1k0/kigen
def print_usage_initramfs(cli, master_conf, initramfs_conf, modules_conf):
    print('Parameter:\t\t    Config value:\tDescription:')
    print()
    print('--execute, -x\t\t\t\t\tExecute')
    print()
    print('Features:')
    print('+ from source code')
    print('| --source-luks             ', end='')
    print(initramfs_conf['source-luks'], end='') # bool
    print('\t\tInclude LUKS support from sources')
    print('| --source-lvm2             ', end='')
    print(initramfs_conf['source-lvm2'], end='') # bool
    print('\t\tInclude LVM2 support from sources')
    print(stdout.red('| --source-dropbear         '), end='')
    print(initramfs_conf['source-dropbear'], end='') # bool
    print('\t\tInclude dropbear support from sources')
    print('|  --debugflag              ', end='')
    print(initramfs_conf['debugflag'], end='') # bool
    print('\t\t Compile dropbear with #define DEBUG_TRACE in debug.h')
    print('| --source-screen           ', end='')
    print(initramfs_conf['source-screen'], end='') # bool
    print('\t\tInclude the screen binary tool from sources')
    print('| --source-disklabel        ', end='')
    print(initramfs_conf['source-disklabel'], end='') # bool
    print('\t\tInclude support for UUID/LABEL from sources')
    print('| --source-ttyecho          ', end='')
    print(initramfs_conf['source-ttyecho'], end='') # bool
    print('\t\tCompile and include the handy ttyecho.c tool')
    print('| --source-strace           ', end='')
    print(initramfs_conf['source-strace'], end='') # bool
    print('\t\tCompile and include the strace binary tool from sources')
    print('| --source-dmraid           ', end='')
    print(initramfs_conf['source-dmraid'], end='') # bool
    print('\t\tInclude DMRAID support from sources')
#    print('| --source-all              ', end='')
#    print(initramfs_conf['source-all'], end='') # bool
#    print('\t\tInclude all possible features from sources')

    print('+ from host binaries')
    print('| --host-busybox            ', end='')
    print(initramfs_conf['bin-busybox'], end='') # bool
    print('\t\tInclude busybox support from host')
    print('| --host-luks               ', end='')
    print(initramfs_conf['bin-luks'], end='') # bool
    print('\t\tInclude LUKS support from host')
    print('| --host-lvm2               ', end='')
    print(initramfs_conf['bin-lvm2'], end='') # bool
    print('\t\tInclude LVM2 support from host')
    print('| --host-dropbear           ', end='')
    print(initramfs_conf['bin-dropbear'], end='') # bool
    print('\t\tInclude dropbear support from host')
    print('| --host-screen             ', end='')
    print(initramfs_conf['bin-screen'], end='') # bool
    print('\t\tInclude the screen binary tool from host')
    print('| --host-disklabel          ', end='')
    print(initramfs_conf['bin-disklabel'], end='') # bool
    print('\t\tInclude support for UUID/LABEL from host')
    print('| --host-strace             ', end='')
    print(initramfs_conf['bin-strace'], end='') # bool
    print('\t\tInclude the strace binary tool from host')
#    print('| --host-evms               ', end='')
#    print(initramfs_conf['bin-evms'], end='') # bool
#    print('\t\tInclude the evms binary tool from host')
    print('| --host-glibc              ', end='')
    print(initramfs_conf['bin-glibc'], end='') # bool
    print('\t\tInclude host GNU C libraries (required for dns,dropbear)')
    print('| --host-libncurses         ', end='')
    print(initramfs_conf['bin-libncurses'], end='') # bool
    print('\t\tInclude host libncurses (required for dropbear)')
    print('| --host-zlib               ', end='')
    print(initramfs_conf['bin-zlib'], end='') # bool
    print('\t\tInclude host zlib (required for dropbear)')
    print('| --host-dmraid             ', end='')
    print(initramfs_conf['bin-dmraid'], end='') # bool
    print('\t\tInclude DMRAID support from host')
#    print('| --host-all                ', end='')
#    print(initramfs_conf['bin-all'], end='') # bool
#    print('\t\tInclude all possible features from host')
    print()

    print(stdout.yellow('  --dynlibs                 '), end='')
    print(initramfs_conf['dynlibs'], end='') # bool
    print('\t\tInclude detected libraries from dynamically linked binaries')

    # fix \t display depending on length of cli[splash']
    if cli['splash'] != '':
        if len(cli['splash']) <= 4:
            tab = '\t\t\t'
        elif len(cli['splash']) > 4 and len(cli['splash']) < 8:
            tab = '\t\t'
        elif len(cli['splash']) > 8:
            tab = '\t\t'
    else:
        tab = '\t\t\t'
#    print('  --splash=<theme>          "'+initramfs_conf['splash'], end='"')
#    print(tab+'Include splash support (splashutils must be merged)')
#    print('   --sres=YxZ[,YxZ]         "'+initramfs_conf['sres'], end='"')
#    print('\t\t\t Splash resolution, all if not set')

    # fix \t display depending on length of cli['ply']
    if cli['plymouth'] != '':
        if len(cli['plymouth']) <= 4:
            tab = '\t\t\t'
        elif len(cli['plymouth']) > 4 and len(cli['plymouth']) < 8:
            tab = '\t\t'
        elif len(cli['plymouth']) > 8:
            tab = '\t\t'
    else:
        tab = '\t\t\t'
    print('  --plymouth=<theme>          "'+initramfs_conf['plymouth'], end='"')
    print(tab+'Include plymouth support (plymouth must be merged)')
#    print('   --sres=YxZ[,YxZ]         "'+initramfs_conf['sres'], end='"')
#    print('\t\t\t Plymouth resolution, all if not set')

    # fix \t display depending on length of cli['rootpasswd']
    if cli['rootpasswd'] != '':
        if len(cli['rootpasswd']) <= 4:
            tab = '\t\t'
        elif len(cli['rootpasswd']) > 4:
            tab = '\t\t'
    else:
        tab = '\t\t\t'
    print('  --rootpasswd=<passwd>     "'+cli['rootpasswd'], end='"')
    print(tab+'Create and set root password (required for dropbear)')
    print('  --hostsshkeys             ', end='')
    print(initramfs_conf['hostsshkeys'], end='') # bool
    print('\t\tInclude the OpenSSHd keys from host (used with dropbear)')
    print('  --ssh-pubkeys             ', end='')
    print(initramfs_conf['ssh-pubkeys'], end='') # bool
    print('\t\tInclude the SSH public keys (used with dropbear)')
    print('  --ssh-pubkeys-file        ', end='')
    print(initramfs_conf['ssh-pubkeys-file'], end='') # bool
    print('\n\t\t\t\t\t\tSource file with SSH public keys (used with dropbear)')
    if cli['keymaps'] != '':
        if len(cli['keymaps']) <= 4:
            tab = '\t\t\t'
        elif len(cli['keymaps']) > 4 and len(cli['keymaps']) < 8:
            tab = '\t\t'
        elif len(cli['keymaps']) > 8:
            tab = '\t'
    else:
        tab = '\t\t\t'
    print('  --keymaps=xx[,xx]|all     ', end='"')
    print(initramfs_conf['keymaps'], end='"') # bool
    print(tab+'Include all keymaps')
    # fix \t display depending on length of cli['plugin']
    if cli['plugin'] != '':
        if len(cli['plugin']) <= 4:
            tab = '\t\t\t'
        elif len(cli['plugin']) > 4:
            tab = '\t'
    else:
        tab = '\t\t\t'
    print('  --plugin=/dir[,/dir]      "'+cli['plugin']+'"', end='')
    print(tab+'Include list of user generated custom roots')
    print()

# NOFIX this works but force user to use --plugin= instead
#    print('Linuxrc:')
#    print('  --linuxrc=/linuxrc[,/file]"'+initramfs_conf['linuxrc']+'"', end='')
#    print('\t\t\tInclude custom linuxrc (files copied over to etc)')
#    print()

    print('Busybox:')
    print('  --dotconfig=/file         "'+initramfs_conf['dotconfig']+'"', end='')
    print('\t\t\tCustom busybox config file')
    print('  --defconfig               ', end='')
    print(initramfs_conf['defconfig'], end='') # bool
    print('\t\tSet .config to largest generic options')
    print('  --oldconfig               ', end='')
    print(initramfs_conf['oldconfig'], end='') # bool
    print('\t\tAsk for new busybox options if any')
    print('  --menuconfig              ', end='')
    print(initramfs_conf['menuconfig'], end='') # bool
    print('\t\tInteractive busybox options menu')
    print()

    print('Misc:')
    print('  --nocache                 ', end='')
    print(initramfs_conf['nocache'], end='')
    print('\t\tDelete previous cached data on startup')
    print('  --nomodules               ', end='')
    print(initramfs_conf['nomodules'], end='')
    print('\t\tDo not install kernel modules (all is kernel builtin)')
    print('  --noboot                  ', end='')
    print(initramfs_conf['noboot'], end='')
    print('\t\tDo not copy initramfs to /boot')
    print('  --rename=/file            "'+initramfs_conf['rename']+'"', end='')
    print('\t\t\tCustom initramfs file name')
    print('  --logfile=/file           "'+master_conf['logfile']+'"', end='')
    print() #'\t\tLog to file'
    print('  --debug, -d               '+master_conf['debug']+'', end='')
    print('\t\tDebug verbose')