From 0c9819e0a578d214cd6e6df4032bedf085066dec Mon Sep 17 00:00:00 2001 From: FORGE Date: Tue, 1 Dec 2026 07:02:19 +0800 Subject: [PATCH 1/2] fix(motd): keep colour when TERM is only Bash's unexported fallback 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. --- modules/system-customize.sh | 4 ++-- tests/test-motd.sh | 10 +++++++++- tools/setup-motd.sh | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/system-customize.sh b/modules/system-customize.sh index 53a00f2..a189efa 100644 --- a/modules/system-customize.sh +++ b/modules/system-customize.sh @@ -38,7 +38,7 @@ fi readonly MOTD_ETC_ROOT MOTD_STATE_DIR MOTD_LOCK_FILE MOTD_TRANSACTION_PARENT MOTD_TRUSTED_UID MOTD_TRUSTED_GID readonly MOTD_SCRIPT="$MOTD_ETC_ROOT/update-motd.d/00-custom-welcome" readonly MOTD_SNAPSHOT_VERSION=1 -readonly MOTD_PAYLOAD_SHA256="5c36a6d573019a7135974b199c4eeca74876d1e5bc436d910db80e1c7c2a772e" +readonly MOTD_PAYLOAD_SHA256="994857572414bb1f63e0104b980e461964d9884ba9329dd61f4fd3580b493b2c" readonly -a MOTD_TARGET_IDS=(motd issue issue_net custom_welcome uname motd_news) readonly -a MOTD_TARGET_PATHS=( "$MOTD_ETC_ROOT/motd" "$MOTD_ETC_ROOT/issue" "$MOTD_ETC_ROOT/issue.net" @@ -2301,7 +2301,7 @@ if [[ "$cpu_count" =~ ^[0-9]+$ ]] && (( cpu_count > 0 )); then fi ESC=$'\033' -if [[ -n "${NO_COLOR+x}" || "${TERM:-}" == dumb ]]; then +if [[ -n "${NO_COLOR+x}" || ( "${TERM:-}" == dumb && "${TERM@a}" == *x* ) ]]; then RESET=""; FG_RESET=""; TEXT=""; LABEL=""; DIM=""; HOST=""; RULE="" SYSTEM=""; CPU=""; ARCH=""; UPTIME=""; UPTIME_ACCENT=""; LOAD=""; TRACK="" KERNEL=""; LOGIN_SOURCE="" diff --git a/tests/test-motd.sh b/tests/test-motd.sh index a6ece78..a76f90e 100644 --- a/tests/test-motd.sh +++ b/tests/test-motd.sh @@ -251,7 +251,7 @@ extract_payload "$ROOT_DIR/tools/setup-motd.sh">"$TEST_DIR/t"; extract_payload "$ROOT_DIR/modules/system-customize.sh">"$TEST_DIR/m"; cmp -s "$TEST_DIR/t" "$TEST_DIR/m"||fail payload; pass "MOTD payloads stay identical"; -assert_eq 5c36a6d573019a7135974b199c4eeca74876d1e5bc436d910db80e1c7c2a772e "$(sha256sum "$TEST_DIR/t"|awk '{print $1}')" "payload hash" +assert_eq 994857572414bb1f63e0104b980e461964d9884ba9329dd61f4fd3580b493b2c "$(sha256sum "$TEST_DIR/t"|awk '{print $1}')" "payload hash" # 固定版式断言按显式 80 列跑,避免宿主长主机名/云内核在 40 列兜底里自然折行后误失败。 payload_output=$(COLUMNS=80 bash "$TEST_DIR/t" | sed -E $'s/\033\\[[0-9;]*m//g' | sed 's/[[:space:]]*$//'); payload_lines=$(printf '%s\n' "$payload_output" | sed '/^$/d'); @@ -428,6 +428,14 @@ dumb_out=$(env TERM=dumb COLUMNS=80 bash "$TEST_DIR/t"); [[ "$dumb_out" != *$'\033'* ]] || fail "dumb terminal still receives colour"; pass "payload skips colour on dumb terminals" +# 干净 Bash 没有收到 TERM 时会自建一个未导出的 TERM=dumb;那只是本地占位, +# 不是调用方的无色请求,必须照常输出 ANSI。只有显式传入(导出)的 TERM=dumb 才无色。 +unset_term_out=$(env -u TERM COLUMNS=80 bash "$TEST_DIR/bin-stable/motd-fixture" "$TEST_DIR/t"); +[[ "$unset_term_out" == *$'\033'* ]] || fail "missing TERM lost colour"; +unset_term_text=$(printf '%s' "$unset_term_out"|sed -E $'s/\033\[[0-9;]*m//g'); +[[ "$unset_term_text" == "$colored_text" ]] || fail "missing TERM text differs from coloured text"; +pass "payload keeps colour when TERM is absent" + mkdir "$TEST_DIR/bin-alert" cat >"$TEST_DIR/bin-alert/df"<<'DF' #!/usr/bin/env bash diff --git a/tools/setup-motd.sh b/tools/setup-motd.sh index ff9fd33..4899dab 100755 --- a/tools/setup-motd.sh +++ b/tools/setup-motd.sh @@ -24,7 +24,7 @@ fi readonly MOTD_ETC_ROOT MOTD_STATE_DIR MOTD_LOCK_FILE MOTD_TRANSACTION_PARENT MOTD_TRUSTED_UID MOTD_TRUSTED_GID readonly MOTD_SCRIPT="$MOTD_ETC_ROOT/update-motd.d/00-custom-welcome" readonly MOTD_SNAPSHOT_VERSION=1 -readonly MOTD_PAYLOAD_SHA256="5c36a6d573019a7135974b199c4eeca74876d1e5bc436d910db80e1c7c2a772e" +readonly MOTD_PAYLOAD_SHA256="994857572414bb1f63e0104b980e461964d9884ba9329dd61f4fd3580b493b2c" readonly -a MOTD_TARGET_IDS=(motd issue issue_net custom_welcome uname motd_news) readonly -a MOTD_TARGET_PATHS=( "$MOTD_ETC_ROOT/motd" "$MOTD_ETC_ROOT/issue" "$MOTD_ETC_ROOT/issue.net" @@ -2287,7 +2287,7 @@ if [[ "$cpu_count" =~ ^[0-9]+$ ]] && (( cpu_count > 0 )); then fi ESC=$'\033' -if [[ -n "${NO_COLOR+x}" || "${TERM:-}" == dumb ]]; then +if [[ -n "${NO_COLOR+x}" || ( "${TERM:-}" == dumb && "${TERM@a}" == *x* ) ]]; then RESET=""; FG_RESET=""; TEXT=""; LABEL=""; DIM=""; HOST=""; RULE="" SYSTEM=""; CPU=""; ARCH=""; UPTIME=""; UPTIME_ACCENT=""; LOAD=""; TRACK="" KERNEL=""; LOGIN_SOURCE="" From 6133c181097590cb8e08a97c692b364935d9321a Mon Sep 17 00:00:00 2001 From: FORGE Date: Tue, 1 Dec 2026 07:27:44 +0800 Subject: [PATCH 2/2] fix(motd): follow the terminal theme instead of fixed truecolour 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. --- modules/system-customize.sh | 43 ++++++++++++++------------- tests/test-motd.sh | 58 ++++++++++++++++++++++--------------- tools/setup-motd.sh | 43 ++++++++++++++------------- 3 files changed, 80 insertions(+), 64 deletions(-) diff --git a/modules/system-customize.sh b/modules/system-customize.sh index a189efa..c1ecd91 100644 --- a/modules/system-customize.sh +++ b/modules/system-customize.sh @@ -38,7 +38,7 @@ fi readonly MOTD_ETC_ROOT MOTD_STATE_DIR MOTD_LOCK_FILE MOTD_TRANSACTION_PARENT MOTD_TRUSTED_UID MOTD_TRUSTED_GID readonly MOTD_SCRIPT="$MOTD_ETC_ROOT/update-motd.d/00-custom-welcome" readonly MOTD_SNAPSHOT_VERSION=1 -readonly MOTD_PAYLOAD_SHA256="994857572414bb1f63e0104b980e461964d9884ba9329dd61f4fd3580b493b2c" +readonly MOTD_PAYLOAD_SHA256="0537c91cb69d1c3360f3302ee515528abf4ba014f018735a1dbebf6ecbcce836" readonly -a MOTD_TARGET_IDS=(motd issue issue_net custom_welcome uname motd_news) readonly -a MOTD_TARGET_PATHS=( "$MOTD_ETC_ROOT/motd" "$MOTD_ETC_ROOT/issue" "$MOTD_ETC_ROOT/issue.net" @@ -2307,31 +2307,34 @@ if [[ -n "${NO_COLOR+x}" || ( "${TERM:-}" == dumb && "${TERM@a}" == *x* ) ]]; th KERNEL=""; LOGIN_SOURCE="" SECTION=""; BOLD=""; UNBOLD=""; GREEN=""; YELLOW=""; RED="" else + # PAM 输出时拿不到终端主题提示,固定真彩色会在浅色主题上失去对比。 + # 正文、标签和普通说明用默认前景(39),由终端主题决定明暗; + # 强调项只用基本 ANSI 主题索引(30-37),让客户端映射到自己的调色板。 RESET="${ESC}[0m" FG_RESET="${ESC}[39m" - TEXT="${ESC}[38;2;248;248;242m" - LABEL="${ESC}[38;2;168;181;217m" - DIM="${ESC}[38;2;183;191;219m" - HOST="${ESC}[38;2;71;220;200m" - RULE="${ESC}[38;2;130;183;255m" - SYSTEM="${ESC}[38;2;255;142;158m" - CPU="${ESC}[38;2;255;184;108m" - ARCH="${ESC}[38;2;163;178;196m" - UPTIME="${ESC}[38;2;186;194;222m" - UPTIME_ACCENT="${ESC}[38;2;109;255;187m" - LOAD="${ESC}[38;2;36;240;208m" - KERNEL="${ESC}[38;2;255;147;77m" - LOGIN_SOURCE="${ESC}[38;2;255;121;198m" - TRACK="${ESC}[38;2;83;91;120m" - SECTION="${ESC}[38;2;98;114;164m" + TEXT="${ESC}[39m" + LABEL="${ESC}[39m" + DIM="${ESC}[39m" + HOST="${ESC}[34m" + RULE="${ESC}[39m" + SYSTEM="${ESC}[35m" + CPU="${ESC}[33m" + ARCH="${ESC}[39m" + UPTIME="${ESC}[39m" + UPTIME_ACCENT="${ESC}[32m" + LOAD="${ESC}[36m" + KERNEL="${ESC}[33m" + LOGIN_SOURCE="${ESC}[35m" + TRACK="${ESC}[39m" + SECTION="${ESC}[39m" BOLD="${ESC}[1m" UNBOLD="${ESC}[22m" - GREEN="${ESC}[38;2;80;250;123m" - YELLOW="${ESC}[38;2;241;250;140m" - RED="${ESC}[38;5;203m" + GREEN="${ESC}[32m" + YELLOW="${ESC}[33m" + RED="${ESC}[31m" fi -# 运行时长:数字用强调色加粗,单位沿用灰蓝且显式退出粗体,避免继承前缀的字重。 +# 运行时长:数字用强调色加粗,单位用默认前景且显式退出粗体,避免继承前缀的字重。 uptime_segments=() for uptime_part in "${uptime_parts[@]}"; do case "${uptime_part%%|*}" in diff --git a/tests/test-motd.sh b/tests/test-motd.sh index a76f90e..c8f9f30 100644 --- a/tests/test-motd.sh +++ b/tests/test-motd.sh @@ -251,7 +251,7 @@ extract_payload "$ROOT_DIR/tools/setup-motd.sh">"$TEST_DIR/t"; extract_payload "$ROOT_DIR/modules/system-customize.sh">"$TEST_DIR/m"; cmp -s "$TEST_DIR/t" "$TEST_DIR/m"||fail payload; pass "MOTD payloads stay identical"; -assert_eq 994857572414bb1f63e0104b980e461964d9884ba9329dd61f4fd3580b493b2c "$(sha256sum "$TEST_DIR/t"|awk '{print $1}')" "payload hash" +assert_eq 0537c91cb69d1c3360f3302ee515528abf4ba014f018735a1dbebf6ecbcce836 "$(sha256sum "$TEST_DIR/t"|awk '{print $1}')" "payload hash" # 固定版式断言按显式 80 列跑,避免宿主长主机名/云内核在 40 列兜底里自然折行后误失败。 payload_output=$(COLUMNS=80 bash "$TEST_DIR/t" | sed -E $'s/\033\\[[0-9;]*m//g' | sed 's/[[:space:]]*$//'); payload_lines=$(printf '%s\n' "$payload_output" | sed '/^$/d'); @@ -260,7 +260,7 @@ assert_eq '│ 今天想做点什么?' "$(printf '%s\n' "$payload_lines" | sed assert_eq "$(printf '─%.0s' {1..38})" "$(printf '%s\n' "$payload_lines" | sed -n '3p')" "payload hero divider"; assert_eq '系统,运行,CPU,负载,内存,根盘,内核' "$(printf '%s\n' "$payload_lines" | sed -n '4,10p' | awk '{printf "%s%s", sep, $1; sep=","}')" "payload info order"; assert_eq 10 "$(printf '%s\n' "$payload_lines" | wc -l)" "payload panel line count"; -! COLUMNS=80 bash "$TEST_DIR/t" | grep -qF $'\033[48;5;' || fail "payload must not paint a background"; +! COLUMNS=80 bash "$TEST_DIR/t" | grep -qF $'\033[48;' || fail "payload must not paint a background"; raw_title=$(COLUMNS=80 bash "$TEST_DIR/t" | sed '/^$/d' | sed -n '1p'); [[ "$raw_title" == *$'\033[0m' ]] || fail "payload title must end with a full reset"; [[ "$raw_title" != *$'\033[39m' ]] || fail "payload title must not end with foreground-only reset"; @@ -278,20 +278,29 @@ done ! printf '%s\n' "$payload_lines" | sed -n '4p' | grep -q '●' || fail "system line must not keep the green dot"; assert_eq " 内核 $(uname -r)($(uname -m))" "$(printf '%s\n' "$payload_lines" | sed -n '10p')" "payload kernel arch"; pass "payload bars limited to memory and root disk"; -# 定稿配色:主机名、系统版本、负载、标签、内核、架构,以及内存/根盘的正常态绿色。 -hero_raw=$(COLUMNS=80 bash "$TEST_DIR/t" | sed '/^$/d' | sed -n '1p'); -[[ "$hero_raw" == *$'\033[38;2;71;220;200m'*"$(hostname)"* ]] || fail "hostname must use #47DCC8"; -system_raw=$(COLUMNS=80 bash "$TEST_DIR/t" | sed '/^$/d' | sed -n '4p'); -[[ "$system_raw" == *$'\033[38;2;255;142;158m'*$'\033[1m'* ]] || fail "system version must be bold #FF8E9E"; +# 主题自适应配色:PAM 输出没有终端主题提示,正文/标签/普通说明继承默认前景, +# 强调项只用基本 ANSI 索引,由客户端主题决定明暗。固定的 256 色或真彩色会在浅色背景上消失。 +theme_raw=$(COLUMNS=80 bash "$TEST_DIR/t" | sed '/^$/d'); +# 用计数断言而不是 `grep -q` 管道:`-q` 提前关闭管道可能触发 SIGPIPE,让禁用项静默通过。 +assert_eq 0 "$(printf '%s\n' "$theme_raw" | grep -cF $'\033[38;' || true)" "payload must not use fixed truecolour or 256-colour foregrounds"; +assert_eq 0 "$(printf '%s\n' "$theme_raw" | grep -cE $'\033\[(9[0-7]|10[0-7])m' || true)" "payload must not use bright colour indices"; +hero_raw=$(printf '%s\n' "$theme_raw" | sed -n '1p'); +[[ "$hero_raw" == *$'\033[34m'*"$(hostname)"* ]] || fail "hostname must use theme blue"; +[[ "$hero_raw" == *$'\033[39m欢迎登录 '* ]] || fail "welcome text must inherit the default foreground"; +system_raw=$(printf '%s\n' "$theme_raw" | sed -n '4p'); +[[ "$system_raw" == *$'\033[35m'*$'\033[1m'* ]] || fail "system version must be bold theme magenta"; [[ "$system_raw" != *'●'* ]] || fail "system line must not carry the status dot"; -[[ "$system_raw" == *$'\033[38;2;168;181;217m系统'* ]] || fail "labels must use #A8B5D9"; -load_raw=$(COLUMNS=80 bash "$TEST_DIR/t" | sed '/^$/d' | sed -n '7p'); -[[ "$load_raw" == *$'\033[38;2;36;240;208m'* ]] || fail "load must use #24F0D0"; -kernel_raw_check=$(COLUMNS=80 bash "$TEST_DIR/t" | sed '/^$/d' | sed -n '10p'); -[[ "$kernel_raw_check" == *$'\033[38;2;255;147;77m'*$'\033[1m'*"$(uname -r)"* ]] || fail "kernel must be bold #FF934D"; -[[ "$kernel_raw_check" == *$'\033[22m'*$'\033[38;2;163;178;196m('* ]] || fail "architecture must be #A3B2C4 and leave the bold run"; -grep -qF 'GREEN="${ESC}[38;2;80;250;123m"' "$TEST_DIR/t" || fail "healthy memory/disk colour must stay #50FA7B"; -pass "payload adopts the approved log palette" +[[ "$system_raw" == *$'\033[39m系统'* ]] || fail "labels must inherit the default foreground"; +load_raw=$(printf '%s\n' "$theme_raw" | sed -n '7p'); +[[ "$load_raw" == *$'\033[36m'* ]] || fail "load must use theme cyan"; +kernel_raw_check=$(printf '%s\n' "$theme_raw" | sed -n '10p'); +[[ "$kernel_raw_check" == *$'\033[33m'*$'\033[1m'*"$(uname -r)"* ]] || fail "kernel must be bold theme yellow"; +[[ "$kernel_raw_check" == *$'\033[22m'*$'\033[39m('* ]] || fail "architecture must inherit the default foreground and leave the bold run"; +hero_rule_raw=$(printf '%s\n' "$theme_raw" | sed -n '3p'); +[[ "$hero_rule_raw" == $'\033[39m'* ]] || fail "hero divider must inherit the default foreground"; +grep -qF 'GREEN="${ESC}[32m"' "$TEST_DIR/t" || fail "healthy memory/disk colour must use theme green"; +grep -qF 'TRACK="${ESC}[39m"' "$TEST_DIR/t" || fail "progress track must inherit the default foreground"; +pass "payload follows the terminal theme instead of fixed colours" mkdir "$TEST_DIR/bin-accent" cat >"$TEST_DIR/bin-accent/motd-fixture"<<'FIXTURE' #!/usr/bin/env bash @@ -308,8 +317,8 @@ chmod 0700 "$TEST_DIR/bin-accent/motd-fixture"; uptime_out=$(COLUMNS=80 bash "$TEST_DIR/bin-accent/motd-fixture" "$TEST_DIR/t"); uptime_raw=$(printf '%s\n' "$uptime_out" | sed '/^$/d' | sed -n '5p'); payload_lines_stable=$(printf '%s\n' "$uptime_out" | sed -E $'s/\033\[[0-9;]*m//g' | sed 's/[[:space:]]*$//' | sed '/^$/d'); -[[ "$uptime_raw" == *$'\033[38;2;109;255;187m'*$'\033[1m1'* ]] || fail "uptime numbers must be bold #6DFFBB"; -[[ "$uptime_raw" == *$'\033[22m'*$'\033[38;2;186;194;222m 天'* ]] || fail "uptime units must leave bold and stay #BAC2DE"; +[[ "$uptime_raw" == *$'\033[32m'*$'\033[1m1'* ]] || fail "uptime numbers must be bold theme green"; +[[ "$uptime_raw" == *$'\033[22m'*$'\033[39m 天'* ]] || fail "uptime units must leave bold and inherit the default foreground"; assert_eq ' 运行 1 天 1 小时' "$(printf '%s\n' "$payload_lines_stable" | sed -n '5p')" "uptime text stays byte-identical"; pass "payload accent-colours uptime numbers only" mkdir "$TEST_DIR/bin-vm" "$TEST_DIR/bin-physical" @@ -326,10 +335,10 @@ cpu_line(){ COLUMNS=80 PATH="$1:$PATH" bash "$TEST_DIR/t"|sed -E $'s/\033\\[[0-9 assert_eq ' CPU Example EPYC(8 vCPU)' "$(cpu_line "$TEST_DIR/bin-vm")" "payload vm cpu label"; assert_eq ' CPU Example EPYC(16 核 32 线程)' "$(cpu_line "$TEST_DIR/bin-physical")" "payload physical cpu label"; cpu_raw=$(COLUMNS=80 PATH="$TEST_DIR/bin-vm:$PATH" bash "$TEST_DIR/t" | sed '/^$/d' | sed -n '6p'); -[[ "$cpu_raw" == *$'\033[38;2;255;184;108mExample EPYC'* ]] || fail "cpu model highlight color"; -[[ "$cpu_raw" == *$'\033[38;2;248;248;242m(8 vCPU)'* ]] || fail "cpu count normal color"; +[[ "$cpu_raw" == *$'\033[33mExample EPYC'* ]] || fail "cpu model must use theme yellow"; +[[ "$cpu_raw" == *$'\033[39m(8 vCPU)'* ]] || fail "cpu count must inherit the default foreground"; kernel_raw=$(COLUMNS=80 bash "$TEST_DIR/t" | sed '/^$/d' | sed -n '10p'); -[[ "$kernel_raw" == *$'\033[38;2;163;178;196m('* ]] || fail "architecture color"; +[[ "$kernel_raw" == *$'\033[39m('* ]] || fail "architecture must inherit the default foreground"; pass "payload cpu and architecture colors" # 独立宽度判据:直接用 coreutils 在 UTF-8 locale 下的 wc -L 计算显示列宽, @@ -446,7 +455,7 @@ esac DF chmod 0700 "$TEST_DIR/bin-alert/df"; alert_raw=$(COLUMNS=80 PATH="$TEST_DIR/bin-alert:$PATH" bash "$TEST_DIR/t"); -printf '%s\n' "$alert_raw"|sed -n '/根盘/p'|grep -qF $'\033[38;5;203m' || fail "critical disk usage must use the red warning colour"; +printf '%s\n' "$alert_raw"|sed -n '/根盘/p'|grep -qF $'\033[31m' || fail "critical disk usage must use theme red"; pass "payload marks critical usage with the red warning colour" mkdir "$TEST_DIR/bin-warn" @@ -459,7 +468,7 @@ esac DF chmod 0700 "$TEST_DIR/bin-warn/df"; warn_raw=$(COLUMNS=80 PATH="$TEST_DIR/bin-warn:$PATH" bash "$TEST_DIR/t"); -printf '%s\n' "$warn_raw"|sed -n '/根盘/p'|grep -qF $'\033[38;2;241;250;140m' || fail "high disk usage must use the yellow warning colour"; +printf '%s\n' "$warn_raw"|sed -n '/根盘/p'|grep -qF $'\033[33m' || fail "high disk usage must use theme yellow"; pass "payload marks high usage with the yellow warning colour" mkdir "$TEST_DIR/bin-cjk" @@ -1658,8 +1667,9 @@ login_payload() { COLUMNS=80 PAM_USER="$1" PATH="$TEST_DIR/login-bin:$PATH" bash out=$(login_payload root); plain=$(printf '%s' "$out" | sed -E $'s/\033\\[[0-9;]*m//g') [[ "$plain" == *'上次登录 2026-12-01 03:25:52'* ]] || fail "IPv6 last-login time line" [[ "$plain" == *'来源 IP 2001:db8::42'* ]] || fail "IPv6 source uses 来源 IP" - [[ "$out" == *$'\033[38;2;248;248;242m2026-12-01 03:25:52'* ]] || fail "last-login time must be #F8F8F2" - [[ "$out" == *$'\033[38;2;255;121;198m2001:db8::42'* ]] || fail "source must be #FF79C6" + [[ "$out" == *$'\033[39m2026-12-01 03:25:52'* ]] || fail "last-login time must inherit the default foreground" + [[ "$out" != *$'\033[38;'* ]] || fail "last-login must not carry a fixed RGB foreground" + [[ "$out" == *$'\033[35m2001:db8::42'* ]] || fail "source must use theme magenta" ! printf '%s' "$plain" | grep -q '欢迎登录\|系统 \|内核' || fail "--last-login must not repeat the welcome panel" pass "IPv4/IPv6 time and source render in the approved colours" ) diff --git a/tools/setup-motd.sh b/tools/setup-motd.sh index 4899dab..5cc849a 100755 --- a/tools/setup-motd.sh +++ b/tools/setup-motd.sh @@ -24,7 +24,7 @@ fi readonly MOTD_ETC_ROOT MOTD_STATE_DIR MOTD_LOCK_FILE MOTD_TRANSACTION_PARENT MOTD_TRUSTED_UID MOTD_TRUSTED_GID readonly MOTD_SCRIPT="$MOTD_ETC_ROOT/update-motd.d/00-custom-welcome" readonly MOTD_SNAPSHOT_VERSION=1 -readonly MOTD_PAYLOAD_SHA256="994857572414bb1f63e0104b980e461964d9884ba9329dd61f4fd3580b493b2c" +readonly MOTD_PAYLOAD_SHA256="0537c91cb69d1c3360f3302ee515528abf4ba014f018735a1dbebf6ecbcce836" readonly -a MOTD_TARGET_IDS=(motd issue issue_net custom_welcome uname motd_news) readonly -a MOTD_TARGET_PATHS=( "$MOTD_ETC_ROOT/motd" "$MOTD_ETC_ROOT/issue" "$MOTD_ETC_ROOT/issue.net" @@ -2293,31 +2293,34 @@ if [[ -n "${NO_COLOR+x}" || ( "${TERM:-}" == dumb && "${TERM@a}" == *x* ) ]]; th KERNEL=""; LOGIN_SOURCE="" SECTION=""; BOLD=""; UNBOLD=""; GREEN=""; YELLOW=""; RED="" else + # PAM 输出时拿不到终端主题提示,固定真彩色会在浅色主题上失去对比。 + # 正文、标签和普通说明用默认前景(39),由终端主题决定明暗; + # 强调项只用基本 ANSI 主题索引(30-37),让客户端映射到自己的调色板。 RESET="${ESC}[0m" FG_RESET="${ESC}[39m" - TEXT="${ESC}[38;2;248;248;242m" - LABEL="${ESC}[38;2;168;181;217m" - DIM="${ESC}[38;2;183;191;219m" - HOST="${ESC}[38;2;71;220;200m" - RULE="${ESC}[38;2;130;183;255m" - SYSTEM="${ESC}[38;2;255;142;158m" - CPU="${ESC}[38;2;255;184;108m" - ARCH="${ESC}[38;2;163;178;196m" - UPTIME="${ESC}[38;2;186;194;222m" - UPTIME_ACCENT="${ESC}[38;2;109;255;187m" - LOAD="${ESC}[38;2;36;240;208m" - KERNEL="${ESC}[38;2;255;147;77m" - LOGIN_SOURCE="${ESC}[38;2;255;121;198m" - TRACK="${ESC}[38;2;83;91;120m" - SECTION="${ESC}[38;2;98;114;164m" + TEXT="${ESC}[39m" + LABEL="${ESC}[39m" + DIM="${ESC}[39m" + HOST="${ESC}[34m" + RULE="${ESC}[39m" + SYSTEM="${ESC}[35m" + CPU="${ESC}[33m" + ARCH="${ESC}[39m" + UPTIME="${ESC}[39m" + UPTIME_ACCENT="${ESC}[32m" + LOAD="${ESC}[36m" + KERNEL="${ESC}[33m" + LOGIN_SOURCE="${ESC}[35m" + TRACK="${ESC}[39m" + SECTION="${ESC}[39m" BOLD="${ESC}[1m" UNBOLD="${ESC}[22m" - GREEN="${ESC}[38;2;80;250;123m" - YELLOW="${ESC}[38;2;241;250;140m" - RED="${ESC}[38;5;203m" + GREEN="${ESC}[32m" + YELLOW="${ESC}[33m" + RED="${ESC}[31m" fi -# 运行时长:数字用强调色加粗,单位沿用灰蓝且显式退出粗体,避免继承前缀的字重。 +# 运行时长:数字用强调色加粗,单位用默认前景且显式退出粗体,避免继承前缀的字重。 uptime_segments=() for uptime_part in "${uptime_parts[@]}"; do case "${uptime_part%%|*}" in