Skip to content
Merged
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
22 changes: 18 additions & 4 deletions bin/baudbot
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ case "${1:-}" in

status)
shift
if has_systemd && systemctl is-enabled baudbot &>/dev/null 2>&1; then
if has_systemd && systemctl is-enabled baudbot &>/dev/null; then
exec systemctl status baudbot "$@"
else
# Fallback: check if baudbot_agent has pi running
Expand All @@ -138,7 +138,7 @@ case "${1:-}" in

logs)
shift
if has_systemd && systemctl is-enabled baudbot &>/dev/null 2>&1; then
if has_systemd && systemctl is-enabled baudbot &>/dev/null; then
exec journalctl -u baudbot -f "$@"
else
echo "No systemd unit. Check tmux sessions:"
Expand Down Expand Up @@ -254,14 +254,28 @@ case "${1:-}" in

update)
shift
# For now: git pull + deploy
require_root "update"
echo "=== Pulling latest ==="
cd "$BAUDBOT_ROOT"
git pull origin main
echo ""
echo "=== Deploying ==="
exec "$BAUDBOT_ROOT/bin/deploy.sh" "$@"
"$BAUDBOT_ROOT/bin/deploy.sh" "$@"
echo ""
# Restart if currently running
if has_systemd && systemctl is-active baudbot &>/dev/null; then
echo "=== Restarting ==="
systemctl restart baudbot
# Wait for ExecStartPre hooks + process init
sleep 3
if systemctl is-active baudbot &>/dev/null; then
echo "✅ Updated and running"
else
echo "⚠️ Deployed but agent didn't restart — check: baudbot logs"
fi
else
echo "✅ Updated. Start with: sudo baudbot start"
fi
;;

uninstall)
Expand Down
14 changes: 12 additions & 2 deletions bin/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,18 @@ fi
echo "Deploying config..."

# Determine who invoked this (the admin user)
# BAUDBOT_CONFIG_USER env var overrides detection (used by install.sh)
DEPLOY_USER="${BAUDBOT_CONFIG_USER:-${SUDO_USER:-$(whoami)}}"
# Priority: BAUDBOT_CONFIG_USER env > SUDO_USER > repo owner > whoami
if [ -n "${BAUDBOT_CONFIG_USER:-}" ]; then
DEPLOY_USER="$BAUDBOT_CONFIG_USER"
elif [ -n "${SUDO_USER:-}" ] && [ "${SUDO_USER:-}" != "root" ]; then
DEPLOY_USER="$SUDO_USER"
else
# Detect from repo ownership (the admin owns the source)
DEPLOY_USER=$(stat -c '%U' "$BAUDBOT_SRC" 2>/dev/null || echo "")
if [ -z "$DEPLOY_USER" ] || [ "$DEPLOY_USER" = "root" ]; then
DEPLOY_USER="$(whoami)"
fi
fi
DEPLOY_HOME=$(getent passwd "$DEPLOY_USER" | cut -d: -f6 2>/dev/null || echo "")
ADMIN_CONFIG="$DEPLOY_HOME/.baudbot/.env"

Expand Down