[openwrt/openwrt] base-files: set root password if present inside board.json
LEDE Commits
lede-commits at lists.infradead.org
Wed Oct 2 06:48:16 PDT 2024
blogic pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/859bb4dd3fe88ffe6b461559a39e3cc1e0547892
commit 859bb4dd3fe88ffe6b461559a39e3cc1e0547892
Author: John Crispin <john at phrozen.org>
AuthorDate: Sat Sep 21 17:53:24 2024 +0200
base-files: set root password if present inside board.json
Add code to set plain password or put the hash into /etc/shadow.
Signed-off-by: John Crispin <john at phrozen.org>
---
package/base-files/files/etc/uci-defaults/50-root-passwd | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/package/base-files/files/etc/uci-defaults/50-root-passwd b/package/base-files/files/etc/uci-defaults/50-root-passwd
new file mode 100644
index 0000000000..9eddf1559b
--- /dev/null
+++ b/package/base-files/files/etc/uci-defaults/50-root-passwd
@@ -0,0 +1,12 @@
+. /usr/share/libubox/jshn.sh
+
+json_init
+json_load "$(cat /etc/board.json)"
+
+json_select credentials
+ json_get_vars root_password_hash root_password_hash
+ [ -z "$root_password_hash" ] || sed -i "s|^root:[^:]*|root:$root_password_hash|g" /etc/shadow
+
+ json_get_vars root_password_plain root_password_plain
+ [ -z "$root_password_plain" ] || { (echo "$root_password_plain"; sleep 1; echo "$root_password_plain") | passwd root }
+json_select ..
More information about the lede-commits
mailing list