Spaces:
Paused
Paused
Update start.sh
Browse files1234567891011121314151617181920212223242526272829303132333435363 unmodified lines404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115#!/bin/bashset -e# ======================= Supabase Config =======================# Strip any whitespace/newlines from environment variablesexport SUPABASE_URL="${SUPABASE_URL//[$'\t\r\n ']}"export SUPABASE_ANON_KEY="${SUPABASE_ANON_KEY//[$'\t\r\n ']}"export CONFIG_ID="mcp_settings"# ================================================================# --- Define paths ---APP_SRC_DIR="/app"RUN_DIR="/tmp/mcphub"CONFIG_FILE_NAME="mcp_settings.json"CONFIG_FILE_PATH="${RUN_DIR}/${CONFIG_FILE_NAME}"echo "--- MCPHub with Supabase Storage ---"# 1. Create runtime directory and copy filesecho "Setting up runtime environment..."mkdir -p "$RUN_DIR"cp -a "${APP_SRC_DIR}/." "$RUN_DIR/"# 2. Download config from Supabaseecho "Loading configuration..."RESPONSE=$(curl --http1.1 -s -S -X GET \"${SUPABASE_URL}/rest/v1/configs?id=eq.${CONFIG_ID}&select=content" \-H "apikey: ${SUPABASE_ANON_KEY}" \-H "Authorization: Bearer ${SUPABASE_ANON_KEY}" \-H "Accept: application/json" 2>&1)if [ -n "$RESPONSE" ] && [ "$RESPONSE" != "[]" ] && [[ ! "$RESPONSE" =~ "ERROR" ]]; thenecho "$RESPONSE" | python3 -c "import sys, jsontry:data = json.load(sys.stdin)3 unmodified linesprint('{}')except:print('{}')" > "$CONFIG_FILE_PATH"echo "✅ Configuration loaded"elseecho "{}" > "$CONFIG_FILE_PATH"echo "⚠️ Using default configuration"fi# 3. Function to sync file to Supabasesync_to_supabase() {if [ ! -f "$CONFIG_FILE_PATH" ]; thenreturn 1fi# Create JSON payload using Python (just for JSON formatting)PAYLOAD=$(python3 -c "import jsonfrom datetime import datetimewith open('$CONFIG_FILE_PATH', 'r') as f:config = json.load(f)payload = {'content': config,'updated_at': datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S')}print(json.dumps(payload))" 2>/dev/null)if [ -n "$PAYLOAD" ]; then# Upload using curlcurl --http1.1 -s -X PATCH \"${SUPABASE_URL}/rest/v1/configs?id=eq.${CONFIG_ID}" \-H "apikey: ${SUPABASE_ANON_KEY}" \-H "Authorization: Bearer ${SUPABASE_ANON_KEY}" \-H "Content-Type: application/json" \-H "Prefer: return=minimal" \-d "$PAYLOAD" > /dev/null 2>&1if [ $? -eq 0 ]; thenecho "✅ Config synced to Supabase at $(date)"fifi}# 4. Start background sync processecho "Starting background sync..."(LAST_HASH=""if [ -f "$CONFIG_FILE_PATH" ]; thenLAST_HASH=$(md5sum "$CONFIG_FILE_PATH" | awk '{ print $1 }')fiwhile true; dosleep 30if [ -f "$CONFIG_FILE_PATH" ]; thenCURRENT_HASH=$(md5sum "$CONFIG_FILE_PATH" | awk '{ print $1 }')if [ "$CURRENT_HASH" != "$LAST_HASH" ]; thensync_to_supabaseLAST_HASH=$CURRENT_HASHfifidone) &# 5. Start applicationecho "🚀 Starting MCPHub server..."cd "$RUN_DIR"npm startecho "MCPHub server stopped."1234567891011121314151617181920212223242526272829303132333435363 unmodified lines404142434445464748495051525354555657585960616263646566676869707172737475#!/bin/bashset -e# Database configuration (using built-in DAO layer)export USE_DAO_LAYER=trueexport DB_URL="${DB_URL//[$'\t\r\n ']}"# Migration flag - set to true to run migration, then set back to falseMIGRATE_DATA="${MIGRATE_DATA:-false}"# --- Define paths ---APP_SRC_DIR="/app"RUN_DIR="/tmp/mcphub"echo "--- MCPHub with Supabase Database ---"# 1. Create runtime directory and copy filesecho "Setting up runtime environment..."mkdir -p "$RUN_DIR"cp -a "${APP_SRC_DIR}/." "$RUN_DIR/"cd "$RUN_DIR"# 2. One-time migration from your current setupif [ "$MIGRATE_DATA" = "true" ]; thenecho "🔄 Migrating data from configs table..."# Download current config from your configs tableCONFIG_JSON=$(curl --http1.1 -s -X GET \"${SUPABASE_URL}/rest/v1/configs?id=eq.mcp_settings&select=content" \-H "apikey: ${SUPABASE_ANON_KEY}" \-H "Authorization: Bearer ${SUPABASE_ANON_KEY}" \-H "Accept: application/json" | python3 -c "import sys, jsontry:data = json.load(sys.stdin)3 unmodified linesprint('{}')except:print('{}')")# Save the config temporarilyecho "$CONFIG_JSON" > /tmp/current_config.json# Set environment to use legacy mode for loadingexport USE_DAO_LAYER=false# Load the config into the app and save via DAO layernode -e "const fs = require('fs');const config = JSON.parse(fs.readFileSync('/tmp/current_config.json', 'utf8'));// Use the built-in migration functionconst { migrateToDao } = require('./dist/config/configManager.js');migrateToDao().then(() => {console.log('✅ Migration completed successfully');process.exit(0);}).catch((error) => {console.error('❌ Migration failed:', error);process.exit(1);});"echo "✅ Migration completed!"fi# 3. Start applicationecho "🚀 Starting MCPHub server..."npm startecho "MCPHub server stopped."
start.sh+44-84