Exemple #1
0
def build(module, args):
    method = get_build_method(module, args)
    if not args.force and method.module_is_built(module):
        print blue("Module '%s' has already been built" % module.name)
        return False

    if args.recursive:
        dependencies = [x for x in [i.strip() for i in module['Depends'].split(',')] if x]
        if dependencies:
            print blue("Building dependencies for '%s'" % module.name)
            for i in dependencies:
                build(args.moduleset[i], args)

    TMP_BUILD_DIR = os.path.expanduser('~/tmp-build-dir')
    BUILD_DIR = os.path.join(TMP_BUILD_DIR, '%s-%s' % (module.name, module['Version']))

    code = system('rm -rf ' + os.path.expanduser('~/tmp-build-dir'), root=True)
    check_code(code, module)

    code = system('mkdir -p %s' % os.path.dirname(BUILD_DIR))
    check_code(code, module)

    method.build_module(module, BUILD_DIR)

    if module['Install']:
        install_packages([i.strip() for i in module['Install'].split(',')], BUILD_DIR, module)

    repo_dir = 'repository-%s' % args.moduleset.name
    if not os.path.exists(repo_dir):
        os.mkdir(repo_dir)
    code = system('mv -f %s/*.deb %s/' % (os.path.dirname(BUILD_DIR), repo_dir))
    return True
Exemple #2
0
    def setup_build_env(self, module, build_dir):
        self.uncompress_tarball(module, build_dir)

        print blue("Configuring the kernel")
        code = system('cp debian/config-%s-%s %s/.config' %
                      (module['Version'], self.args.arch, build_dir))
        check_code(code, module)
Exemple #3
0
def install_packages(packages_to_install, build_dir, module):
    if not packages_to_install:
        return

    control = PackageControlParser()
    control.read(os.path.join(build_dir, 'debian/control'))

    # Make a list of packages
    packages = [x['Package'] for x in control]

    # Make a list of dependencies we didn't build ourselves
    # FIXME: we skip the ${} for now.
    dependencies = []
    for package_info in control:
        if package_info['Package'] in packages:
            for dep in package_info.get('Depends', '').split(','):
                dep = dep.strip().split(None, 1)[0]
                if dep and not dep.startswith('$') and dep not in packages:
                    dependencies.append(dep)

    # Install said dependencies if there are any
    if dependencies:
        print blue("Installing dependencies for packages '%s'" % "', '".join(packages_to_install))
        code = system('apt-get install %s' % ' '.join(dependencies), root=True)
        check_code(code, module)

    # Install built packages
    print blue("Installing packages '%s'" % "', '".join(packages_to_install))
    dpkg_args = []
    for filename in glob.glob(os.path.join(os.path.dirname(build_dir), '*.deb')):
        if os.path.basename(filename).split('_', 1)[0] in packages_to_install:
            dpkg_args.append(filename)
    code = system("dpkg -i %s" % ' '.join(dpkg_args), root=True)
    check_code(code, module)
Exemple #4
0
    def build_module(self, module, build_dir):
        self.setup_build_env(module, build_dir)

        print blue("Building linux kernel '%s'" % module['Version'])
        cwd = os.path.expanduser('~/tmp-build-dir/linux-%s' % module['Version'])
        code = system('make-kpkg --revision=%s kernel_image kernel_headers kernel_source' % self.get_rev_tag(module),
                                  cwd=cwd, root=True)
        check_code(code, module)
Exemple #5
0
    def build_module(self, module, build_dir):
        self.setup_build_env(module, build_dir)

        print blue("Building linux kernel '%s'" % module['Version'])
        cwd = os.path.expanduser('~/tmp-build-dir/linux-%s' %
                                 module['Version'])
        code = system(
            'make-kpkg --revision=%s kernel_image kernel_headers kernel_source'
            % self.get_rev_tag(module),
            cwd=cwd,
            root=True)
        check_code(code, module)
