diff --git a/stages/org.osbuild.wsl.conf b/stages/org.osbuild.wsl.conf new file mode 100755 index 00000000..b9bbc7f3 --- /dev/null +++ b/stages/org.osbuild.wsl.conf @@ -0,0 +1,65 @@ +#!/usr/bin/python3 +""" +Configure advanced settings in Windows Subsystem for Linux. + +The stage configures the WSL settings on the system. +""" + +import sys + +import iniparse + +import osbuild.api + +SCHEMA = """ +"description": "WSL configuration.", +"additionalProperties": false, +"minProperties": 1, +"properties": { + "boot": { + "type": "object", + "description": "Configures the [boot] section.", + "additionalProperties": false, + "minProperties": 1, + "properties": { + "systemd": { + "type": "boolean", + "default": false, + "description": "Enable systemd." + } + } + } +} +""" + + +def main(tree, options): + boot = options.get("boot", {}) + if not boot: + return 0 + + systemd = boot.get("systemd", False) + wsl_conf_path = f"{tree}/etc/wsl.conf" + wsl_config = iniparse.SafeConfigParser() + + try: + with open(wsl_conf_path, "r", encoding="utf8") as f: + wsl_config.readfp(f) + except FileNotFoundError: + print(f"WSL configuration file '{wsl_conf_path}' does not exist, will be created.") + + if not wsl_config.has_section("boot"): + wsl_config.add_section("boot") + + wsl_config.set("boot", "systemd", (f"{systemd}").lower()) + + with open(wsl_conf_path, mode="w", encoding="utf8") as f: + wsl_config.write(f) + + return 0 + + +if __name__ == '__main__': + args = osbuild.api.arguments() + r = main(args["tree"], args["options"]) + sys.exit(r)