8900 commited on
Commit
8e65ec4
·
verified ·
1 Parent(s): 6c2acc7

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +39 -55
entrypoint.sh CHANGED
@@ -1,76 +1,60 @@
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
 
1
  #!/bin/sh
2
 
3
+ # 开启调试输出(可选)
4
+ set -x
5
 
6
+ # resolve OPENCLAW_HOME
7
  if mkdir -p /data/.openclaw 2>/dev/null; then
8
+ export OPENCLAW_HOME=/data
9
  else
10
+ export OPENCLAW_HOME=/home/user
11
+ mkdir -p /home/user/.openclaw
12
  fi
 
13
  echo "[entrypoint] OPENCLAW_HOME=$OPENCLAW_HOME"
14
 
15
+ # 导出 provider keys(逻辑不变)
16
+ for VAR in $(env | cut -d= -f1); do
17
+ case "$VAR" in
18
+ OPENCLAW_*|SPACE_*|SYSTEM_*|NODE_*|HF_SPACE*) continue ;;
19
+ esac
20
+ case "$VAR" in
21
+ *_API_KEY|*_SECRET_KEY|*_ACCESS_TOKEN|*_BOT_TOKEN|*_AUTH_TOKEN|*_APP_KEY)
22
+ eval "VAL=\$$VAR"
23
+ if [ -n "$VAL" ]; then
24
+ export "$VAR"
25
+ echo "[entrypoint] exported: $VAR"
26
+ fi
27
+ ;;
28
+ esac
 
 
 
 
 
 
 
 
 
 
29
  done
30
 
 
 
31
  export HF_TOKEN="${HF_TOKEN:-}"
32
 
33
+ # 恢复数据集(非致命)
34
+ if [ -n "$HF_TOKEN" ] && [ -n "$HF_DATASET_ID" ]; then
35
+ echo "[entrypoint] Restoring from dataset ${HF_DATASET_ID}..."
36
+ timeout 30 sh /app/hf-sync.sh restore || echo "[entrypoint] Restore skipped (non-fatal)"
 
 
 
37
  fi
38
 
39
+ # 生成配置(失败则退出,便于排查)
40
+ echo "[entrypoint] Generating OpenClaw config..."
41
+ if ! node /app/spaces/huggingface/setup-hf-config.mjs; then
42
+ echo "[entrypoint] ERROR: Config generation failed. Check OPENCLAW_GATEWAY_TOKEN/PASSWORD."
43
+ exit 1
44
+ fi
45
 
46
+ # 安全检查(非致命)
47
+ if [ -f /app/security-check.sh ]; then
48
+ sh /app/security-check.sh || true
49
  fi
50
 
51
  echo "[entrypoint] starting gateway..."
52
 
53
+ # 启动后台同步循环
54
+ if [ -n "$HF_TOKEN" ] && [ -n "$HF_DATASET_ID" ]; then
55
+ sh /app/hf-sync.sh loop &
56
+ echo "[entrypoint] sync loop started (interval=${HF_SYNC_INTERVAL:-3600}s)"
 
 
57
  fi
58
 
59
+ # 启动网关
60
+ exec node /app/openclaw.mjs gateway --allow-unconfigured --bind lan --port 7860