Files
matrix/hookshot/deploy.sh
Jared Vititoe 5e936b2ca1 Add auto-deployment infrastructure for all 4 LXCs
- Per-LXC deploy scripts (lxc151-hookshot, lxc106-cinny, lxc139-landing, lxc110-draupnir)
- Per-LXC webhook hook configs with unique HMAC-SHA256 secrets
- Livekit graceful restart script + systemd timer (waits for zero active calls)
- Fix hookshot/deploy.sh capitalization bug (Uptime-Kuma, Tinker-Tickets, etc.)

Each LXC independently clones repo and runs its own deploy.sh via adnanh/webhook on port 9000.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 11:41:32 -04:00

56 lines
2.1 KiB
Bash

#!/bin/bash
# Deploy hookshot transformation functions to Matrix room state.
# Each .js file in this directory maps to a webhook by the same name (case-sensitive).
#
# Usage:
# ./deploy.sh # deploy all hooks
# ./deploy.sh proxmox.js # deploy one hook
#
# Requirements:
# MATRIX_TOKEN - access token with power level >= 50 in the target room
# MATRIX_SERVER - homeserver URL (default: https://matrix.lotusguild.org)
# MATRIX_ROOM - room ID where hooks are registered
MATRIX_SERVER="${MATRIX_SERVER:-https://matrix.lotusguild.org}"
MATRIX_ROOM="${MATRIX_ROOM:-!GttT4QYd1wlGlkHU3qTmq_P3gbyYKKeSSN6R7TPcJHg}"
if [ -z "$MATRIX_TOKEN" ]; then
echo "Error: MATRIX_TOKEN is not set." >&2
exit 1
fi
DIR="$(cd "$(dirname "$0")" && pwd)"
deploy_hook() {
local file="$1"
local filename="$(basename "$file" .js)"
# Capitalize first letter of each hyphen-separated word, preserving hyphens
# e.g. proxmox -> Proxmox, uptime-kuma -> Uptime-Kuma, tinker-tickets -> Tinker-Tickets
local state_key="$(python3 -c "import sys; s='$filename'; print('-'.join(w.capitalize() for w in s.split('-')))")"
local fn="$(cat "$file")"
local encoded_room="$(python3 -c "import urllib.parse; print(urllib.parse.quote('$MATRIX_ROOM'))")"
local encoded_key="$(python3 -c "import urllib.parse; print(urllib.parse.quote('$state_key'))")"
local response
response=$(curl -sf -X PUT \
"$MATRIX_SERVER/_matrix/client/v3/rooms/$encoded_room/state/uk.half-shot.matrix-hookshot.generic.hook/$encoded_key" \
-H "Authorization: Bearer $MATRIX_TOKEN" \
-H "Content-Type: application/json" \
--data-binary "$(python3 -c "import json; print(json.dumps({'name': '$state_key', 'transformationFunction': open('$file').read()}))")" \
2>&1)
if echo "$response" | python3 -c "import json,sys; d=json.load(sys.stdin); exit(0 if 'event_id' in d else 1)" 2>/dev/null; then
echo "$state_key"
else
echo "$state_key: $response"
fi
}
if [ -n "$1" ]; then
deploy_hook "$DIR/$1"
else
for f in "$DIR"/*.js; do
deploy_hook "$f"
done
fi