Add mkdir function

This commit is contained in:
Jan Schär 2024-05-10 17:37:19 +02:00
parent 968d09e362
commit b778340a5f
1 changed files with 12 additions and 10 deletions

View File

@ -66,6 +66,9 @@ def run(args, check=True, **kwargs):
print(f"> {' '.join(args)}")
subprocess.run(args, check=check, **kwargs)
def mkdir(dirname):
pathlib.Path(dirname).mkdir(parents=True, exist_ok=True)
def edit_file(filename, fn):
with open(filename) as f:
content = f.read()
@ -87,7 +90,6 @@ def main():
args = parser.parse_args()
script_dir = pathlib.Path(__file__).parent.resolve()
chroot_includes = pathlib.Path("config/includes.chroot")
with open(script_dir / "config/config.toml", "rb") as f:
config = tomllib.load(f)
@ -97,7 +99,7 @@ def main():
run("rm -rf .build config udeb-build".split())
# Download files.
run("mkdir -p downloads".split())
mkdir("downloads")
for download in DOWNLOADS:
filename = f'downloads/{download["name"]}'
try:
@ -144,7 +146,7 @@ def main():
lambda s: s.replace("@install_admin_password@", config["install_admin_password"]))
# Copy inventory file.
run("mkdir -p config/includes.binary/install".split())
mkdir("config/includes.binary/install")
run(["cp", f"{script_dir}/config/installer-inventory.txt", "config/includes.binary/install/inventory.txt"])
# Insert build date in login screen logo.
@ -154,7 +156,7 @@ def main():
# Build and install custom udeb packages for installer.
run(["cp", "-rT", f"{script_dir}/installer-udeb", "udeb-build"])
run("dpkg-buildpackage --build=all".split(), cwd="udeb-build/inventory-hostname")
run("mkdir -p config/packages.binary".split())
mkdir("config/packages.binary")
run("cp udeb-build/inventory-hostname_0_all.udeb config/packages.binary/".split())
# Copy the source lists. The installer deletes everything in sources.list.d,
@ -167,7 +169,7 @@ def main():
lambda s: s.replace("@contestant_root_password@", config["contestant_root_password"]))
# Copy authorized_keys.
run("mkdir -p config/includes.chroot/root/.ssh".split())
mkdir("config/includes.chroot/root/.ssh")
run(["cp", f"{script_dir}/config/contestant_authorized_keys", "config/includes.chroot/root/.ssh/authorized_keys"])
# Configure boot options.
@ -194,17 +196,17 @@ def main():
f"\n"
for i, option in enumerate(VARIANT_BOOT_OPTIONS[args.variant])
)
pathlib.Path("config/bootloaders/syslinux_common").mkdir(parents=True, exist_ok=True)
mkdir("config/bootloaders/syslinux_common")
with open("config/bootloaders/syslinux_common/live.cfg.in", "w") as f:
f.write(syslinux_boot_options)
# Install soi header.
(chroot_includes / "usr/local/include").mkdir(parents=True, exist_ok=True)
run(["tar", "--overwrite", "-xf", f"downloads/soi-header.tar.gz", "-C", f"{chroot_includes}/usr/local/include", "--strip-components=2", "soi-header/include/"])
mkdir("config/includes.chroot/usr/local/include")
run(["tar", "--overwrite", "-xf", "downloads/soi-header.tar.gz", "-C", "config/includes.chroot/usr/local/include", "--strip-components=2", "soi-header/include/"])
# Install codeblocks template.
(chroot_includes / "usr/share/codeblocks/templates/wizard").mkdir(parents=True, exist_ok=True)
run(["unzip", "-o", f"downloads/soi_template_codeblocks_ubuntu.zip", "-d", f"{chroot_includes}/usr/share/codeblocks/templates/wizard/"])
mkdir("config/includes.chroot/usr/share/codeblocks/templates/wizard")
run(["unzip", "-o", "downloads/soi_template_codeblocks_ubuntu.zip", "-d", "config/includes.chroot/usr/share/codeblocks/templates/wizard/"])
# Start the build.
run("lb build".split())