From c9f9ca7dc7d30e993643bf5a48be33ddb8be0dc2 Mon Sep 17 00:00:00 2001 From: Guy Sheffer Date: Thu, 2 Jul 2026 11:34:54 +0300 Subject: [PATCH] Fix GUI autologin without tty autologin Use Raspberry Pi's GUI-only autologin path after first-boot user setup so GUI images do not leave tty1 autologin enabled, and add a pre-post-boot E2E hook point for distros to assert boot state before test setup mutates it. Document the raspi-config do_autologin bitmask so the GUI-only value is clear. --- src/distro_testing/scripts/entrypoint.sh | 24 +++++++++++- .../opt/scripts/update_lightdm_conf | 37 ++++++++++++++++++- .../system/update_lightdm_conf.service | 1 + 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/distro_testing/scripts/entrypoint.sh b/src/distro_testing/scripts/entrypoint.sh index 2ce049cc..034c8d38 100755 --- a/src/distro_testing/scripts/entrypoint.sh +++ b/src/distro_testing/scripts/entrypoint.sh @@ -63,10 +63,32 @@ if [ "$SSH_WAIT_RC" -ne 0 ]; then exit 1 fi +# Run distro-specific boot-state checks before post-boot hooks mutate the image +if [ -x /test/hooks/post-ssh.sh ]; then + echo "" + echo "--- Step 3b: Post-SSH checks ---" + set +e + if [ -n "$ARTIFACTS_DIR" ]; then + /test/hooks/post-ssh.sh localhost "$SSH_PORT" "$ARTIFACTS_DIR" + else + /test/hooks/post-ssh.sh localhost "$SSH_PORT" + fi + POST_SSH_RC=$? + set -e + if [ "$POST_SSH_RC" -ne 0 ]; then + echo "Post-SSH hook failed" + if [ -n "$ARTIFACTS_DIR" ]; then + cp "$LOG_FILE" "$ARTIFACTS_DIR/qemu-boot.log" 2>/dev/null || true + echo "$POST_SSH_RC" > "$ARTIFACTS_DIR/exit-code" + fi + exit "$POST_SSH_RC" + fi +fi + # Run distro-specific post-boot setup (e.g. install packages, restart services) if [ -x /test/hooks/post-boot.sh ]; then echo "" - echo "--- Step 3b: Post-boot setup ---" + echo "--- Step 3c: Post-boot setup ---" /test/hooks/post-boot.sh localhost "$SSH_PORT" || echo "WARNING: post-boot hook failed" fi diff --git a/src/modules/gui/filesystem/opt/scripts/update_lightdm_conf b/src/modules/gui/filesystem/opt/scripts/update_lightdm_conf index 1fbd68ff..08dc9716 100755 --- a/src/modules/gui/filesystem/opt/scripts/update_lightdm_conf +++ b/src/modules/gui/filesystem/opt/scripts/update_lightdm_conf @@ -1,6 +1,39 @@ #!/bin/bash +set -e + +LIGHTDM_CONF=/etc/lightdm/lightdm.conf +TTY1_AUTOLOGIN_CONF=/etc/systemd/system/getty@tty1.service.d/autologin.conf + +set_lightdm_option() { + local key="$1" + local value="$2" + + if grep -Eq "^#?${key}=" "${LIGHTDM_CONF}"; then + sed -i -E "s|^#?${key}=.*|${key}=${value}|" "${LIGHTDM_CONF}" + else + printf '%s=%s\n' "${key}" "${value}" >> "${LIGHTDM_CONF}" + fi +} + if [ ! -f /etc/updated_lightdm_conf ]; then - sed -i 's/UID_1000_PLACEHOLDER/'$(id -nu 1000)'/g' /etc/lightdm/lightdm.conf + gui_user="$(id -nu 1000)" + + sed -i "s/UID_1000_PLACEHOLDER/${gui_user}/g" "${LIGHTDM_CONF}" + + # raspi-config do_autologin uses a bitmask: 1=TTY, 2=GUI, 3=both. + # FullPageOS needs GUI autologin without opening a local tty shell. + if ! SUDO_USER="${gui_user}" raspi-config nonint do_autologin 2; then + rm -f "${TTY1_AUTOLOGIN_CONF}" + rmdir --ignore-fail-on-non-empty "$(dirname "${TTY1_AUTOLOGIN_CONF}")" 2>/dev/null || true + set_lightdm_option autologin-user "${gui_user}" + fi + + set_lightdm_option user-session guisession + set_lightdm_option autologin-session guisession + set_lightdm_option autologin-user "${gui_user}" + + systemctl daemon-reload || true + systemctl try-restart getty@tty1.service || true + touch /etc/updated_lightdm_conf - # sudo shutdown -r now fi diff --git a/src/modules/gui/filesystem/root_init/etc/systemd/system/update_lightdm_conf.service b/src/modules/gui/filesystem/root_init/etc/systemd/system/update_lightdm_conf.service index eaf6b89b..3f6d974d 100644 --- a/src/modules/gui/filesystem/root_init/etc/systemd/system/update_lightdm_conf.service +++ b/src/modules/gui/filesystem/root_init/etc/systemd/system/update_lightdm_conf.service @@ -1,5 +1,6 @@ [Unit] Description=on first boot set up the user name auto login in lightdm.service +Before=lightdm.service [Service] ExecStart=/opt/custompios/scripts/update_lightdm_conf Type=oneshot