arcticaurora commited on
Commit
a1682cc
·
verified ·
1 Parent(s): 086338a

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +44 -84
start.sh CHANGED
@@ -1,36 +1,36 @@
1
  #!/bin/bash
2
  set -e
3
 
4
- # ======================= Supabase Config =======================
5
- # Strip any whitespace/newlines from environment variables
6
- export SUPABASE_URL="${SUPABASE_URL//[$'\t\r\n ']}"
7
- export SUPABASE_ANON_KEY="${SUPABASE_ANON_KEY//[$'\t\r\n ']}"
8
- export CONFIG_ID="mcp_settings"
9
- # ================================================================
10
 
11
  # --- Define paths ---
12
  APP_SRC_DIR="/app"
13
  RUN_DIR="/tmp/mcphub"
14
- CONFIG_FILE_NAME="mcp_settings.json"
15
- CONFIG_FILE_PATH="${RUN_DIR}/${CONFIG_FILE_NAME}"
16
 
17
- echo "--- MCPHub with Supabase Storage ---"
18
 
19
  # 1. Create runtime directory and copy files
20
  echo "Setting up runtime environment..."
21
  mkdir -p "$RUN_DIR"
22
  cp -a "${APP_SRC_DIR}/." "$RUN_DIR/"
23
 
24
- # 2. Download config from Supabase
25
- echo "Loading configuration..."
26
- RESPONSE=$(curl --http1.1 -s -S -X GET \
27
- "${SUPABASE_URL}/rest/v1/configs?id=eq.${CONFIG_ID}&select=content" \
28
- -H "apikey: ${SUPABASE_ANON_KEY}" \
29
- -H "Authorization: Bearer ${SUPABASE_ANON_KEY}" \
30
- -H "Accept: application/json" 2>&1)
31
 
32
- if [ -n "$RESPONSE" ] && [ "$RESPONSE" != "[]" ] && [[ ! "$RESPONSE" =~ "ERROR" ]]; then
33
- echo "$RESPONSE" | python3 -c "
 
 
 
 
 
 
 
 
34
  import sys, json
35
  try:
36
  data = json.load(sys.stdin)
@@ -40,76 +40,36 @@ try:
40
  print('{}')
41
  except:
42
  print('{}')
