#!/bin/sh # Install the oikos-web deploy-webhook launchd unit on the mac-mini. # # Renders scripts/oikos-web-deploy-webhook.plist with real secret values and # loads it. Values come from env; when absent, the HMAC secret and API token # are resolved from the oikos stack's Infisical via the oikos CLI (only # available on the mac-mini with the oikos checkout + .env). # # Usage: # WEBHOOK_HMAC_SECRET=... GITEA_TOKEN=... ./scripts/install-webhook.sh set -e REPO_DIR="${REPO_DIR:-$(cd "$(dirname "$0")/.." && pwd)}" PLIST_DST="$HOME/Library/LaunchAgents/network.hubris.oikos-web-deploy-webhook.plist" LABEL="network.hubris.oikos-web-deploy-webhook" OIKOS_CLI="${OIKOS_CLI:-$HOME/Projects/oikos/oikos}" infisical_get() { [ -x "$OIKOS_CLI" ] || return 1 (cd "$HOME/Projects/oikos" && set -a && . ./.env 2>/dev/null && set +a \ && OIKOS_INFISICAL_SITE_URL=http://localhost:8080 "$OIKOS_CLI" secret get "$1" 2>/dev/null) \ | grep -E '^[0-9a-f]{40,}$' | head -n1 } HMAC="${WEBHOOK_HMAC_SECRET:-$(infisical_get webhook_hmac-secret || true)}" GITEA_TOKEN="${GITEA_TOKEN:-$(infisical_get gitea-pat_token || true)}" API_TOKEN="${OIKOS_API_TOKEN:-$(infisical_get api_token || true)}" if [ -z "$HMAC" ]; then echo "ERROR: WEBHOOK_HMAC_SECRET not set and could not resolve from Infisical" >&2 exit 1 fi # Build the webhook binary first (cd "$REPO_DIR" && make webhook) launchctl bootout "gui/$(id -u)" "$PLIST_DST" 2>/dev/null || true cat > "$PLIST_DST" < Label $LABEL ProgramArguments $REPO_DIR/webhook WorkingDirectory $REPO_DIR EnvironmentVariables HOME $HOME PATH /usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin WEBHOOK_LISTEN :9798 WEBHOOK_REPO_DIR $REPO_DIR WEBHOOK_HMAC_SECRET $HMAC GITEA_URL https://git.hubris.network GITEA_TOKEN $GITEA_TOKEN OIKOS_API_TOKEN $API_TOKEN RunAtLoad KeepAlive StandardOutPath $HOME/Library/Logs/oikos-web-webhook.log StandardErrorPath $HOME/Library/Logs/oikos-web-webhook.log EOF chmod 600 "$PLIST_DST" launchctl bootstrap "gui/$(id -u)" "$PLIST_DST" sleep 1 launchctl print "gui/$(id -u)/$LABEL" >/dev/null && echo "installed: $LABEL (listening :9798)"