tools: dtlogin-check.sh, the installed package through dtlogin

The dev tree has mcde-desktop.sh; the .deb path (/usr/mdt, /etc/mdt) had
no test that logs in.  This one starts dtlogin on :94 against the
installed package, logs in with pam_permit, and requires the front
panel's Applications menu in the window tree.

Three things it learned in the runs, each a real failure first:

- -ac on the Xvfb line: dtlogin starts the server as nobody and nothing
  can look at it otherwise (xwininfo, xdotool, import all refused).
- Roll dtlogin.log before the run: a previous run's "Greeter started"
  satisfied the wait loop and the test measured a display that never
  came up.
- Kill the display's dtlogin and its Xvfb BEFORE restoring $HOME/.dt:
  dtsession writes sessions/current and errorlog on its way out, and a
  copy put back while it still ran was written over again.

Also: dtsession restores the last session, so without an empty $HOME/.dt
the screenshot showed the user's own Firefox and xterm, not the package
(a 682k-pixel white block).  $HOME/.dt is backed up and restored, and
the session's copy is kept in build/dtlogin-check/home.dt.session.

Test: sh tools/dtlogin-check.sh -> rc=0, clients dtwm, dtlaunch,
dtterm, mcdesoundd; screenshot is the MCDE desktop (no Firefox);
diff of $HOME/.dt against the pre-run copy: IDENTISCH.
This commit is contained in:
lotherk committed 2026-11-22 18:32:01 +00:00
1 parent 93aa5bacf2
commit c8cc69aac5
2 files changed
+240

No files matched your search

+14
View File
@@ -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
+226
View File
@@ -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" <<EOF
${DISP} Local local@none /usr/bin/Xvfb ${DISP} -ac -screen 0 1024x768x24 -nolisten tcp
EOF
cat > "$CFG/Xconfig" <<EOF
Dtlogin.errorLogFile: $WORK/dtlogin.log
Dtlogin.pidFile: $WORK/dtlogin.pid
Dtlogin.accessFile: $CFG/Xaccess
Dtlogin.servers: $CFG/Xservers
Dtlogin*resources: $CFG/C/Xresources
Dtlogin*startup: $CFG/Xstartup
Dtlogin*reset: $CFG/Xreset
Dtlogin*setup: $CFG/Xsetup
Dtlogin*failsafeClient: $CFG/Xfailsafe
Dtlogin.exportList: NLSPATH LANG
Dtlogin*userPath: /usr/bin:/bin:/usr/sbin:/sbin:$PREFIX/bin
Dtlogin*environment: XFILESEARCHPATH=$PREFIX/app-defaults/%L/%N
Dtlogin*authorize: False
Dtlogin*grabServer: False
Dtlogin*openTimeout: 20
Dtlogin*serverAttempts: 3
Dtlogin.requestPort: 0
EOF
# The configuration directory dtlogin reads: /etc/mdt, as the package and
# mcde-host.sh set it. Xconfig is read from there too, so the run uses one.
mkdir -p /etc/mdt/config 2>/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