Skip to content

Commit fc892c5

Browse files
authored
doctor: clarify non-root inconclusive checks (#57)
1 parent dbc925f commit fc892c5

3 files changed

Lines changed: 62 additions & 9 deletions

File tree

bin/doctor.sh

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,22 @@ BAUDBOT_HOME="/home/baudbot_agent"
1919
PASS=0
2020
FAIL=0
2121
WARN=0
22+
IS_ROOT=0
23+
if [ "$(id -u)" -eq 0 ]; then
24+
IS_ROOT=1
25+
fi
2226

2327
pass() { echo "$1"; PASS=$((PASS + 1)); }
2428
fail() { echo "$1"; FAIL=$((FAIL + 1)); }
2529
warn() { echo "$1"; WARN=$((WARN + 1)); }
2630

2731
echo "Baudbot Doctor"
2832
echo ""
33+
if [ "$IS_ROOT" -ne 1 ]; then
34+
echo "ℹ Running without root: some checks may be inconclusive."
35+
echo " For full accuracy, run: sudo baudbot doctor"
36+
echo ""
37+
fi
2938

3039
# ── User ─────────────────────────────────────────────────────────────────────
3140

@@ -135,7 +144,11 @@ if [ -f "$ENV_FILE" ]; then
135144
fi
136145
done
137146
else
138-
fail ".env not found at $ENV_FILE"
147+
if [ "$IS_ROOT" -ne 1 ] && [ -d "$BAUDBOT_HOME/.config" ]; then
148+
warn "cannot verify agent .env as non-root (run: sudo baudbot doctor)"
149+
else
150+
fail ".env not found at $ENV_FILE"
151+
fi
139152
fi
140153

141154
# ── Runtime ──────────────────────────────────────────────────────────────────
@@ -146,26 +159,42 @@ echo "Runtime:"
146159
if [ -f "$BAUDBOT_HOME/runtime/start.sh" ]; then
147160
pass "start.sh deployed"
148161
else
149-
fail "start.sh not found (run: baudbot deploy)"
162+
if [ "$IS_ROOT" -ne 1 ] && [ -d "$BAUDBOT_HOME/runtime" ]; then
163+
warn "cannot verify start.sh as non-root (run: sudo baudbot doctor)"
164+
else
165+
fail "start.sh not found (run: baudbot deploy)"
166+
fi
150167
fi
151168

152169
if [ -d "$BAUDBOT_HOME/.pi/agent/extensions" ]; then
153170
EXT_COUNT=$(find "$BAUDBOT_HOME/.pi/agent/extensions" -maxdepth 1 -name '*.ts' -o -name '*.mjs' 2>/dev/null | wc -l)
154171
pass "extensions deployed ($EXT_COUNT files)"
155172
else
156-
fail "extensions not deployed (run: baudbot deploy)"
173+
if [ "$IS_ROOT" -ne 1 ] && [ -d "$BAUDBOT_HOME" ]; then
174+
warn "cannot verify extensions as non-root (run: sudo baudbot doctor)"
175+
else
176+
fail "extensions not deployed (run: baudbot deploy)"
177+
fi
157178
fi
158179

159180
if [ -d "$BAUDBOT_HOME/.pi/agent/skills" ]; then
160181
pass "skills deployed"
161182
else
162-
fail "skills not deployed (run: baudbot deploy)"
183+
if [ "$IS_ROOT" -ne 1 ] && [ -d "$BAUDBOT_HOME" ]; then
184+
warn "cannot verify skills as non-root (run: sudo baudbot doctor)"
185+
else
186+
fail "skills not deployed (run: baudbot deploy)"
187+
fi
163188
fi
164189

165190
if [ -d "$BAUDBOT_HOME/runtime/slack-bridge" ] && [ -f "$BAUDBOT_HOME/runtime/slack-bridge/bridge.mjs" ]; then
166191
pass "slack bridge deployed"
167192
else
168-
fail "slack bridge not deployed (run: baudbot deploy)"
193+
if [ "$IS_ROOT" -ne 1 ] && [ -d "$BAUDBOT_HOME/runtime" ]; then
194+
warn "cannot verify slack bridge files as non-root (run: sudo baudbot doctor)"
195+
else
196+
fail "slack bridge not deployed (run: baudbot deploy)"
197+
fi
169198
fi
170199

171200
# ── Security ─────────────────────────────────────────────────────────────────
@@ -178,7 +207,11 @@ if command -v iptables &>/dev/null && iptables -w -L BAUDBOT_OUTPUT -n &>/dev/nu
178207
RULE_COUNT=$(iptables -w -L BAUDBOT_OUTPUT -n 2>/dev/null | tail -n +3 | wc -l)
179208
pass "firewall active ($RULE_COUNT rules)"
180209
else
181-
warn "firewall not active (run: baudbot setup)"
210+
if command -v iptables &>/dev/null && [ "$IS_ROOT" -ne 1 ]; then
211+
warn "cannot verify firewall as non-root (run: sudo baudbot doctor)"
212+
else
213+
warn "firewall not active (run: baudbot setup)"
214+
fi
182215
fi
183216

184217
# /proc hidepid
@@ -214,7 +247,11 @@ if [ -f "$TOOL_GUARD" ]; then
214247
fi
215248
fi
216249
else
217-
fail "tool-guard.ts not found"
250+
if [ "$IS_ROOT" -ne 1 ] && [ -d "$BAUDBOT_HOME" ]; then
251+
warn "cannot verify tool-guard.ts as non-root (run: sudo baudbot doctor)"
252+
else
253+
fail "tool-guard.ts not found"
254+
fi
218255
fi
219256

220257
# ── Agent Status ─────────────────────────────────────────────────────────────
@@ -223,13 +260,20 @@ echo ""
223260
echo "Agent:"
224261

225262
if command -v systemctl &>/dev/null && [ -d /run/systemd/system ]; then
226-
if systemctl is-enabled baudbot &>/dev/null 2>&1; then
263+
enabled_state=$(systemctl is-enabled baudbot 2>&1 || true)
264+
if [ "$enabled_state" = "enabled" ]; then
227265
pass "systemd unit enabled"
228-
if systemctl is-active baudbot &>/dev/null 2>&1; then
266+
267+
active_state=$(systemctl is-active baudbot 2>&1 || true)
268+
if [ "$active_state" = "active" ]; then
229269
pass "agent is running (systemd)"
270+
elif [ "$IS_ROOT" -ne 1 ] && echo "$active_state" | grep -qiE 'access denied|not authorized|interactive authentication|required'; then
271+
warn "cannot verify agent runtime as non-root (run: sudo baudbot doctor)"
230272
else
231273
warn "agent is not running"
232274
fi
275+
elif [ "$IS_ROOT" -ne 1 ] && echo "$enabled_state" | grep -qiE 'access denied|not authorized|interactive authentication|required'; then
276+
warn "cannot verify systemd unit state as non-root (run: sudo baudbot doctor)"
233277
else
234278
warn "systemd unit not installed (run: baudbot setup)"
235279
fi

bin/update-release.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ publish_release() {
256256
if [ -d "$RELEASE_DIR" ]; then
257257
log "release already exists: $RELEASE_DIR"
258258
verify_git_free_release "$RELEASE_DIR" || die "existing release contains .git: $RELEASE_DIR"
259+
# Ensure the top-level release directory is traversable by non-root users
260+
# so /usr/local/bin/baudbot remains discoverable on PATH.
261+
chmod a+rx "$RELEASE_DIR" 2>/dev/null || true
259262
return 0
260263
fi
261264

@@ -277,6 +280,10 @@ publish_release() {
277280
# Keep directories writable for release pruning/cleanup workflows.
278281
find "$STAGING_DIR" -type f -exec chmod a-w {} +
279282

283+
# Ensure release root is traversable by non-root users so the global
284+
# /usr/local/bin/baudbot symlink can be resolved from PATH.
285+
chmod a+rx "$STAGING_DIR"
286+
280287
mv "$STAGING_DIR" "$RELEASE_DIR"
281288
STAGING_DIR=""
282289
}

bin/update-release.test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ test_publish_git_free_release() {
107107

108108
[ "$current_target" = "$release_root/releases/$sha" ]
109109
[ -f "$current_target/baudbot-release.json" ]
110+
# Release root must be traversable so /usr/local/bin/baudbot is discoverable.
111+
[ "$(stat -c '%a' "$current_target")" = "755" ]
110112
assert_no_git_dirs "$release_root/releases"
111113
)
112114
}

0 commit comments

Comments
 (0)