diff --git a/tools/AGENTS.md b/tools/AGENTS.md index 2a5d21e8b4..951bb0f437 100644 --- a/tools/AGENTS.md +++ b/tools/AGENTS.md @@ -113,6 +113,20 @@ MCDE and the logo: set before the switch. `mcde-desktop-webshots.cmds` is the script for the website's pictures (raw shots in `www/screenshots/`, not tracked; the kept ones are copied to `www/img/`). +- `dtlogin-check.sh` -- the INSTALLED package (`make debian-install`, /usr/mdt + with /etc/mdt) through dtlogin: greeter, login, session, front panel. + `mcde-desktop.sh` does that for the dev tree; this is the path of a package + user, which the tree never exercises. Runs on `:94`, exit 0 means the front + panel's `Applications` menu was in the window tree. + Hazard, like `mcde-desktop.sh`: `/etc/pam.d/dtlogin` is pam_permit for the + length of the run (sudo). Two things it must do in the right order, both + learned the hard way: kill the display's dtlogin and its Xvfb BEFORE putting + `$HOME/.dt` back (dtsession writes `sessions/current` and `errorlog` while it + dies, and a copy restored too early is written over), and roll `dtlogin.log` + before the run (a previous run's `Greeter started` satisfies the wait loop and + the test then measures a display that never came up). `-ac` on the Xvfb line + is not optional: dtlogin starts the server as `nobody` and nothing can look at + it otherwise. - `mcde-xkey.sh` -- presses keys by their plain keycodes (XTest), `mcde-xkey.sh Super_L h`; `xdotool key F8` on Xvfb sends Alt+F8 (header of the script). - `logo-ascii.sh`, `theme-logo.sh` -- the logo as ASCII, and in a palette's diff --git a/tools/dtlogin-check.sh b/tools/dtlogin-check.sh new file mode 100755 index 0000000000..08c80e011a --- /dev/null +++ b/tools/dtlogin-check.sh @@ -0,0 +1,226 @@ +#!/bin/sh +# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree. +# +# dtlogin-check.sh -- the MCDE of the INSTALLED package (make debian-install) +# through dtlogin: greeter, login, session, front panel. +# +# tools/mcde-desktop.sh does this for the dev tree (build/mcde-root). This is +# the other half: /usr/mdt as the package put it, with /etc/mdt as its +# configuration, which is the path a user of the package takes and a path the +# tree never exercises. +# +# usage: tools/dtlogin-check.sh [shot.png] +# +# Root is needed for dtlogin; the PAM file is switched to pam_permit for the +# run and put back by the trap, exactly as mcde-desktop.sh does it. + +set -u + +TOP=$(cd "$(dirname "$0")/.." && pwd) +PREFIX=/usr/mdt +[ -x "$PREFIX/bin/dtlogin" ] || + { echo "${0##*/}: no $PREFIX/bin/dtlogin (make debian-install)" >&2; exit 1; } + +DISP=${DTL_DISPLAY:-:94} +USERN=${USER:-lotherk} +WAIT=${DTL_WAIT:-10} +SHOT=${1:-$TOP/build/dtlogin-check/desktop.png} +WORK=$TOP/build/dtlogin-check +CFG=$WORK/cfg + +mkdir -p "$WORK" +rm -rf "$CFG" +mkdir -p "$CFG" +cp -a "$PREFIX/config/." "$CFG/" || exit 1 + +# A log of the previous run still says "Greeter started": the wait loop below +# would take that answer and test a display that never came up. Each run gets +# a fresh log. +mv -f "$WORK/dtlogin.log" "$WORK/dtlogin.log.prev" 2>/dev/null + +# A server of our own: the host has no display for dtlogin to attach to. +# A lock of a run that was killed makes the server refuse to start ("Server is +# already active for display 94", measured 2026-11-22): the lock goes only if +# nothing answers there any more. +if ! DISPLAY=$DISP xdpyinfo >/dev/null 2>&1; then + rm -f "/tmp/.X${DISP#:}-lock" 2>/dev/null || + sudo rm -f "/tmp/.X${DISP#:}-lock" +fi +# -ac: dtlogin starts the server as another user ("nobody", measured +# 2026-11-22), and an X server refuses local connections from anyone but its +# owner while access control is on. Without -ac the greeter is up but nothing +# can look at it: no xwininfo, no screenshot, no login. +cat > "$CFG/Xservers" < "$CFG/Xconfig" </dev/null +sudo cp "$CFG/Xconfig" /etc/mdt/config/Xconfig || exit 1 + +PAM=/etc/pam.d/dtlogin +PAMBAK=/etc/pam.d/dtlogin.orig.makronix +HOME_BAK=$WORK/home.dt.bak +switched= +restored= + +restore() { + [ -n "$restored" ] && return 0 + restored=yes + [ -n "$switched" ] && [ -f "$PAMBAK" ] && sudo cp "$PAMBAK" "$PAM" + # dtlogin forks the greeter and the session, and those are what hold the + # display: killing only $DTLOGIN_PID left a greeter and its Xvfb behind, + # and the next run then found the display taken ("Server unexpectedly + # died", measured 2026-11-22). Kill the tree, by name and by pid. + # "dtlogin <:94> -config ..." is the process that holds the display; the + # master ("dtlogin -config ... -nodaemon") is $DTLOGIN_PID and goes with it. + for p in $(pgrep -f "dtlogin <${DISP}>" 2>/dev/null) ${DTLOGIN_PID:-}; do + sudo kill "$p" 2>/dev/null + done + sleep 1 + for p in $(pgrep -f "dtlogin <${DISP}>" 2>/dev/null) \ + $(pgrep -f "Xvfb ${DISP}" 2>/dev/null); do + sudo kill -9 "$p" 2>/dev/null + done + sleep 2 + # $HOME/.dt AFTER the session is dead: dtsession writes sessions/current + # and errorlog on its way out, and a copy put back while it still ran was + # written over again ("errorlog differ", a fresh sessions/current.* -- + # measured 2026-11-22). The session's copy is set aside in + # $WORK/home.dt.session, never removed before the backup is back. + if [ -d "$HOME_BAK" ]; then + rm -rf "$WORK/home.dt.session" + [ -d "$HOME/.dt" ] && mv "$HOME/.dt" "$WORK/home.dt.session" + cp -a "$HOME_BAK" "$HOME/.dt" && rm -rf "$HOME_BAK" + fi +} +trap restore EXIT +trap 'restore; exit 1' HUP INT TERM + +if grep -q pam_permit "$PAM" 2>/dev/null; then + [ -f "$PAMBAK" ] || + { echo "$PAM is pam_permit and $PAMBAK is missing" >&2; exit 1; } +else + sudo cp "$PAM" "$PAMBAK" || exit 1 +fi +switched=yes +sudo tee "$PAM" >/dev/null <<'PAMEOF' +auth required pam_permit.so +account required pam_permit.so +session required pam_permit.so +password required pam_permit.so +PAMEOF + +# $HOME/.dt is where dtsession keeps the last session, and it restores it: a +# run on this host brought up Firefox and an xterm from the user's own +# desktop, so the screenshot showed the user's session and not the package's +# (measured 2026-11-22). Back it up and start from an empty one. A backup +# left by a killed run is the original: it is kept. +if [ -d "$HOME/.dt" ] && [ ! -d "$HOME_BAK" ]; then + rm -rf "$HOME_BAK.tmp" + cp -a "$HOME/.dt" "$HOME_BAK.tmp" && mv "$HOME_BAK.tmp" "$HOME_BAK" || + { echo "${0##*/}: cannot back up $HOME/.dt" >&2; exit 1; } +fi +rm -rf "$HOME/.dt" + +sudo "$PREFIX/bin/dtlogin" -config /etc/mdt/config/Xconfig -nodaemon -debug 1 \ + >> "$WORK/dtlogin.log" 2>&1 & +DTLOGIN_PID=$! + +i=0 +while [ $i -lt 90 ]; do + grep -q 'Greeter started' "$WORK/dtlogin.log" 2>/dev/null && break + sleep 1 + i=$((i + 1)) +done +if ! grep -q 'Greeter started' "$WORK/dtlogin.log" 2>/dev/null; then + echo "${0##*/}: greeter did not start; see $WORK/dtlogin.log" >&2 + exit 1 +fi +echo "${0##*/}: greeter up on $DISP" >&2 +sleep 5 + +# The username field: dtlogin's own size, as mcde-desktop.sh finds it. +UENTRY=$(DISPLAY=$DISP xwininfo -root -tree 2>/dev/null | awk '/222x23/ {print $1; exit}') +if [ -z "$UENTRY" ]; then + echo "${0##*/}: username entry not found" >&2 + DISPLAY=$DISP xwininfo -root -tree > "$WORK/tree.txt" 2>&1 + DISPLAY=$DISP import -window root "$WORK/greeter.png" 2>/dev/null + exit 1 +fi +DISPLAY=$DISP xdotool mousemove 551 394 click 1 +sleep 1 +DISPLAY=$DISP xdotool type --delay 40 "$USERN" +sleep 1 +DISPLAY=$DISP xdotool key Return +sleep 3 +# The password field takes a dummy: pam_permit says yes to anything. +i=0 +while [ $i -lt 5 ]; do + DISPLAY=$DISP xdotool type --delay 40 "x" + sleep 1 + DISPLAY=$DISP xdotool key Return + sleep 3 + DISPLAY=$DISP xdotool search --name login_shell >/dev/null 2>&1 || break + i=$((i + 1)) +done +sleep "$WAIT" + +if ! grep -q "Verify(): $USERN" "$WORK/dtlogin.log" 2>/dev/null; then + echo "${0##*/}: login failed; see $WORK/dtlogin.log" >&2 + tail -20 "$WORK/dtlogin.log" >&2 + exit 1 +fi +if ! grep -q 'Client started' "$WORK/dtlogin.log" 2>/dev/null; then + echo "${0##*/}: session did not start; see $WORK/dtlogin.log" >&2 + tail -20 "$WORK/dtlogin.log" >&2 + exit 1 +fi + +mkdir -p "$(dirname "$SHOT")" +# The window tree and the client list, while the display still exists. Taken +# here and printed from the files: an xdotool call on a display that is gone +# does not fail, it falls back to the caller's own DISPLAY and lists the host's +# windows ("Firefox", the browser of this desktop -- measured 2026-11-22). +DISPLAY=$DISP xwininfo -root -tree > "$WORK/tree.txt" 2>&1 +DISPLAY=$DISP xlsclients > "$WORK/clients.txt" 2>&1 +DISPLAY=$DISP import -window root "$SHOT" 2>/dev/null + +echo "${0##*/}: desktop up on $DISP (installed package, $SHOT)" >&2 +echo "--- windows ($WORK/tree.txt):" >&2 +sed -n 's/^ *0x[0-9a-f]* "\([^"]*\)".*/ \1/p' "$WORK/tree.txt" | sort -u >&2 +echo "--- clients ($WORK/clients.txt):" >&2 +sed 's/^/ /' "$WORK/clients.txt" >&2 + +# The front panel is what tells a desktop from a lone window manager: its +# menus are part of dtwm's panel, not of any client. +if sed -n 's/^ *0x[0-9a-f]* "\([^"]*\)".*/\1/p' "$WORK/tree.txt" | + grep -qx 'Applications'; then + echo "${0##*/}: front panel up (Applications menu present)" >&2 +else + echo "${0##*/}: front panel missing; see $WORK/tree.txt" >&2 + exit 1 +fi + +exit 0