base-files: uci-defaults: allow setting default credentials and ssh keys
authorJohn Crispin <john@phrozen.org>
Sat, 14 Sep 2024 06:44:19 +0000 (08:44 +0200)
committerJohn Crispin <john@phrozen.org>
Wed, 2 Oct 2024 13:41:33 +0000 (15:41 +0200)
Introduce new uci-default functions:
     - ucidef_set_root_password_hash [hash]
     - ucidef_set_root_password_plain [plaintext]
     - ucidef_set_ssh_authorized_key [ssh key]

Signed-off-by: John Crispin <john@phrozen.org>
package/base-files/files/lib/functions/uci-defaults.sh

index ba7288c2c6bcc21a39d04405d4169bceb380ef0e..507ddfc11ae1cea84dc69cbc8b5d244304a58e4b 100644 (file)
@@ -677,6 +677,29 @@ ucidef_set_country() {
        json_select ..
 }
 
+ucidef_set_root_password_plain() {
+       local passwd="$1"
+       json_select_object credentials
+               json_add_string root_password_plain "$passwd"
+       json_select ..
+}
+
+ucidef_set_root_password_hash() {
+       local passwd="$1"
+       json_select_object credentials
+               json_add_string root_password_hash "$passwd"
+       json_select ..
+}
+
+ucidef_set_ssh_authorized_key() {
+       local ssh_key="$1"
+       json_select_object credentials
+               json_select_array ssh_authorized_keys
+                       json_add_string "" "$ssh_key"
+               json_select ..
+       json_select ..
+}
+
 ucidef_set_ntpserver() {
        local server