Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion system_files/shared/etc/profile.d/uwelcome.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ if [ -e ~/.config/no-show-user-motd ]; then
mv ~/.config/no-show-user-motd ~/.config/uwelcome/disabled 2>/dev/null
fi

# Only greet a terminal: GDM starts the desktop session through a login shell,
# and uwelcome run there (no tty) asks for the portal before
# graphical-session.target is up, so xdg-desktop-portal fails its dependency
# and every portal call then waits out D-Bus's 120 s activation timeout.
# Skip for root: root shells (sudo su -, sudo -i) have no desktop session,
# and the portal lookup uwelcome makes can stall the prompt when the portal
# cannot start. Guard against double greetings when a shell chains into
# another (bash login shell starting fish): the first one wins.
if [ "$(id -u)" != "0" ] && [ -z "${UWELCOME_SHOWN-}" ]; then
if [ -t 1 ] && [ "$(id -u)" != "0" ] && [ -z "${UWELCOME_SHOWN-}" ]; then
UWELCOME_SHOWN=1
export UWELCOME_SHOWN
uwelcome
Expand Down
8 changes: 4 additions & 4 deletions tests/test_motd_integration.bats
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ teardown() {
# ---------------------------------------------------------------------------

@test "uwelcome.sh: invokes uwelcome" {
run bash "${UWELCOME_PROFILE}"
run script -qec "bash '${UWELCOME_PROFILE}'" /dev/null
[ "${status}" -eq 0 ]
[ -f "${WORKDIR}/uwelcome.log" ]
}

@test "uwelcome.sh: migrates legacy opt-out and still runs uwelcome" {
touch "${HOME}/.config/no-show-user-motd"
run bash "${UWELCOME_PROFILE}"
run script -qec "bash '${UWELCOME_PROFILE}'" /dev/null
[ "${status}" -eq 0 ]
# Legacy marker is consumed, not left behind to retry every login
[ ! -e "${HOME}/.config/no-show-user-motd" ]
Expand All @@ -75,7 +75,7 @@ teardown() {
}

@test "uwelcome.sh: is a no-op migration when no legacy marker exists" {
run bash "${UWELCOME_PROFILE}"
run script -qec "bash '${UWELCOME_PROFILE}'" /dev/null
[ "${status}" -eq 0 ]
[ ! -e "${HOME}/.config/uwelcome/disabled" ]
[ -f "${WORKDIR}/uwelcome.log" ]
Expand Down Expand Up @@ -106,7 +106,7 @@ teardown() {

@test "uwelcome.sh: skips invocation if UWELCOME_SHOWN is set" {
export UWELCOME_SHOWN=1
run bash "${UWELCOME_PROFILE}"
run script -qec "bash '${UWELCOME_PROFILE}'" /dev/null
[ "${status}" -eq 0 ]
[ ! -f "${WORKDIR}/uwelcome.log" ]
}
Expand Down
26 changes: 21 additions & 5 deletions tests/test_uwelcome_profile.bats
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ not_called() {
[ ! -f "${WORKDIR}/calls" ]
}

# The greeting only runs on a terminal, so tests that exercise the greeting
# guards run the profile under script(1), which gives it a pty.
run_tty() {
run script -qec "$1" /dev/null
}

@test "legacy no-show-user-motd marker migrates to uwelcome/disabled" {
stub_id 1000
touch "${HOME}/.config/no-show-user-motd"
Expand Down Expand Up @@ -86,7 +92,7 @@ not_called() {
stub_id 1000
unset UWELCOME_SHOWN

run bash "$UWELCOME_PROFILE"
run_tty "bash '$UWELCOME_PROFILE'"

[ "$status" -eq 0 ]
called
Expand All @@ -96,7 +102,7 @@ not_called() {
@test "uwelcome is skipped for root" {
stub_id 0

run bash "$UWELCOME_PROFILE"
run_tty "bash '$UWELCOME_PROFILE'"

[ "$status" -eq 0 ]
not_called
Expand All @@ -106,7 +112,7 @@ not_called() {
stub_id 1000
export UWELCOME_SHOWN=1

run bash "$UWELCOME_PROFILE"
run_tty "bash '$UWELCOME_PROFILE'"

[ "$status" -eq 0 ]
not_called
Expand All @@ -117,7 +123,7 @@ not_called() {
unset UWELCOME_SHOWN

# Source the profile, then start a child shell that sources it again.
run bash -c '. "$1"; bash "$1"' _ "$UWELCOME_PROFILE"
run_tty "bash -c '. \"$UWELCOME_PROFILE\"; bash \"$UWELCOME_PROFILE\"'"

[ "$status" -eq 0 ]
[ "$(wc -l < "${WORKDIR}/calls")" -eq 1 ]
Expand All @@ -138,8 +144,18 @@ not_called() {
stub_id 1000
export UWELCOME_SHOWN=""

run bash "$UWELCOME_PROFILE"
run_tty "bash '$UWELCOME_PROFILE'"

[ "$status" -eq 0 ]
called
}

@test "uwelcome is skipped without a terminal (GDM's login shell)" {
stub_id 1000
unset UWELCOME_SHOWN

run bash "$UWELCOME_PROFILE" < /dev/null > /dev/null

[ "$status" -eq 0 ]
not_called
}
Loading