stages/org.osbuild.wsl.conf: add stage to configure WSL settings
This commit is contained in:
parent
5dbf596ffa
commit
028bf67a1d
1 changed files with 65 additions and 0 deletions
65
stages/org.osbuild.wsl.conf
Executable file
65
stages/org.osbuild.wsl.conf
Executable file
|
|
@ -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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue