Skip to content

fix(motd): keep colour when TERM is only bash unexported fallback - #107

Merged
LucaLin233 merged 2 commits into
mainfrom
forge/fix-motd-pam-colors
Nov 30, 2026
Merged

LucaLin233 merged 2 commits into
mainfrom
forge/fix-motd-pam-colors

Conversation

@LucaLin233

Copy link
Copy Markdown
Owner

Summary

Non-interactive login shells (PAM / run-parts) start the MOTD payload with no TERM. Bash then synthesises an unexported TERM=dumb, which the old guard [[ "${TERM:-}" == dumb ]] read as an explicit colourless request. On real SSH PTY logins to usnc this dropped all SGR, so the welcome panel, the Chinese time and the last-login source rendered plain.

The guard now disables colour only when TERM=dumb was actually exported by the caller: ( "${TERM:-}" == dumb && "${TERM@a}" == *x* ). An unexported Bash placeholder reports no export attribute, so the palette is restored. NO_COLOR handling is unchanged.

Scope

  • tools/setup-motd.sh and modules/system-customize.sh: the identical MOTD payload, same one-line guard change in both.
  • Both MOTD_PAYLOAD_SHA256 pins refreshed to the new payload hash 994857572414bb1f63e0104b980e461964d9884ba9329dd61f4fd3580b493b2c.
  • tests/test-motd.sh: payload hash pin refreshed; existing explicit TERM=dumb and NO_COLOR assertions kept; one new regression assertion for the missing-TERM case (must stay coloured and text-identical).

No site-specific config, no hkaz hook or date-colour work, no unrelated refactors.

Validation

Local, seconds-scale only (full MOTD suite left to CI):

  • bash -n on all three touched scripts: pass.
  • git diff --check: clean.
  • Payload extracted from both entries: byte-identical, sha256 994857572414bb1f63e0104b980e461964d9884ba9329dd61f4fd3580b493b2c, matching both pins and the test pin.
  • Guard matrix on the extracted payload with a fixed-input fixture (env -u NO_COLOR/NO_COLOR=1 as noted):
    • no TERM (Bash fallback, unexported): ANSI present, text identical to the coloured run
    • explicit TERM=dumb: no ANSI
    • NO_COLOR=1 with TERM=xterm-256color: no ANSI
    • TERM=xterm-256color: ANSI present
  • env -i PATH=... bash -c '...': TERM=dumb, attribute [] (unexported), confirming the fallback signature.

Configured-vs-behaviour caveat: the above is a local payload check, not a re-run of the full suite and not a real SSH login.

Risks

Low. The change only narrows when colour is suppressed. Terminals that explicitly receive TERM=dumb still get plain output, and NO_COLOR still wins. Servers where the payload is invoked with a genuinely exported TERM=dumb keep the previous plain behaviour.

Rollback

Revert this squash commit; the payload hash pins and the regression assertion revert with it.

Closes the colour regression only. hkaz's dated administrator hook keeps its own date-colour issue and is out of scope here.

FORGE added 2 commits December 1, 2026 07:02
Non-interactive login shells (PAM/run-parts) run the payload with no TERM.
Bash then synthesises an unexported TERM=dumb, which the previous check
read as a colourless request, so SSH PTY logins lost the palette and the
Chinese last-login line rendered without SGR.

Only an explicitly supplied TERM=dumb disables colour now: an unexported
placeholder reports no export attribute. NO_COLOR is unchanged.

Refresh both payload sha pins and add a missing-TERM regression assertion
alongside the existing explicit dumb and NO_COLOR cases.
PAM runs the payload without any hint of the client's theme, so the fixed
palette was chosen blind. In the reported light-theme login the white
last-login time sat near 1.9:1 against the surrounding background and the
fixed label colour near 1:1, which is why the panel looked washed out or
disappeared there.

Body text, labels, the prompt line, the hero divider, the progress track,
uptime units and the architecture note now use the default foreground
(SGR 39) so the terminal theme decides light or dark. Accents use only
basic ANSI indices, which each client maps onto its own palette: the host
name uses blue, the load average cyan, system version and last-login source
magenta, idle CPU model and kernel yellow, uptime numbers and healthy usage
green, and the warning states yellow and red.

Colour meaning, weight and layout are unchanged: the same fields keep their
distinct accents, and plain text output is byte-identical at 80, 60, 40 and
32 columns. The unexported-TERM fallback fix, explicit TERM=dumb and
NO_COLOR remain plain text.

Payload pins refreshed in both entries; assertions now require absence of
fixed truecolour, 256-colour and bright indices, and the last-login time
must carry no fixed RGB.
@LucaLin233
LucaLin233 merged commit 999bbac into main Nov 30, 2026
16 checks passed
@LucaLin233
LucaLin233 deleted the forge/fix-motd-pam-colors branch November 30, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant