def apply(context, args): parser = argparse.ArgumentParser() parser.add_argument("--overlay", action="store_true", help="use overlay") parser.add_argument("--envvar", type=str, action="append", default=[], help="variable in NAME=VALUE format") parser.add_argument("command", type=str, help="command to execute inside chroot") args = parser.parse_args(args) envvars = dict(map(lambda x:collect.parse_var(x), args.envvar)) command = context.apply_variables(args.command) print "$exec '%s'" % command if args.overlay: print "Using overlay" overlay_dir = os.path.normpath(context.destination) + ".overlay" overlay_root = overlay_dir + "/root" overlay_work = overlay_dir + "/work" collect.mkdir_p(overlay_root) collect.mkdir_p(overlay_work) try: overlayfs_opts = "lowerdir=%s,upperdir=%s,workdir=%s" % (context.source,context.destination,overlay_work) subprocess.check_call(["mount","-t","overlay","overlay","-o",overlayfs_opts,overlay_root]) try: do_chroot(overlay_root, command, envvars) finally: subprocess.check_call(["umount", overlay_root]) finally: shutil.rmtree(overlay_dir) else: do_chroot(context.destination, command, envvars)
def apply(context, args): parser = argparse.ArgumentParser() parser.add_argument("-b", "--baseurl", help="Base URL which points gentoo mirror", default="http://ftp.kddilabs.jp/pub/Linux/distributions/gentoo") args = parser.parse_args(args) url = find_latest_stage3.run(context.get_variable("ARCH"), context.apply_variables(args.baseurl)) filename = os.path.basename(url) cache_file = "download_cache/%s" % filename progress_file = "download_cache/_download_in_progress" if not os.path.exists(cache_file): collect.mkdir_p("download_cache") subprocess.check_call(["wget","-O",progress_file,url]) os.rename(progress_file, cache_file) subprocess.check_call(["tar","jxvpf",cache_file,"--xattrs","--xattrs-include=*","-C",context.destination])
def apply(context, args): parser = argparse.ArgumentParser() parser.add_argument("--overlay", action="store_true", help="use overlay") parser.add_argument("--envvar", type=str, action="append", default=[], help="variable in NAME=VALUE format") parser.add_argument("--store", type=str, default=None, help="variable name to store result") parser.add_argument("command", type=str, help="command to execute inside chroot") args = parser.parse_args(args) envvars = dict(map(lambda x: collect.parse_var(x), args.envvar)) command = context.apply_variables(args.command) print "$exec '%s'" % command output = "" if args.overlay: print "Using overlay" overlay_dir = os.path.normpath(context.destination) + ".overlay" overlay_root = overlay_dir + "/root" overlay_work = overlay_dir + "/work" collect.mkdir_p(overlay_root) collect.mkdir_p(overlay_work) try: overlayfs_opts = "lowerdir=%s,upperdir=%s,workdir=%s" % ( context.source, context.destination, overlay_work) subprocess.check_call([ "mount", "-t", "overlay", "overlay", "-o", overlayfs_opts, overlay_root ]) try: output = do_chroot(overlay_root, command, envvars) finally: subprocess.check_call(["umount", overlay_root]) finally: shutil.rmtree(overlay_dir) else: output = do_chroot(context.destination, command, envvars) if args.store is not None: context.set_variable(args.store, output.strip())
def apply(context, args): parser = argparse.ArgumentParser() parser.add_argument("--arch", type=str, help="target architecture (this directive is ignored if arch differents from $(ARCH))") parser.add_argument("--include", type=str, help="additional packages(space separated)") parser.add_argument("releaserpm", type=str, help="URL of release rpm") # e.g. http://ftp.kddilabs.jp/pub/Linux/distributions/CentOS/7.1.1503/os/x86_64/Packages/centos-release-7-1.1503.el7.centos.2.8.x86_64.rpm args = parser.parse_args(args) if args.arch is not None and args.arch != context.get_variable("ARCH"): return releaserpm = context.apply_variables(args.releaserpm) include = context.apply_variables(args.include) prefix = ["i386"] if context.get_variable("ARCH") == "i686" else [] release_name = re.sub('\.rpm$','', os.path.basename(releaserpm)) include_hash = "none" if include is None else base64.b32encode(hashlib.sha1(include).digest())[:8] cache_file = "download_cache/%s-%s.tar.gz" % (release_name, include_hash) if not os.path.isfile(cache_file): rpmbootstrap_dir = os.path.normpath(context.destination) + ".rpmbootstrap" collect.mkdir_p("%s/var/lib/rpm" % rpmbootstrap_dir) try: subprocess.check_call(prefix + ["rpm","--root",rpmbootstrap_dir,"--initdb"]) subprocess.check_call(prefix + ["rpm","-ivh","--nodeps","--root",os.path.abspath(rpmbootstrap_dir),releaserpm]) subprocess.check_call(prefix + ["yum","--nogpgcheck","--installroot",os.path.abspath(rpmbootstrap_dir),"install","-y","yum"]) shutil.rmtree("%s/var/lib/rpm" % rpmbootstrap_dir) collect.mkdir_p("%s/var/lib/rpm" % rpmbootstrap_dir) shutil.rmtree("%s/var/cache/yum" % rpmbootstrap_dir) with open("%s/etc/resolv.conf" % rpmbootstrap_dir, "w") as f: f.write("nameserver 8.8.8.8\n") env_with_root_path = collect.env_with_root_path() subprocess.check_call(prefix + ["chroot",rpmbootstrap_dir,"rpm","--initdb"], env=env_with_root_path) subprocess.check_call(prefix + ["chroot",rpmbootstrap_dir,"rpm","-ivh", releaserpm], env=env_with_root_path) subprocess.check_call(["mount","-o","bind","/dev","%s/dev" % rpmbootstrap_dir]) try: subprocess.check_call(prefix + ["chroot",rpmbootstrap_dir,"yum","install","-y","yum"], env=env_with_root_path) if include is not None: subprocess.check_call(prefix + ["chroot",rpmbootstrap_dir,"yum","install","-y"] + include.split(), env=env_with_root_path) subprocess.check_call(prefix + ["chroot",rpmbootstrap_dir,"yum","clean","-y","all"], env=env_with_root_path) shutil.rmtree("%s/var/cache/yum/base/packages" % rpmbootstrap_dir, True) collect.mkdir_p("%s/var/cache/yum/base/packages" % rpmbootstrap_dir) finally: subprocess.check_call(["umount","%s/dev" % rpmbootstrap_dir]) progress_file = "download_cache/_rpmbootstrap_in_progress" subprocess.check_call(["tar","zcvpf",progress_file,"--xattrs","--xattrs-include=*","-C",rpmbootstrap_dir,"."]) os.rename(progress_file, cache_file) finally: shutil.rmtree(rpmbootstrap_dir, True) subprocess.check_call(["tar","zxvpf",cache_file,"--xattrs","--xattrs-include=*","-C",context.destination])
def apply(context, args): parser = argparse.ArgumentParser() parser.add_argument( "--arch", type=str, help= "target architecture (this directive is ignored if arch differents from $(ARCH))" ) parser.add_argument("--include", type=str, help="additional packages(space separated)") parser.add_argument( "releaserpm", type=str, help="URL of release rpm" ) # e.g. http://ftp.kddilabs.jp/pub/Linux/distributions/CentOS/7.1.1503/os/x86_64/Packages/centos-release-7-1.1503.el7.centos.2.8.x86_64.rpm args = parser.parse_args(args) if args.arch is not None and args.arch != context.get_variable("ARCH"): return releaserpm = context.apply_variables(args.releaserpm) include = context.apply_variables(args.include) prefix = ["i386"] if context.get_variable("ARCH") == "i686" else [] release_name = re.sub('\.rpm$', '', os.path.basename(releaserpm)) include_hash = "none" if include is None else base64.b32encode( hashlib.sha1(include).digest())[:8] cache_file = "download_cache/%s-%s.tar.gz" % (release_name, include_hash) if not os.path.isfile(cache_file): rpmbootstrap_dir = os.path.normpath( context.destination) + ".rpmbootstrap" collect.mkdir_p("%s/var/lib/rpm" % rpmbootstrap_dir) try: subprocess.check_call( prefix + ["rpm", "--root", rpmbootstrap_dir, "--initdb"]) subprocess.check_call(prefix + [ "rpm", "-ivh", "--nodeps", "--root", os.path.abspath(rpmbootstrap_dir), releaserpm ]) subprocess.check_call(prefix + [ "yum", "--nogpgcheck", "--installroot", os.path.abspath(rpmbootstrap_dir), "install", "-y", "yum" ]) shutil.rmtree("%s/var/lib/rpm" % rpmbootstrap_dir) collect.mkdir_p("%s/var/lib/rpm" % rpmbootstrap_dir) shutil.rmtree("%s/var/cache/yum" % rpmbootstrap_dir) with open("%s/etc/resolv.conf" % rpmbootstrap_dir, "w") as f: f.write("nameserver 8.8.8.8\n") env_with_root_path = collect.env_with_root_path() execute.do_chroot(rpmbootstrap_dir, "rpm --initdb", envvars=env_with_root_path) execute.do_chroot(rpmbootstrap_dir, "rpm -ivh %s --nodeps" % releaserpm, envvars=env_with_root_path) execute.do_chroot(rpmbootstrap_dir, "yum install -y yum", envvars=env_with_root_path) if include is not None: execute.do_chroot(rpmbootstrap_dir, "yum install -y %s" % include, envvars=env_with_root_path) execute.do_chroot(rpmbootstrap_dir, "yum clean -y all", envvars=env_with_root_path) shutil.rmtree("%s/var/cache/yum/base/packages" % rpmbootstrap_dir, True) collect.mkdir_p("%s/var/cache/yum/base/packages" % rpmbootstrap_dir) progress_file = "download_cache/_rpmbootstrap_in_progress" subprocess.check_call([ "tar", "zcvpf", progress_file, "--xattrs", "--xattrs-include=*", "-C", rpmbootstrap_dir, "." ]) os.rename(progress_file, cache_file) finally: shutil.rmtree(rpmbootstrap_dir, True) subprocess.check_call([ "tar", "zxvpf", cache_file, "--xattrs", "--xattrs-include=*", "-C", context.destination ])