Exemple #6
0
def build(module, args):
    method = get_build_method(module, args)
    if not args.force and method.module_is_built(module):
        print blue("Module '%s' has already been built" % module.name)
        return False

    if args.recursive:
        dependencies = [
            x for x in [i.strip() for i in module['Depends'].split(',')] if x
        ]
        if dependencies:
            print blue("Building dependencies for '%s'" % module.name)
            for i in dependencies:
                build(args.moduleset[i], args)

    TMP_BUILD_DIR = os.path.expanduser('~/tmp-build-dir')
    BUILD_DIR = os.path.join(TMP_BUILD_DIR,
                             '%s-%s' % (module.name, module['Version']))

    code = system('rm -rf ' + os.path.expanduser('~/tmp-build-dir'), root=True)
    check_code(code, module)

    code = system('mkdir -p %s' % os.path.dirname(BUILD_DIR))
    check_code(code, module)

    method.build_module(module, BUILD_DIR)

    if module['Install']:
        install_packages([i.strip() for i in module['Install'].split(',')],
                         BUILD_DIR, module)

    repo_dir = 'repository-%s' % args.moduleset.name
    if not os.path.exists(repo_dir):
        os.mkdir(repo_dir)
    code = system('mv -f %s/*.deb %s/' %
                  (os.path.dirname(BUILD_DIR), repo_dir))
    return True
Exemple #7
0
def install_packages(packages_to_install, build_dir, module):
    if not packages_to_install:
        return

    control = PackageControlParser()
    control.read(os.path.join(build_dir, 'debian/control'))

    # Make a list of packages
    packages = [x['Package'] for x in control]

    # Make a list of dependencies we didn't build ourselves
    # FIXME: we skip the ${} for now.
    dependencies = []
    for package_info in control:
        if package_info['Package'] in packages:
            for dep in package_info.get('Depends', '').split(','):
                dep = dep.strip().split(None, 1)[0]
                if dep and not dep.startswith('$') and dep not in packages:
                    dependencies.append(dep)

    # Install said dependencies if there are any
    if dependencies:
        print blue("Installing dependencies for packages '%s'" %
                   "', '".join(packages_to_install))
        code = system('apt-get install %s' % ' '.join(dependencies), root=True)
        check_code(code, module)

    # Install built packages
    print blue("Installing packages '%s'" % "', '".join(packages_to_install))
    dpkg_args = []
    for filename in glob.glob(os.path.join(os.path.dirname(build_dir),
                                           '*.deb')):
        if os.path.basename(filename).split('_', 1)[0] in packages_to_install:
            dpkg_args.append(filename)
    code = system("dpkg -i %s" % ' '.join(dpkg_args), root=True)
    check_code(code, module)
Exemple #8
0
    def setup_build_env(self, debian_dir, build_dir, module):
        orig_dir = build_dir + ".original"

        self.uncompress_tarball(module, orig_dir)

        print blue("Encoding PHP files")

        try:
            php_version = int(module["PHP-Version"])
        except:
            php_version = 5

        ioncube = php_version == 5 and IONCUBE5 or IONCUBE4
        code = system("%s %s %s -o %s" % (ioncube, IONCUBE_ARGS, orig_dir, build_dir))
        check_code(code, module)

        code = system("rm -rf %s" % orig_dir)
        check_code(code, module)

        code = system("cp -r %s %s/debian" % (debian_dir, build_dir))
        check_code(code, module)
Exemple #9
0
    def setup_build_env(self, debian_dir, build_dir, module):
        orig_dir = build_dir + ".original"

        self.uncompress_tarball(module, orig_dir)

        print blue("Encoding PHP files")

        try:
            php_version = int(module['PHP-Version'])
        except:
            php_version = 5

        ioncube = php_version == 5 and IONCUBE5 or IONCUBE4
        code = system('%s %s %s -o %s' %
                      (ioncube, IONCUBE_ARGS, orig_dir, build_dir))
        check_code(code, module)

        code = system('rm -rf %s' % orig_dir)
        check_code(code, module)

        code = system('cp -r %s %s/debian' % (debian_dir, build_dir))
        check_code(code, module)
