Skip to content

Commit 7692ed5

Browse files
committed
firstlogin: use useradd/groupadd instead of the adduser suite
Debian forky demoted adduser from the essential/minimal set, so minimal images ship without it and armbian-firstlogin fails at user creation (adduser: command not found) — reported in armbian/os#470 on Forky minimal. Switch to the passwd (Essential) tools, matching a6cb68a (addgroup -> groupadd in rockchip family_tweaks): - user creation: adduser --disabled-password --home ... --gecos ... -> useradd --create-home --home-dir ... --shell "$SHELL_PATH" --comment ... --user-group (per-user group, skel copy, disabled password preserved; password is set right after as before) - docker group: addgroup --system --quiet -> groupadd --system (getent guard already present) - /etc/adduser.conf DSHELL edit now guarded on the file existing; useradd reads /etc/default/useradd, which set_shell already updates. No new package needed; useradd/groupadd are Essential (passwd) so present on every image including minimal. Signed-off-by: Igor Pecovnik <igor@armbian.com>
1 parent e1f2e37 commit 7692ed5

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

packages/bsp/common/usr/lib/armbian/armbian-firstlogin

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,11 @@ set_shell() {
258258
SHELL_PATH=$(grep "/$USER_SHELL$" /etc/shells | tail -1)
259259
chsh -s "$(grep -iF "/$USER_SHELL" /etc/shells | tail -1)"
260260

261-
# change shell for future users
261+
# change shell for future users. useradd (Essential, from passwd) reads
262+
# /etc/default/useradd; /etc/adduser.conf only exists when the (now optional
263+
# on Debian forky+) adduser package is installed, so guard that edit.
262264
sed -i "s|^SHELL=.*|SHELL=${SHELL_PATH}|" /etc/default/useradd
263-
sed -i "s|^DSHELL=.*|DSHELL=${SHELL_PATH}|" /etc/adduser.conf
265+
[[ -f /etc/adduser.conf ]] && sed -i "s|^DSHELL=.*|DSHELL=${SHELL_PATH}|" /etc/adduser.conf
264266

265267
}
266268

@@ -586,7 +588,13 @@ add_user() {
586588
RealName="$PRESET_DEFAULT_REALNAME"
587589
fi
588590

589-
adduser --quiet --disabled-password --home /home/"$RealUserName" --gecos "$RealName" "$RealUserName"
591+
# useradd (Essential, from passwd) instead of adduser (optional on
592+
# Debian forky+, absent from minimal images). --user-group mirrors
593+
# adduser's per-user group; --create-home copies /etc/skel; login shell
594+
# comes from SHELL_PATH (set_shell ran first). Password is disabled here
595+
# and set right below, same as adduser --disabled-password.
596+
useradd --create-home --home-dir /home/"$RealUserName" --shell "$SHELL_PATH" \
597+
--comment "$RealName" --user-group "$RealUserName"
590598

591599
# download and add SSH key if defined
592600
if [[ -n "${PRESET_USER_KEY}" ]]; then
@@ -608,7 +616,7 @@ add_user() {
608616
# (docker-ce package creates this group automatically during postinst, but we create it early
609617
# to guarantee group membership is ready immediately after user creation.)
610618
if ! getent group docker >/dev/null; then
611-
if ! addgroup --system --quiet docker 2>/dev/null; then
619+
if ! groupadd --system docker 2>/dev/null; then
612620
echo "Warning: Failed to create docker group" >&2
613621
fi
614622
fi

0 commit comments

Comments
 (0)