armbian-firstlogin: fix rcfile ownership when creating ~/.bashrc and ~/.xsessionrc

When firstlogin (running as root) appends locale exports to a user's
~/.bashrc or ~/.xsessionrc and the file does not yet exist, the
redirection creates it as root:root. The user's subsequent login shell
cannot read it cleanly under strict modes and ownership is wrong.

Create the file first with touch + chown to the target user before
appending. If the file already exists, leave ownership alone — the
user may have customized it.

Addresses PR #9954 review discussion r3443078088.
This commit is contained in:
mingzq
2026-07-15 19:30:21 +08:00
committed by Tom Urlings
parent 7a018edae3
commit d4162b7733
@@ -511,6 +511,12 @@ set_timezone_and_locales() {
# setting detected locales only for user (idempotent)
for rcfile in /home/"$RealUserName"/.bashrc /home/"$RealUserName"/.xsessionrc; do
if [[ ! -e "$rcfile" ]]; then
# Create empty file with proper ownership before appending; leave
# ownership alone if the file already exists (user may have customized).
touch -- "$rcfile"
chown -- "$RealUserName":"$RealUserName" "$rcfile"
fi
if ! grep -q "^export LC_ALL=$LOCALES" "$rcfile" 2>/dev/null; then
{
echo "export LC_ALL=$LOCALES"