From: Felix Fietkau Date: Tue, 17 Dec 2024 12:30:50 +0000 (+0100) Subject: unet-cli: add add/set-local-host command X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=bf3488a3807a570cfc0471c40a39113407c0de1f;p=project%2Funetd.git unet-cli: add add/set-local-host command Works like add/set-ssh-host, except that it executes commands locally in order to add the local host to the network. Signed-off-by: Felix Fietkau --- diff --git a/scripts/unet-cli b/scripts/unet-cli index bae0965..f7d8839 100755 --- a/scripts/unet-cli +++ b/scripts/unet-cli @@ -35,9 +35,11 @@ const usage_message = `Usage: ${basename(sourcepath())} [] : Import signed network config - set-config: Change network config parameters - add-host : Add a host + - add-local-host : Add a local OpenWrt host directly - add-ssh-host : Add a remote OpenWrt host via SSH ( can contain SSH options as well) - set-host : Change host settings + - set-local-host : Update local host settings - set-ssh-host : Update local and remote host settings - add-service : Add a service - set-service : Change service settings @@ -53,7 +55,7 @@ const usage_message = `Usage: ${basename(sourcepath())} [] set keepalive interval (seconds, 0: off, default: ${defaults.keepalive}) seed[=] create network private key from seed passphrase stun=[+|-][,...] set/add/remove STUN servers - - host options (add-host, add-ssh-host, set-host): + - host options (add-host, add-local-host, add-ssh-host, set-host): key= set host public key (required for add-host) port= set host tunnel port number pex_port= set host peer-exchange port (default: network pex_port, 0: disabled) @@ -62,7 +64,7 @@ const usage_message = `Usage: ${basename(sourcepath())} [] [,...] set/add/remove host announced subnets endpoint= set host endpoint address gateway= set host gateway (using name of other host) - - ssh host options (add-ssh-host, set-ssh-host) + - ssh host options (add-local-host, set-local-host, add-ssh-host, set-ssh-host) auth_key= use as public auth key on the remote host priv_key= use as private host key on the remote host (default: generate a new key) interface= use as interface in /etc/config/network on the remote host @@ -249,7 +251,7 @@ function key_arg(file, net_data) { return `-K ${file}.key`; } -function sync_ssh_host(host, net_data) { +function sync_host(host, net_data) { let interface = args.interface ?? "unet"; let connect = replace(args.connect ?? "", ",", " "); let auth_key = args.auth_key ?? net_data.config.id; @@ -287,7 +289,8 @@ function sync_ssh_host(host, net_data) { fh.seek(); let fh2 = mkstemp(); - system(`ssh ${host} sh <&${fh.fileno()} >&${fh2.fileno()}`); + let ssh = host ? "ssh " + host : ""; + system(`${ssh} sh <&${fh.fileno()} >&${fh2.fileno()}`); fh.close(); let data = {}, line; @@ -322,7 +325,7 @@ if (command == "import") { assert(import_file, "Missing import file argument"); } -if (command in [ "add-host", "set-host", "add-ssh-host", "set-ssh-host" ]) { +if (command in [ "add-host", "set-host", "add-local-host", "set-local-host", "add-ssh-host", "set-ssh-host" ]) { hostname = shift(ARGV); assert(hostname, "Missing host name argument"); } @@ -368,8 +371,13 @@ if (command == "create") { } } +if (command in [ "add-local-host", "set-local-host" ]) { + sync_host(null, net_data); + command = replace(command, "local-", ""); +} + if (command in [ "add-ssh-host", "set-ssh-host" ]) { - sync_ssh_host(ssh_host, net_data); + sync_host(ssh_host, net_data); command = replace(command, "ssh-", ""); }