Skip to main content

max / alloy

Read the user's configuration, not root's, when the run is privileged
Author: Max Johnson <me@maxj.phd> · 2026-09-03 19:58 UTC
Signed with PGP, not checked
Commit: 7d659fa16437284d34a1ee4e7690d463e3900511
Parent: ab85258
1 file changed, +22 insertions, -7 deletions
@@ -60,6 +60,14 @@
60 60
61 61 have() { command -v "$1" >/dev/null 2>&1; }
62 62 is_root() { [ "$(id -u)" -eq 0 ]; }
63 +
64 + # The user whose configuration is being asked about, which is not root even
65 + # when the run is. sudo leaves HOME=/root, so a row that reads $HOME asks
66 + # whether root has a sway config and answers no on a machine that is correctly
67 + # set up. That is how the privileged run on fw12 reported zero screenshot binds
68 + # on 2026-09-03 while the unprivileged one found all four.
69 + target_user() { echo "${SUDO_USER:-$(id -un)}"; }
70 + target_home() { getent passwd "$(target_user)" 2>/dev/null | cut -d: -f6; }
63 71 # A graphical session is not reachable over a plain ssh connection, which is
64 72 # how this script is usually run. Rows that need one skip rather than fail.
65 73 has_session() { [ -n "${WAYLAND_DISPLAY:-}" ] && have swaymsg; }
@@ -125,7 +133,7 @@
125 133 if has_session; then
126 134 binds="$(swaymsg -t get_config 2>/dev/null | grep -c 'exec alloy-shot')"
127 135 else
128 - binds="$(grep -c 'exec alloy-shot' "${HOME}/.config/sway/config" 2>/dev/null || echo 0)"
136 + binds="$(grep -c 'exec alloy-shot' "$(target_home)/.config/sway/config" 2>/dev/null || echo 0)"
129 137 fi
130 138 if [ "${binds:-0}" -ge 4 ]; then
131 139 row PASS shot-binds "$binds alloy-shot binds, and the binary resolves"
@@ -199,13 +207,20 @@
199 207 # ------------------------------------------------------------ export wrapper --
200 208 # `alloy pkg` writes per-box wrappers under ~/.local/bin. A wrapper that is not
201 209 # on PATH is the failure that looks like nothing at all.
202 - if [ -d "$HOME/.local/bin" ]; then
203 - case ":$PATH:" in
204 - *":$HOME/.local/bin:"*) row PASS export-path "~/.local/bin exists and is on PATH" ;;
205 - *) row FAIL export-path "~/.local/bin exists and is NOT on PATH, so every exported wrapper is invisible" ;;
206 - esac
207 - else
210 + # The directory belongs to the user being checked; the PATH being searched
211 + # belongs to whoever is running this. Under sudo those are different people, so
212 + # the second half is not answerable and says so rather than reporting root's
213 + # PATH as if it were the user's.
214 + export_dir="$(target_home)/.local/bin"
215 + if [ ! -d "$export_dir" ]; then
208 216 row SKIP export-path "nothing has been exported on this machine yet"
217 + elif is_root && [ -n "${SUDO_USER:-}" ]; then
218 + row SKIP export-path "$export_dir exists; whether it is on $(target_user)'s PATH cannot be read from a root shell"
219 + else
220 + case ":$PATH:" in
221 + *":$export_dir:"*) row PASS export-path "$export_dir exists and is on PATH" ;;
222 + *) row FAIL export-path "$export_dir exists and is NOT on PATH, so every exported wrapper is invisible" ;;
223 + esac
209 224 fi
210 225
211 226 # ------------------------------------------------------------------- fonts ---