Exemple #10
0
    def uncompress_tarball(self, module, destination):
        filename = os.path.join('tarballs', module['Basename'])
        if not os.path.exists(filename):
            fetch(module)

        dest_parent = os.path.dirname(destination)

        print blue("Uncompressing '%s'" % filename)
        if filename.endswith('.tar.bz2') or filename.endswith('.tbz'):
            check_code(system('tar xjf %s -C %s' % (filename, dest_parent)), module)
        elif filename.endswith('.tar.gz') or filename.endswith('.tgz'):
            check_code(system('tar xzf %s -C %s' % (filename, dest_parent)), module)
        elif filename.endswith('.zip'):
            check_code(system('unzip %s -d %s' % (filename, dest_parent)), module)
        else:
            raise Exception("Cannot find the type of the archive.")

        # Put the directory in the tarball in the right directory
        if not os.path.exists(destination):
            contents = os.listdir(dest_parent)
            if len(contents) == 1 and os.path.isdir('%s/%s' % (dest_parent, contents[0])):
                check_code(system('mv "%s/%s" %s' % (dest_parent, contents[0], destination)), module)
            else:
                check_code(system('mkdir %s' % destination), module)
                files = [os.path.join(dest_parent, file) for file in contents]
                check_code(system('mv %s %s' % (' '.join(files), destination)), module)
Exemple #11
0
 def build(self, module):
     cwd = os.path.expanduser('~/tmp-build-dir/%s-%s' % (module.name, module['Version']))
     code = system('pwd; dpkg-buildpackage -rfakeroot -b -uc', cwd=cwd)
     check_code(code, module)
Exemple #12
0
 def build(self, module):
     cwd = os.path.expanduser("~/tmp-build-dir/%s-%s" % (module.name, module["Version"]))
     code = system("pwd; dpkg-buildpackage -rfakeroot -b -uc", cwd=cwd)
     check_code(code, module)
Exemple #13
0
 def install_dependencies(self, module, build_dir):
     deps = self.get_dependencies(build_dir)
     if deps:
         code = system("apt-get install %s" % " ".join(deps), root=True)
         check_code(code, module)
Exemple #14
0
def fetch(module):
    if (os.path.exists('tarballs/%s' % module['Basename'])):
        print blue("File already exists: '%s'" % module['Basename'])
        return False

    if not os.path.exists('tarballs'):
        os.mkdir('tarballs')

    source_type = module['Source-Type']

    if source_type == 'wget':
        code = system('wget -nc %s -Otarballs/%s' % (module['Source'], module['Basename']))
        check_code(code, module)

    elif source_type == 'git':
        fullname = '%s-%s' % (module.name, module['Version'])
        branch = module.get('Branch', 'master')

        print blue("Cloning the last revision of the remote repository")
        code = system('git clone --depth=1 --branch=%s -- %s tarballs/%s' % (branch, module['Source'], fullname))
        check_code(code, module)

        print blue("Generating tarball")
        code = system('( cd tarballs/%s && git archive --format=tar --prefix=%s/ origin/%s ) | gzip -9 > tarballs/%s' \
                      % (fullname, fullname, branch, module['Basename']))
        check_code(code, module)

        print blue("Removing temporary directory")
        code = system('rm -rf tarballs/%s' % fullname)
        check_code(code, module)

    elif source_type == 'svn':
        tmpdir = '%s-%s' % (module.name, module['Version'])

        print blue("Exporting the SVN snapshot")
        code = system('svn export --force %s tarballs/%s' % (module['Source'], tmpdir))
        check_code(code, module)

        print blue("Generating tarball")
        code = system('cd tarballs && tar czvf %s %s' % (module['Basename'], tmpdir))
        check_code(code, module)

        print blue("Removing temporary directory")
        code = system('rm -rf tarballs/%s' % tmpdir)
        check_code(code, module)

    elif source_type == 'local':
        filename = module['Source']
        if filename.startswith('file://'):
            filename = filename[7:]

        code = system('cp %s tarballs/' % filename)
        check_code(code, module)

    else:
        raise Exception("The '%s' source type is not handled yet" % source_type)

    return True
Exemple #15
0
 def build(self, module):
     cmd = 'sh ' + os.path.expanduser(self.wrapper_script)
     cwd = os.path.expanduser('~/tmp-build-dir/%s-%s' % (module.name, module['Version']))
     code = system(cmd, cwd=cwd)
     check_code(code, module)
