base-files: improve default root-passwd script

The script was not exiting cleanly causing it to not be removed from the
uci-defaults folder.

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin 2024-11-12 07:49:22 +01:00
parent 4c65359af4
commit b902284290
1 changed files with 12 additions and 6 deletions

View File

@ -3,10 +3,16 @@
json_init json_init
json_load "$(cat /etc/board.json)" json_load "$(cat /etc/board.json)"
json_select credentials if json_is_a credentials object; then
json_select credentials
json_get_vars root_password_hash root_password_hash json_get_vars root_password_hash root_password_hash
[ -z "$root_password_hash" ] || sed -i "s|^root:[^:]*|root:$root_password_hash|g" /etc/shadow if [ -n "$root_password_hash" ]; then
sed -i "s|^root:[^:]*|root:$root_password_hash|g" /etc/shadow
fi
json_get_vars root_password_plain root_password_plain 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 } if [ -n "$root_password_plain" ]; then
json_select .. (echo "$root_password_plain"; sleep 1; echo "$root_password_plain") | passwd root
fi
json_select ..
fi