-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
117 lines (97 loc) · 5.19 KB
/
Copy pathdeploy.sh
File metadata and controls
117 lines (97 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
# deploy.sh — Sync project to Pi, restart TARS, tail the log.
#
# Usage:
# ./deploy.sh # deploy and tail log
# ./deploy.sh --no-tail # deploy and restart, don't tail
# ./deploy.sh --stop # stop TARS without redeploying
#
# Prerequisites:
# - SSH key auth configured: ssh-copy-id pi@tars.local
# - tmux installed on Pi: sudo apt-get install tmux
# - TARS_HOST set below
set -euo pipefail
# ── Configure this ──────────────────────────────────────────────────────────
TARS_HOST="${TARS_HOST:-pi@192.168.0.20}" # override with: TARS_HOST=pi@192.168.1.42 ./deploy.sh
REMOTE_DIR="~/tars-mini"
TMUX_SESSION="tars"
LOG_FILE="$REMOTE_DIR/tars.log"
VENV_PYTHON="$REMOTE_DIR/.venv/bin/python"
# ────────────────────────────────────────────────────────────────────────────
# Colours
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
info() { echo -e "${GREEN}[deploy]${NC} $*"; }
warn() { echo -e "${YELLOW}[deploy]${NC} $*"; }
die() { echo -e "${RED}[deploy] ERROR:${NC} $*" >&2; exit 1; }
# ── --stop shortcut ──────────────────────────────────────────────────────────
if [[ "${1:-}" == "--stop" ]]; then
info "Stopping TARS on $TARS_HOST…"
ssh "$TARS_HOST" "pkill -f tars_pi.py || true; tmux kill-session -t $TMUX_SESSION 2>/dev/null || true"
info "Stopped."
exit 0
fi
# ── Verify SSH reachable ─────────────────────────────────────────────────────
info "Checking SSH connection to $TARS_HOST…"
ssh -o ConnectTimeout=5 "$TARS_HOST" "echo ok" > /dev/null \
|| die "Cannot reach $TARS_HOST. Check hostname/IP and SSH key auth."
# ── Create remote directory ──────────────────────────────────────────────────
info "Ensuring $REMOTE_DIR exists on Pi…"
ssh "$TARS_HOST" "mkdir -p $REMOTE_DIR"
# ── Sync files ───────────────────────────────────────────────────────────────
# Note: rsync is unavailable on this Windows machine (Git Bash); using scp instead.
info "Syncing files to $TARS_HOST:$REMOTE_DIR…"
for f in tars_pi.py requirements_pi.txt deploy.sh CLAUDE.md; do
[[ -f "$f" ]] && scp -q "$f" "$TARS_HOST:$REMOTE_DIR/$f"
done
info "Sync complete."
# ── Install/update Python deps if requirements.txt changed ───────────────────
info "Checking Python venv…"
ssh "$TARS_HOST" bash << 'REMOTE'
set -e
cd ~/tars-mini
# Ensure portaudio is installed (needed for pyaudio to build)
if ! dpkg -l portaudio19-dev &>/dev/null; then
echo "[pi] Installing portaudio19-dev…"
sudo apt-get install -y portaudio19-dev -q
fi
# Use system python3 (3.5, has SSL) not the custom-built 3.11 (no SSL)
PYTHON=/usr/bin/python3
if [ ! -f .venv/bin/python ]; then
echo "[pi] Creating virtual environment…"
# --system-site-packages: inherit python3-pyaudio from apt (pip can't use SSL on this OS)
$PYTHON -m venv --system-site-packages .venv
fi
echo "[pi] Verifying pyaudio is available…"
.venv/bin/python -c "import pyaudio; print('[pi] pyaudio', pyaudio.__version__, 'OK')"
echo "[pi] Dependencies OK."
REMOTE
# ── Stop existing TARS process ───────────────────────────────────────────────
info "Stopping any running TARS process…"
ssh "$TARS_HOST" "pkill -f tars_pi.py 2>/dev/null || true; sleep 1"
# ── Start TARS Pi client in a tmux session ───────────────────────────────────
info "Starting TARS Pi client in tmux session '$TMUX_SESSION'…"
ssh "$TARS_HOST" bash << REMOTE
set -e
cd ~/tars-mini
tmux kill-session -t $TMUX_SESSION 2>/dev/null || true
tmux new-session -d -s $TMUX_SESSION -x 220 -y 50 \
"bash -lc 'cd ~/tars-mini && .venv/bin/python tars_pi.py 2>&1 | tee tars.log'; bash"
echo "[pi] TARS Pi client started in tmux session '$TMUX_SESSION'."
REMOTE
info "TARS deployed and running."
info ""
info "Useful commands:"
info " Watch log: ssh $TARS_HOST 'tail -f $LOG_FILE'"
info " Attach tmux: ssh -t $TARS_HOST 'tmux attach -t $TMUX_SESSION'"
info " Stop TARS: ./deploy.sh --stop"
info ""
# ── Tail log (unless --no-tail) ───────────────────────────────────────────────
if [[ "${1:-}" != "--no-tail" ]]; then
info "Tailing log (Ctrl+C to stop watching — TARS keeps running)…"
echo ""
sleep 1 # give TARS a moment to start writing
ssh "$TARS_HOST" "tail -f $LOG_FILE" || true
fi