#!/bin/bash # Webhook Receiver for Basil Deployments # This script sets up a simple webhook endpoint that triggers deployments set -e # Configuration SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PORT="${WEBHOOK_PORT:-9000}" SECRET="${WEBHOOK_SECRET:-changeme}" LOG_FILE="$SCRIPT_DIR/../webhook.log" # Colors GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' log() { echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1" | tee -a "$LOG_FILE" } warning() { echo -e "${YELLOW}[$(date +'%Y-%m-%d %H:%M:%S')] WARNING:${NC} $1" | tee -a "$LOG_FILE" } # Install webhook if not present install_webhook() { if ! command -v webhook &> /dev/null; then log "Installing webhook..." if command -v apt-get &> /dev/null; then sudo apt-get update && sudo apt-get install -y webhook elif command -v yum &> /dev/null; then sudo yum install -y webhook else warning "Please install 'webhook' manually: https://github.com/adnanh/webhook" exit 1 fi fi } # Create webhook configuration create_webhook_config() { cat > "$SCRIPT_DIR/webhook-config.json" <