Files
matrix/deploy/lxc151-hookshot.sh
T
jared b9a251bd7a
Lint / Shell (shellcheck) (push) Successful in 11s
Lint / JS (eslint) (push) Successful in 6s
Integrate matrixbot into existing LXC 151 deploy hook
Removed standalone matrixbot/deploy.sh — deploy is handled by the existing
webhook system. Added matrixbot/ block to deploy/lxc151-hookshot.sh: on push,
if any matrixbot/ file changed, source files are synced to /opt/matrixbot and
matrixbot.service is restarted automatically.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-20 16:18:10 -04:00

70 lines
2.3 KiB
Bash

#!/bin/bash
# Auto-deploy script for LXC 151 (matrix homeserver)
# Handles: hookshot transformation functions, livekit service file (graceful), matrixbot
# Triggered by: Gitea webhook on push to main
set -euo pipefail
REPO_DIR="/opt/matrix-config"
LOG="/var/log/matrix-deploy.log"
CLONE_URL="https://code.lotusguild.org/LotusGuild/matrix.git"
ENV_FILE="/etc/matrix-deploy.env"
exec >> "$LOG" 2>&1
echo "=== $(date) === LXC151 deploy triggered ==="
# Load env (MATRIX_TOKEN, MATRIX_SERVER, MATRIX_ROOM)
if [ -f "$ENV_FILE" ]; then
# shellcheck source=/dev/null
source "$ENV_FILE"
fi
# Clone or pull
if [ ! -d "$REPO_DIR/.git" ]; then
git clone "$CLONE_URL" "$REPO_DIR"
else
cd "$REPO_DIR"
git fetch --all
PREV=$(git rev-parse HEAD)
git reset --hard origin/main
NEW=$(git rev-parse HEAD)
CHANGED=$(git diff --name-only "$PREV" "$NEW")
echo "Changed files: $CHANGED"
# Hookshot transforms
if echo "$CHANGED" | grep -q '^hookshot/'; then
echo "Deploying hookshot transforms..."
export MATRIX_TOKEN MATRIX_SERVER MATRIX_ROOM
bash "$REPO_DIR/hookshot/deploy.sh"
fi
# Livekit service file — graceful restart (never kill active calls)
if echo "$CHANGED" | grep -q '^systemd/livekit-server.service'; then
echo "livekit-server.service changed — staging graceful restart..."
cp "$REPO_DIR/systemd/livekit-server.service" /etc/systemd/system/livekit-server.service
systemctl daemon-reload
touch /run/livekit-restart-pending
echo "Restart pending — will apply when no active calls."
fi
# Matrixbot source files
if echo "$CHANGED" | grep -q '^matrixbot/'; then
echo "Deploying matrixbot changes..."
BOT_DIR="/opt/matrixbot"
BOT_FILES="bot.py callbacks.py commands.py config.py utils.py welcome.py wordle.py wordlist_answers.py wordlist_valid.py requirements.txt"
for f in $BOT_FILES; do
if [ -f "$REPO_DIR/matrixbot/$f" ]; then
cp "$REPO_DIR/matrixbot/$f" "$BOT_DIR/$f"
fi
done
systemctl restart matrixbot
sleep 2
if systemctl is-active --quiet matrixbot; then
echo "matrixbot restarted successfully."
else
echo "ERROR: matrixbot failed to restart."
fi
fi
fi
echo "=== $(date) === LXC151 deploy complete ==="