43
- " > "$CONFIG_FILE_PATH"
44
- echo "✅ Configuration loaded"
45
- else
46
- echo "{}" > "$CONFIG_FILE_PATH"
47
- echo "⚠️ Using default configuration"
48
- fi
49
-
50
- # 3. Function to sync file to Supabase
51
- sync_to_supabase() {
52
- if [ ! -f "$CONFIG_FILE_PATH" ]; then
53
- return 1
54
- fi
55
 
56
- # Create JSON payload using Python (just for JSON formatting)
57
- PAYLOAD=$(python3 -c "
58
- import json
59
- from datetime import datetime
60
-
61
- with open('$CONFIG_FILE_PATH', 'r') as f:
62
- config = json.load(f)
63
-
64
- payload = {
65
- 'content': config,
66
- 'updated_at': datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S')
67
- }
68
-
69
- print(json.dumps(payload))
70
- " 2>/dev/null)
71
 
72
- if [ -n "$PAYLOAD" ]; then
73
- # Upload using curl
74
- curl --http1.1 -s -X PATCH \
75
- "${SUPABASE_URL}/rest/v1/configs?id=eq.${CONFIG_ID}" \
76
- -H "apikey: ${SUPABASE_ANON_KEY}" \
77
- -H "Authorization: Bearer ${SUPABASE_ANON_KEY}" \
78
- -H "Content-Type: application/json" \
79
- -H "Prefer: return=minimal" \
80
- -d "$PAYLOAD" > /dev/null 2>&1
81
-
82
- if [ $? -eq 0 ]; then
83
- echo "✅ Config synced to Supabase at $(date)"
84
- fi
85
- fi
86
- }
87
-
88
- # 4. Start background sync process
89
- echo "Starting background sync..."
90
- (
91
- LAST_HASH=""
92
- if [ -f "$CONFIG_FILE_PATH" ]; then
93
- LAST_HASH=$(md5sum "$CONFIG_FILE_PATH" | awk '{ print $1 }')
94
- fi
95
 
96
- while true; do
97
- sleep 30
98
-
99
- if [ -f "$CONFIG_FILE_PATH" ]; then
100
- CURRENT_HASH=$(md5sum "$CONFIG_FILE_PATH" | awk '{ print $1 }')
101
-
102
- if [ "$CURRENT_HASH" != "$LAST_HASH" ]; then
103
- sync_to_supabase
104
- LAST_HASH=$CURRENT_HASH
105
- fi
106
- fi
107
- done
108
- ) &
109
 
110
- # 5. Start application
111
  echo "🚀 Starting MCPHub server..."
112
- cd "$RUN_DIR"
113
  npm start
114
 
115
- echo "MCPHub server stopped."
 
1
  #!/bin/bash
2
  set -e
3
 
4
+ # Database configuration (using built-in DAO layer)
5
+ export USE_DAO_LAYER=true
6
+ export DB_URL="${DB_URL//[$'\t\r\n ']}"
7
+
8
+ # Migration flag - set to true to run migration, then set back to false
9
+ MIGRATE_DATA="${MIGRATE_DATA:-false}"
10
 
11
  # --- Define paths ---
12
  APP_SRC_DIR="/app"
13
  RUN_DIR="/tmp/mcphub"
 
 
14
 
15
+ echo "--- MCPHub with Supabase Database ---"
16
 
17
  # 1. Create runtime directory and copy files
18
  echo "Setting up runtime environment..."
19
  mkdir -p "$RUN_DIR"
20
  cp -a "${APP_SRC_DIR}/." "$RUN_DIR/"
21
 
22
+ cd "$RUN_DIR"
 
 
 
 
 
 
23
 
24
+ # 2. One-time migration from your current setup
25
+ if [ "$MIGRATE_DATA" = "true" ]; then
26
+ echo "🔄 Migrating data from configs table..."
27
+
28
+ # Download current config from your configs table
29
+ CONFIG_JSON=$(curl --http1.1 -s -X GET \
30
+ "${SUPABASE_URL}/rest/v1/configs?id=eq.mcp_settings&select=content" \
31
+ -H "apikey: ${SUPABASE_ANON_KEY}" \
32
+ -H "Authorization: Bearer ${SUPABASE_ANON_KEY}" \
33
+ -H "Accept: application/json" | python3 -c "
34
  import sys, json
35
  try:
36
  data = json.load(sys.stdin)
 
40
  print('{}')
41
  except:
42
  print('{}')
43
+ ")
 
 
 
 
 
 
 
 
 
 
 
44
 
45
+ # Save the config temporarily
46
+ echo "$CONFIG_JSON" > /tmp/current_config.json
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
+ # Set environment to use legacy mode for loading
49
+ export USE_DAO_LAYER=false
50
+
51
+ # Load the config into the app and save via DAO layer
52
+ node -e "
53
+ const fs = require('fs');
54
+ const config = JSON.parse(fs.readFileSync('/tmp/current_config.json', 'utf8'));
55
+
56
+ // Use the built-in migration function
57
+ const { migrateToDao } = require('./dist/config/configManager.js');
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
+ migrateToDao().then(() => {
60
+ console.log('✅ Migration completed successfully');
61
+ process.exit(0);
62
+ }).catch((error) => {
63
+ console.error('❌ Migration failed:', error);
64
+ process.exit(1);
65
+ });
66
+ "
67
+
68
+ echo "✅ Migration completed!"
69
+ fi
 
 
70
 
71
+ # 3. Start application
72
  echo "🚀 Starting MCPHub server..."
 
73
  npm start
74
 
75
+ echo "MCPHub server stopped."