From 8b1f1d099352954063a2bf53a612af4b81645be7 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sun, 15 Dec 2024 19:46:51 +0100 Subject: [PATCH] unet-cli: add support for importing networks from signed data This can be used to edit existing networks on the device when the key is generated from a seed password. Signed-off-by: Felix Fietkau --- scripts/unet-cli | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/unet-cli b/scripts/unet-cli index 600c332..970caaa 100755 --- a/scripts/unet-cli +++ b/scripts/unet-cli @@ -314,7 +314,12 @@ while (substr(ARGV[0], 0, 1) == "-") { exit(usage()); } -let hostname, ssh_host, servicename; +let import_file, hostname, ssh_host, servicename; + +if (command == "import") { + import_file = shift(ARGV); + assert(import_file, "Missing import file argument"); +} if (command in [ "add-host", "set-host", "add-ssh-host", "set-ssh-host" ]) { hostname = shift(ARGV); @@ -340,6 +345,16 @@ if (command in [ "add-ssh-host", "set-ssh-host" ]) { let net_data; +if (command == "import") { + if (!access(import_file) && + index(import_file, "/") < 0) + import_file = "/etc/unetd/" + import_file + ".bin"; + + assert(access(import_file), "Invalid import file name"); + if (system(`${unet_tool} -b ${import_file} -T -o ${file}`)) + exit(1); +} + if (command == "create") { net_data = { config: {}, @@ -380,6 +395,8 @@ if (command == "sign") { } switch (command) { +case 'import': + break; case 'create': case 'set-config': set_fields(net_data.config, { -- 2.30.2