builder: build: filesystem.py: Allow downloading files from predefined url in config

This commit is contained in:
anonymix007 2024-08-25 16:01:30 +03:00
parent 53d8df4154
commit 48d7785332

View File

@ -96,8 +96,8 @@ def add_file(ctx: ArchBuilderContext, file: dict):
# at least path content # at least path content
if "path" not in file: if "path" not in file:
raise ArchBuilderConfigError("no path set in file") raise ArchBuilderConfigError("no path set in file")
if "content" not in file and "source" not in file: if "content" not in file and "source" not in file and "url" not in file:
raise ArchBuilderConfigError("no content or source set in file") raise ArchBuilderConfigError(f"no content, source or url set in file")
root = ctx.get_rootfs() root = ctx.get_rootfs()
path: str = file["path"] path: str = file["path"]
if path.startswith("/"): path = path[1:] if path.startswith("/"): path = path[1:]
@ -142,6 +142,10 @@ def add_file(ctx: ArchBuilderContext, file: dict):
shutil.copytree(src, real, symlinks=follow, dirs_exist_ok=True) shutil.copytree(src, real, symlinks=follow, dirs_exist_ok=True)
else: else:
shutil.copyfile(src, real, follow_symlinks=follow) shutil.copyfile(src, real, follow_symlinks=follow)
elif "url" in file:
cmds = ["wget", file["url"], "-O", real]
ret = ctx.run_external(cmds)
if ret != 0: raise OSError(f"wget failed with {ret}")
else: else:
assert False assert False
log.debug(f"chmod file {real} to {mode:04o}") log.debug(f"chmod file {real} to {mode:04o}")