Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Reset user session once first-setup completes #230

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions __first_setup_reset_session
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,28 @@ if [ "$(echo "${LOGIN_USERS}" | wc -l)" -gt 1 ]; then
fi

echo '[daemon]' > /etc/gdm3/daemon.conf


export highest_uid=$(grep -E "^UID_MIN " /etc/login.defs | sed 's/UID_MIN //')
export REAL_USER=""

# Gets the latest added user from /etc/passwd
# It gets the minimum UID for users using /etc/login.defs
# and loops over all the entries in /etc/passwd
# checking if the uid of the selected user is higher than the minimum uid
# if it is, then this uid gets set as the new minimum uid
# and it gets repeated until the last line of passwd is processed
# NOTE: This assumes that new users always have a higher uid than the previously added user and that no system user has a higher UID than the users
# it generally is a safe assumption to make, but should still be noted in case something goes wrong.
while read entry; do
uid=$(echo "$entry" | awk 'BEGIN {FS=":"}; {print $3}')
name=$(echo "$entry" | awk 'BEGIN {FS=":"}; {print $1}')
if [[ $((uid)) -gt $((highest_uid)) && $name != "nobody" ]]; then
export highest_uid=$uid
export REAL_USER=$name
fi
done < <(getent passwd)

if [ -e "/var/lib/AccountsService/users/$REAL_USER" ]; then
sed 's/Session=firstsetup/Session=gnome/g' -i "/var/lib/AccountsService/users/$REAL_USER"
fi