diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-07-13 08:40:59 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-07-13 08:40:59 +0300 |
commit | c2cffd5635379a49c3451c08c5d0f545281c61e8 (patch) | |
tree | 6ba356807f0a9f9b004b2cd5bc60253860df8e1a | |
parent | e8e737603e44d4077f81798d16010210114aa468 (diff) | |
download | v-i-c2cffd5635379a49c3451c08c5d0f545281c61e8.tar.gz |
feat(configure-installer): allow user to pre-configure a wifi
Sponsored-by: author
-rwxr-xr-x | configure-installer | 16 |
1 files changed, 16 insertions, 0 deletions
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) |