introduce hostname stage

this stage will set /etc/hostname in the image. it uses
systemd-firstboot to perform the change
This commit is contained in:
Martin Sehnoutka 2019-07-31 10:10:01 +02:00 committed by Tom Gundersen
parent 4c91a23e98
commit c27cdd5928

25
stages/org.osbuild.hostname Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/python3
import json
import os
import subprocess
import sys
def main(tree, options):
hostname = options["hostname"]
try:
os.remove(f"{tree}/etc/hostname")
print("/etc/hostname already exists. Replacing.")
except FileNotFoundError:
pass
subprocess.run(["systemd-firstboot", f"--root={tree}", f"--hostname={hostname}"], check=True)
return 0
if __name__ == '__main__':
args = json.load(sys.stdin)
r = main(args["tree"], args["options"])
sys.exit(r)