From c2cffd5635379a49c3451c08c5d0f545281c61e8 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 13 Jul 2023 08:40:59 +0300 Subject: feat(configure-installer): allow user to pre-configure a wifi Sponsored-by: author --- configure-installer | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/configure-installer b/configure-installer index fce3695..b11cc6e 100755 --- a/configure-installer +++ b/configure-installer @@ -29,6 +29,8 @@ class Config: "user_ca_pub_file": None, "user_ca_pub_cmd": None, "cmd_as_user": None, + "wifi_name": None, + "wifi_password": None, } exandable = [ @@ -65,6 +67,9 @@ class Config: def host_cert(self, hostname): return self._get_from_file_or_cmd("host_cert", "host certificate", hostname) + def wifi(self): + return self.config.get("wifi_name"), self.config.get("wifi_password") + def _get_from_file_or_cmd(self, prefix, msg, hostname): log("_get: A") filename = self.config.get(f"{prefix}_file") @@ -206,6 +211,16 @@ def user_ca(config, mp): write(cakeys, ca_key, 0, 0, 0o644) +def wifi(config, mp): + (name, password) = config.wifi() + if name and password: + data = f"[Security]\nPassphrase={password}\n" + filename = f"{mp}/var/lib/iwd/{name}.psk" + dirname = os.path.dirname(filename) + os.makedirs(dirname, exist_ok=True) + write(filename, data, 0, 0, 0o600) + + def main(): log("configure-image starting") @@ -236,6 +251,7 @@ def main(): host_id(config, mp, args.hostname) authorized_keys(config, mp) user_ca(config, mp) + wifi(config, mp) finally: unmount(mp) os.rmdir(mp) -- cgit v1.2.1