Spaces:
Paused
Paused
Update start.sh
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647#!/bin/bashset -e# Database configuration (using built-in DAO layer)export USE_DAO_LAYER=trueexport DB_URL="${DB_URL//[$'\t\r\n ']}"# Debug flag to see what's happeningexport DEBUG=true# --- Define paths ---APP_SRC_DIR="/app"RUN_DIR="/tmp/mcphub"echo "--- MCPHub with Supabase Database ---"echo "DB_URL: ${DB_URL:0:50}..." # Log partial URL for debugging# 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. Test database connectionecho "🧪 Testing database connection..."node -e "const { initializeDatabase } = require('./dist/db/connection.js');initializeDatabase().then(() => {console.log('✅ Database connection successful');process.exit(0);}).catch((error) => {console.error('❌ Database connection failed:', error.message);process.exit(1);});"if [ $? -ne 0 ]; thenecho "Database connection failed, falling back to file mode..."export USE_DAO_LAYER=falsefi# 3. Start applicationecho "🚀 Starting MCPHub server..."npm startecho "MCPHub server stopped."123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115#!/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)if data and len(data) > 0:print(json.dumps(data[0]['content']))else:print('{}')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."
start.sh+94-26