#!/bin/bash # Setup script for admin features set -e echo "==================================================" echo "OBS R2 Uploader - Admin Setup" echo "==================================================" echo "" # Get the directory where this script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" cd "$PROJECT_DIR/worker" # Check if wrangler is authenticated echo "Checking Wrangler authentication..." if ! wrangler whoami &> /dev/null; then echo "✗ Wrangler is not authenticated" echo "Run 'wrangler login' first" exit 1 fi echo "✓ Wrangler is authenticated" echo "" # Create KV namespace for video metadata echo "Creating KV namespace for video metadata..." if wrangler kv:namespace create VIDEO_METADATA 2>&1 | tee /tmp/kv_output.txt; then echo "✓ KV namespace created" # Extract the KV namespace ID from output KV_ID=$(grep -oP 'id = "\K[^"]+' /tmp/kv_output.txt || echo "") if [ -n "$KV_ID" ]; then echo "KV Namespace ID: $KV_ID" echo "" echo "⚠️ IMPORTANT: Update wrangler-enhanced.toml with this ID:" echo " Replace 'placeholder_id' with: $KV_ID" echo "" # Automatically update the wrangler.toml file if [ -f "wrangler-enhanced.toml" ]; then sed -i "s/id = \"placeholder_id\"/id = \"$KV_ID\"/" wrangler-enhanced.toml echo "✓ Updated wrangler-enhanced.toml with KV namespace ID" fi fi else echo "⚠️ KV namespace may already exist. Check with:" echo " wrangler kv:namespace list" fi echo "" # Set admin password echo "Setting up admin password..." echo "Please enter a secure admin password:" read -s ADMIN_PASSWORD echo "" echo "Confirm password:" read -s ADMIN_PASSWORD_CONFIRM echo "" if [ "$ADMIN_PASSWORD" != "$ADMIN_PASSWORD_CONFIRM" ]; then echo "✗ Passwords do not match" exit 1 fi # Set the secret echo "$ADMIN_PASSWORD" | wrangler secret put ADMIN_PASSWORD echo "" echo "==================================================" echo "Admin setup complete!" echo "==================================================" echo "" echo "Next steps:" echo "1. Copy the enhanced worker as the main worker:" echo " cp video-server-enhanced.js video-server.js" echo " cp wrangler-enhanced.toml wrangler.toml" echo "" echo "2. Build and embed the admin HTML:" echo " ./build-admin.sh" echo "" echo "3. Deploy the worker:" echo " wrangler deploy" echo "" echo "4. Access the admin panel:" echo " https://videos.jeffemmett.com/admin" echo ""