8900 commited on
Commit
6c2acc7
·
1 Parent(s): 2dc6956

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +48 -39
entrypoint.sh CHANGED
@@ -1,67 +1,76 @@
1
  #!/bin/sh
2
 
3
  # resolve OPENCLAW_HOME
 
4
  if mkdir -p /data/.openclaw 2>/dev/null; then
5
- export OPENCLAW_HOME=/data
6
  else
7
- export OPENCLAW_HOME=/home/user
8
- mkdir -p /home/user/.openclaw
9
  fi
10
 
11
  echo "[entrypoint] OPENCLAW_HOME=$OPENCLAW_HOME"
12
 
13
- # 显式导出网关令牌(如果存在),确保网关能读取
14
- if [ -n "$OPENCLAW_GATEWAY_TOKEN" ]; then
15
- export OPENCLAW_GATEWAY_TOKEN
16
- echo "[entrypoint] Gateway token is set (use this in Control UI): $OPENCLAW_GATEWAY_TOKEN"
17
- elif [ -n "$OPENCLAW_GATEWAY_PASSWORD" ]; then
18
- export OPENCLAW_GATEWAY_PASSWORD
19
- echo "[entrypoint] Gateway password is set (use this in Control UI)"
20
- else
21
- echo "[entrypoint] WARNING: Neither OPENCLAW_GATEWAY_TOKEN nor OPENCLAW_GATEWAY_PASSWORD is set. Gateway will be unprotected!"
22
- fi
23
-
24
  # dynamically export all provider keys so openclaw gateway can read them
25
- # matches: *_API_KEY *_SECRET_KEY *_ACCESS_TOKEN *_BOT_TOKEN *_AUTH_TOKEN *_APP_KEY
26
- # excludes: OPENCLAW_ SPACE_ SYSTEM_ HF_SPACE NODE_ prefixes
27
- for VAR in $(env | cut -d= -f1); do
28
- case "$VAR" in
29
- OPENCLAW_*|SPACE_*|SYSTEM_*|HF_SPACE*|NODE_*) continue ;;
30
- esac
31
- case "$VAR" in
32
- *_API_KEY|*_SECRET_KEY|*_ACCESS_TOKEN|*_BOT_TOKEN|*_AUTH_TOKEN|*_APP_KEY)
33
- eval VAL=\$VAR
34
- if [ -n "$VAL" ]; then
35
- export "$VAR"
36
- echo "[entrypoint] exported: $VAR"
37
- fi
38
- ;;
39
- esac
 
 
 
 
 
 
 
 
40
  done
41
 
42
- # always export HF_TOKEN for dataset sync
 
43
  export HF_TOKEN="${HF_TOKEN:-}"
44
 
45
  # restore from HF Dataset (30s timeout, non-fatal)
46
- if [ -n "$HF_TOKEN" ] && [ -n "$HF_DATASET_ID" ]; then
47
- echo "[entrypoint] Restoring from dataset ${HF_DATASET_ID}..."
48
- timeout 30 sh /app/hf-sync.sh restore || echo "[entrypoint] Restore skipped (non-fatal)"
 
 
 
49
  fi
50
 
51
  # write openclaw config
 
52
  node /app/spaces/huggingface/setup-hf-config.mjs || true
53
 
54
  # run security check (non-fatal)
55
- if [ -f /app/security-check.sh ]; then
56
- sh /app/security-check.sh || true
 
 
57
  fi
58
 
59
  echo "[entrypoint] starting gateway..."
60
 
61
  # start background sync loop
62
- if [ -n "$HF_TOKEN" ] && [ -n "$HF_DATASET_ID" ]; then
63
- sh /app/hf-sync.sh loop &
64
- echo "[entrypoint] sync loop started (interval=${HF_SYNC_INTERVAL:-3600}s)"
 
 
65
  fi
66
 
67
- exec node /app/openclaw.mjs gateway --allow-unconfigured --bind lan --port 7860
 
 
 
1
  #!/bin/sh
2
 
3
  # resolve OPENCLAW_HOME
4
+
5
  if mkdir -p /data/.openclaw 2>/dev/null; then
6
+ export OPENCLAW_HOME=/data
7
  else
8
+ export OPENCLAW_HOME=/home/user
9
+ mkdir -p /home/user/.openclaw
10
  fi
11
 
12
  echo "[entrypoint] OPENCLAW_HOME=$OPENCLAW_HOME"
13
 
 
 
 
 
 
 
 
 
 
 
 
14
  # dynamically export all provider keys so openclaw gateway can read them
15
+
16
+ # OpenClaw's official mechanism: reads provider keys directly from process env vars
17
+
18
+ # matches: anything ending in _API_KEY _SECRET_KEY _ACCESS_TOKEN _BOT_TOKEN _AUTH_TOKEN _APP_KEY
19
+
20
+ # excludes: OPENCLAW SPACE SYSTEM NODE vars prefixes
21
+
22
+ for VAR in $(env | cut -d= -f1);
23
+ do
24
+ case "$VAR" in
25
+ OPENCLAW_*|SPACE_*|SYSTEM_*|NODE_*|HF_SPACE*) continue ;;
26
+ esac
27
+ case "$VAR" in
28
+ *_API_KEY|*_SECRET_KEY|*_ACCESS_TOKEN|*_BOT_TOKEN|*_AUTH_TOKEN|*_APP_KEY)
29
+ # Optimized dynamic export logic for both standard sh and bash.
30
+ # Ensure both Key exists in env and its Value is not empty before exporting
31
+ #eval VAL=\$$VAR # Convoluted expression that can be simplified
32
+ if env | grep -q "^$VAR="; then
33
+ export "$VAR"
34
+ echo "[entrypoint] exported: $VAR"
35
+ fi
36
+ ;;
37
+ esac
38
  done
39
 
40
+ # also always export HF TOKEN for dataset sync
41
+
42
  export HF_TOKEN="${HF_TOKEN:-}"
43
 
44
  # restore from HF Dataset (30s timeout, non-fatal)
45
+
46
+ if [ -n "$HF_TOKEN" ] && [ -n "$HF_DATASET_ID" ];
47
+ then
48
+ echo "[entrypoint] Restoring from dataset ${HF_DATASET_ID}..."
49
+ timeout 30 sh /app/hf-sync.sh restore ||
50
+ echo "[entrypoint] Restore skipped (non-fatal)"
51
  fi
52
 
53
  # write openclaw config
54
+
55
  node /app/spaces/huggingface/setup-hf-config.mjs || true
56
 
57
  # run security check (non-fatal)
58
+
59
+ if [ -f /app/security-check.sh ];
60
+ then
61
+ sh /app/security-check.sh || true
62
  fi
63
 
64
  echo "[entrypoint] starting gateway..."
65
 
66
  # start background sync loop
67
+
68
+ if [ -n "$HF_TOKEN" ] && [ -n "$HF_DATASET_ID" ];
69
+ then
70
+ sh /app/hf-sync.sh loop &
71
+ echo "[entrypoint] sync loop started (interval=${HF_SYNC_INTERVAL:-3600}s)"
72
  fi
73
 
74
+ # FIX: must use ASCII hyphens -- not en-dashes – in execution line
75
+
76
+ exec node /app/openclaw.mjs gateway --allow-unconfigured --bind lan --port 7860