Files
matrix/hookshot/deploy.sh
T
jared 735c1eb30e
Lint / Shell (shellcheck) (push) Has been cancelled
Lint / JS (eslint) (push) Has been cancelled
ci: add lint workflow, shellcheck fixes, and CI failure hookshot alert
- .gitea/workflows/lint.yml: new workflow running shellcheck on .sh files
  and eslint on hookshot/ JS transform scripts
- hookshot/.eslintrc.json: declare data/result as hookshot globals
- hookshot/ci-alert.js: new Matrix hookshot transform for CI failure alerts
- hookshot/deploy.sh: fix SC2155 (split local/assign), SC2034 (remove unused var)
- systemd/livekit-clear-port.sh: fix SC2148 (invalid shebang escape)
- cinny/dev-update.sh: fix SC2115 (use ${WEB_ROOT:?} to guard rm -rf)
- deploy/lxc151-hookshot.sh: add shellcheck source=/dev/null for sourced file
- .gitignore: ignore node_modules/
- package.json + package-lock.json: eslint@8 dev dependency

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 16:25:39 -04:00

59 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
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
state_key="$(python3 -c "import sys; s='$filename'; print('-'.join(w.capitalize() for w in s.split('-')))")"
local encoded_room
encoded_room="$(python3 -c "import urllib.parse; print(urllib.parse.quote('$MATRIX_ROOM'))")"
local encoded_key
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