Exemple #16
0
def fetch(module):
    if (os.path.exists('tarballs/%s' % module['Basename'])):
        print blue("File already exists: '%s'" % module['Basename'])
        return False

    if not os.path.exists('tarballs'):
        os.mkdir('tarballs')

    source_type = module['Source-Type']

    if source_type == 'wget':
        code = system('wget -nc %s -Otarballs/%s' %
                      (module['Source'], module['Basename']))
        check_code(code, module)

    elif source_type == 'git':
        fullname = '%s-%s' % (module.name, module['Version'])
        branch = module.get('Branch', 'master')

        print blue("Cloning the last revision of the remote repository")
        code = system('git clone --depth=1 --branch=%s -- %s tarballs/%s' %
                      (branch, module['Source'], fullname))
        check_code(code, module)

        print blue("Generating tarball")
        code = system('( cd tarballs/%s && git archive --format=tar --prefix=%s/ origin/%s ) | gzip -9 > tarballs/%s' \
                      % (fullname, fullname, branch, module['Basename']))
        check_code(code, module)

        print blue("Removing temporary directory")
        code = system('rm -rf tarballs/%s' % fullname)
        check_code(code, module)

    elif source_type == 'svn':
        tmpdir = '%s-%s' % (module.name, module['Version'])

        print blue("Exporting the SVN snapshot")
        code = system('svn export --force %s tarballs/%s' %
                      (module['Source'], tmpdir))
        check_code(code, module)

        print blue("Generating tarball")
        code = system('cd tarballs && tar czvf %s %s' %
                      (module['Basename'], tmpdir))
        check_code(code, module)

        print blue("Removing temporary directory")
        code = system('rm -rf tarballs/%s' % tmpdir)
        check_code(code, module)

    elif source_type == 'local':
        filename = module['Source']
        if filename.startswith('file://'):
            filename = filename[7:]

        code = system('cp %s tarballs/' % filename)
        check_code(code, module)

    else:
        raise Exception("The '%s' source type is not handled yet" %
                        source_type)

    return True
Exemple #17
0
 def build(self, module):
     cmd = 'sh ' + os.path.expanduser(self.wrapper_script)
     cwd = os.path.expanduser('~/tmp-build-dir/%s-%s' %
                              (module.name, module['Version']))
     code = system(cmd, cwd=cwd)
     check_code(code, module)
Exemple #18
0
 def install_dependencies(self, module, build_dir):
     deps = self.get_dependencies(build_dir)
     if deps:
         code = system('apt-get install %s' % ' '.join(deps), root=True)
         check_code(code, module)
Exemple #19
0
    def setup_build_env(self, module, build_dir):
        self.uncompress_tarball(module, build_dir)

        print blue("Configuring the kernel")
        code = system('cp debian/config-%s-%s %s/.config' % (module['Version'], self.args.arch, build_dir))
        check_code(code, module)
Exemple #20
0
    def uncompress_tarball(self, module, destination):
        filename = os.path.join('tarballs', module['Basename'])
        if not os.path.exists(filename):
            fetch(module)

        dest_parent = os.path.dirname(destination)

        print blue("Uncompressing '%s'" % filename)
        if filename.endswith('.tar.bz2') or filename.endswith('.tbz'):
            check_code(system('tar xjf %s -C %s' % (filename, dest_parent)),
                       module)
        elif filename.endswith('.tar.gz') or filename.endswith('.tgz'):
            check_code(system('tar xzf %s -C %s' % (filename, dest_parent)),
                       module)
        elif filename.endswith('.zip'):
            check_code(system('unzip %s -d %s' % (filename, dest_parent)),
                       module)
        else:
            raise Exception("Cannot find the type of the archive.")

        # Put the directory in the tarball in the right directory
        if not os.path.exists(destination):
            contents = os.listdir(dest_parent)
            if len(contents) == 1 and os.path.isdir(
                    '%s/%s' % (dest_parent, contents[0])):
                check_code(
                    system('mv "%s/%s" %s' %
                           (dest_parent, contents[0], destination)), module)
            else:
                check_code(system('mkdir %s' % destination), module)
                files = [os.path.join(dest_parent, file) for file in contents]
                check_code(system('mv %s %s' % (' '.join(files), destination)),
                           module)