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