#!/usr/bin/env bash set -e cd "$(dirname "$0")" # systemd user units need XDG_RUNTIME_DIR when run over a non-login (ssh) shell. export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" SERVICE=silero-tts.service UNIT_FILE="$HOME/.config/systemd/user/$SERVICE" if [ -f "$UNIT_FILE" ]; then HAS_SYSTEMD=1; else HAS_SYSTEMD=0; fi echo "[1/4] Stopping service..." PORT=$(python3 -c "import json;print(json.load(open('config.json'))['runtime'].get('port',5215))" 2>/dev/null || echo 5215) if [ "$HAS_SYSTEMD" = "1" ]; then systemctl --user stop "$SERVICE" 2>/dev/null || true fi fuser -k "$PORT/tcp" 2>/dev/null || true sleep 1 echo "[2/4] Pulling latest changes..." git pull origin main echo "[3/4] Updating dependencies..." if [ ! -d .venv ]; then python3.12 -m venv .venv fi .venv/bin/python -m pip install --upgrade pip >/dev/null .venv/bin/pip install -e ".[dev]" echo "[4/4] Starting service..." if [ "$HAS_SYSTEMD" = "1" ]; then echo " systemd user unit '$SERVICE' found -> restarting it" systemctl --user restart "$SERVICE" sleep 5 systemctl --user is-active "$SERVICE" || true else echo " no systemd unit -> starting via run.sh (port $PORT)" exec ./run.sh fi