fix: use exact match for USER_NAME in /etc/passwd check

The grep pattern `^${USER_NAME}` incorrectly matches usernames that
are prefixes of existing users. For example, USER_NAME=b matches the
'bin' user, causing the container to halt with a false positive.

Adding a colon after USER_NAME ensures exact username matching:
`^${USER_NAME}:` only matches the exact username field.

closes #118
This commit is contained in:
Brendan DeBeasi 2026-01-21 12:32:07 -08:00
parent 3923d9a27b
commit 155cbf4efd

View File

@ -1,7 +1,7 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
if [[ ! -f "/usermod.done" ]] && [[ -n "${USER_NAME}" ]] && [[ "${USER_NAME}" != "abc" ]] && grep -q "^${USER_NAME}" /etc/passwd; then
if [[ ! -f "/usermod.done" ]] && [[ -n "${USER_NAME}" ]] && [[ "${USER_NAME}" != "abc" ]] && grep -q "^${USER_NAME}:" /etc/passwd; then
echo "*** USER_NAME cannot be set to an user that already exists in /etc/passwd. Halting init. ***"
sleep infinity
else