Initial commit
This commit is contained in:
26
scripts/build.sh
Executable file
26
scripts/build.sh
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "🔨 Building Slack to ntfy middleware..."
|
||||
|
||||
# Build for different platforms
|
||||
PLATFORMS="linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64"
|
||||
OUTPUT_DIR="dist"
|
||||
|
||||
mkdir -p $OUTPUT_DIR
|
||||
|
||||
for platform in $PLATFORMS; do
|
||||
OS=$(echo $platform | cut -d'/' -f1)
|
||||
ARCH=$(echo $platform | cut -d'/' -f2)
|
||||
|
||||
OUTPUT_NAME="middleware-$OS-$ARCH"
|
||||
if [ $OS = "windows" ]; then
|
||||
OUTPUT_NAME="$OUTPUT_NAME.exe"
|
||||
fi
|
||||
|
||||
echo "Building for $OS/$ARCH..."
|
||||
CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -a -installsuffix cgo -o $OUTPUT_DIR/$OUTPUT_NAME main.go
|
||||
done
|
||||
|
||||
echo "✅ Build complete! Binaries available in $OUTPUT_DIR/"
|
||||
ls -la $OUTPUT_DIR/
|
||||
56
scripts/setup.sh
Executable file
56
scripts/setup.sh
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "⚙️ Setting up Slack to ntfy middleware..."
|
||||
|
||||
# Check if Docker is installed
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo "❌ Docker is not installed. Please install Docker first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if Docker Compose is available
|
||||
if ! docker compose version &> /dev/null; then
|
||||
echo "❌ Docker Compose is not available. Please install Docker Compose."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ Docker and Docker Compose are available"
|
||||
|
||||
# Prompt for configuration
|
||||
echo
|
||||
echo "📝 Please provide your ntfy server configuration:"
|
||||
read -p "ntfy server URL (e.g., https://ntfy.example.com): " NTFY_URL
|
||||
read -p "Bearer token (e.g., tk_xxxxx) [optional]: " NTFY_TOKEN
|
||||
read -p "ntfy username (for basic auth) [optional]: " NTFY_USERNAME
|
||||
read -p "ntfy password (for basic auth) [optional]: " NTFY_PASSWORD
|
||||
|
||||
# Update docker-compose.yml
|
||||
if [ ! -z "$NTFY_URL" ]; then
|
||||
sed -i '' "s|https://your-ntfy-server.com|$NTFY_URL|g" docker-compose.yml
|
||||
fi
|
||||
|
||||
# Reset all auth lines to commented placeholders first to ensure a clean state
|
||||
sed -i '' "s|^ - NTFY_TOKEN=.*| # - NTFY_TOKEN=tk_your_bearer_token_here|" docker-compose.yml
|
||||
sed -i '' "s|^ - NTFY_USERNAME=.*| # - NTFY_USERNAME=your_username|" docker-compose.yml
|
||||
sed -i '' "s|^ - NTFY_PASSWORD=.*| # - NTFY_PASSWORD=your_password|" docker-compose.yml
|
||||
|
||||
if [ ! -z "$NTFY_TOKEN" ]; then
|
||||
sed -i '' "s|^ # - NTFY_TOKEN=tk_your_bearer_token_here| - NTFY_TOKEN=$NTFY_TOKEN|" docker-compose.yml
|
||||
elif [ ! -z "$NTFY_USERNAME" ] && [ ! -z "$NTFY_PASSWORD" ]; then
|
||||
sed -i '' "s|^ # - NTFY_USERNAME=your_username| - NTFY_USERNAME=$NTFY_USERNAME|" docker-compose.yml
|
||||
sed -i '' "s|^ # - NTFY_PASSWORD=your_password| - NTFY_PASSWORD=$NTFY_PASSWORD|" docker-compose.yml
|
||||
fi
|
||||
|
||||
echo "✅ Configuration updated in docker-compose.yml"
|
||||
|
||||
# Build and start
|
||||
echo "🐳 Building and starting the service..."
|
||||
docker compose up -d --build
|
||||
|
||||
echo "✅ Service is starting up..."
|
||||
echo
|
||||
echo "Next steps:"
|
||||
echo "1. Test the service: ./scripts/test.sh"
|
||||
echo "2. Check logs: docker compose logs -f"
|
||||
echo "3. Configure Slack webhook URL: http://your-server-ip:8080/your-topic-name"
|
||||
39
scripts/test.sh
Executable file
39
scripts/test.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
MIDDLEWARE_URL="http://localhost:8080"
|
||||
TEST_TOPIC="test-topic"
|
||||
|
||||
echo "🧪 Testing Slack to ntfy middleware..."
|
||||
|
||||
# Check if service is running
|
||||
echo "Checking if middleware is running..."
|
||||
if ! curl -s "$MIDDLEWARE_URL/health" > /dev/null; then
|
||||
echo "❌ Middleware is not running on $MIDDLEWARE_URL"
|
||||
echo "Please start it with: docker compose up -d"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ Middleware is running"
|
||||
|
||||
# Test health endpoint
|
||||
echo "Testing health endpoint..."
|
||||
HEALTH_RESPONSE=$(curl -s "$MIDDLEWARE_URL/health")
|
||||
echo "Health response: $HEALTH_RESPONSE"
|
||||
|
||||
# Test Slack webhook format
|
||||
echo "Testing Slack webhook format..."
|
||||
curl -X POST "$MIDDLEWARE_URL/$TEST_TOPIC" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"text": "🧪 Test alert from Slack to ntfy middleware test script"}' \
|
||||
-w "\nHTTP Status: %{http_code}\n"
|
||||
|
||||
# Test plain text format
|
||||
echo "Testing plain text format..."
|
||||
curl -X POST "$MIDDLEWARE_URL/$TEST_TOPIC" \
|
||||
-H 'Content-Type: text/plain' \
|
||||
-d 'Plain text test alert' \
|
||||
-w "\nHTTP Status: %{http_code}\n"
|
||||
|
||||
echo "✅ Tests completed!"
|
||||
echo "Check your ntfy client to see if messages were delivered to topic: $TEST_TOPIC"
|
||||
Reference in New Issue
Block a user