Subsequently commited on
Commit
1f0834a
·
verified ·
1 Parent(s): 00b27df

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +25 -37
entrypoint.sh CHANGED
@@ -1,13 +1,18 @@
1
  #!/bin/sh
2
- # OpenClaw HF Spaces — Entrypoint
3
- # openclaw installed globally via npm → available as `openclaw` in PATH
4
 
 
 
 
5
  ts() { date -u +"%H:%M:%S"; }
6
  log() { echo "[$(ts)] [entrypoint] $*"; }
7
  warn() { echo "[$(ts)] [entrypoint] WARN: $*"; }
8
 
9
  # ----------------------------------------------------------------
10
  # Storage: resolve OPENCLAW_HOME
 
 
11
  # ----------------------------------------------------------------
12
  OPENCLAW_HOME=/home/user
13
  mkdir -p /home/user/.openclaw
@@ -36,32 +41,6 @@ fi
36
  export OPENCLAW_HOME
37
  log "OPENCLAW_HOME=$OPENCLAW_HOME"
38
 
39
- # ----------------------------------------------------------------
40
- # Clean up stale extensions (uid mismatch fix)
41
- # ----------------------------------------------------------------
42
- EXTENSIONS_DIR="$OPENCLAW_HOME/.openclaw/extensions"
43
- if [ -d "$EXTENSIONS_DIR" ]; then
44
- log "Removing stale extensions dir..."
45
- rm -rf "$EXTENSIONS_DIR" || true
46
- fi
47
-
48
- CONFIG_PATH="$OPENCLAW_HOME/.openclaw/openclaw.json"
49
- if [ -f "$CONFIG_PATH" ]; then
50
- node - << 'JSEOF' || true
51
- const fs = require('fs');
52
- const p = process.env.OPENCLAW_HOME + '/.openclaw/openclaw.json';
53
- try {
54
- const cfg = JSON.parse(fs.readFileSync(p, 'utf-8'));
55
- if (cfg.plugins) {
56
- delete cfg.plugins;
57
- fs.copyFileSync(p, p + '.bak');
58
- fs.writeFileSync(p, JSON.stringify(cfg, null, 2), 'utf-8');
59
- console.log('[entrypoint] Removed stale plugins config');
60
- }
61
- } catch(e) {}
62
- JSEOF
63
- fi
64
-
65
  # ----------------------------------------------------------------
66
  # Export provider API keys from Secrets
67
  # ----------------------------------------------------------------
@@ -83,22 +62,26 @@ done
83
  export HF_TOKEN="${HF_TOKEN:-}"
84
 
85
  # ----------------------------------------------------------------
86
- # Setup
87
  # ----------------------------------------------------------------
88
  log "Running setup..."
89
  node /app/spaces/huggingface/setup-hf-config.mjs || true
90
  log "Setup done."
91
 
 
 
 
92
  if [ -f /app/security-check.sh ]; then
93
  sh /app/security-check.sh || true
94
  fi
95
 
96
  # ----------------------------------------------------------------
97
- # Device auto-pairing (background)
98
  # ----------------------------------------------------------------
99
  (
100
  DEVICES_DIR="$OPENCLAW_HOME/.openclaw/devices"
101
  mkdir -p "$DEVICES_DIR"
 
102
  while true; do
103
  sleep 8
104
  PENDING="$DEVICES_DIR/pending.json"
@@ -118,15 +101,17 @@ try {
118
  let paired = [];
119
  try { paired = JSON.parse(fs.readFileSync(pair, 'utf-8')); } catch(e) {}
120
  if (!Array.isArray(paired)) paired = [];
121
- const ids = new Set(paired.map(d => d.id||d.deviceId||d.name));
122
- const todo = pending.filter(d => !ids.has(d.id||d.deviceId||d.name));
123
  if (todo.length === 0) process.exit(0);
124
  const now = new Date().toISOString();
125
- paired = paired.concat(todo.map(d => Object.assign({}, d, { approved: true, approvedAt: now })));
 
 
126
  fs.writeFileSync(pair, JSON.stringify(paired, null, 2));
127
  fs.writeFileSync(pend, '[]');
128
  console.log('[auto-pair] Approved ' + todo.length + ' device(s)');
129
- } catch(e) {}
130
  JSEOF
131
  fi
132
  done
@@ -151,7 +136,7 @@ while true; do
151
  WAITED=0
152
  while nc -z 127.0.0.1 7860 2>/dev/null; do
153
  if [ $WAITED -eq 0 ]; then
154
- log "Port 7860 still held - waiting..."
155
  fi
156
  sleep 2
157
  WAITED=$((WAITED + 2))
@@ -161,7 +146,10 @@ while true; do
161
  fi
162
  done
163
 
164
- [ $WAITED -gt 0 ] && log "Port free after ${WAITED}s"
 
 
 
165
  sleep 1
166
  log "Restarting gateway..."
167
- done
 
1
  #!/bin/sh
2
+ # OpenClaw HF Spaces - Production Entrypoint
3
+ # Storage: HF Storage Bucket at /data (100 GB persistent)
4
 
5
+ # ----------------------------------------------------------------
6
+ # Logging
7
+ # ----------------------------------------------------------------
8
  ts() { date -u +"%H:%M:%S"; }
9
  log() { echo "[$(ts)] [entrypoint] $*"; }
10
  warn() { echo "[$(ts)] [entrypoint] WARN: $*"; }
11
 
12
  # ----------------------------------------------------------------
13
  # Storage: resolve OPENCLAW_HOME
14
+ # Prefer /data (HF Storage Bucket). Fall back to /home/user.
15
+ # Retry up to 5s in case the bucket mount is slightly delayed.
16
  # ----------------------------------------------------------------
17
  OPENCLAW_HOME=/home/user
18
  mkdir -p /home/user/.openclaw
 
41
  export OPENCLAW_HOME
42
  log "OPENCLAW_HOME=$OPENCLAW_HOME"
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  # ----------------------------------------------------------------
45
  # Export provider API keys from Secrets
46
  # ----------------------------------------------------------------
 
62
  export HF_TOKEN="${HF_TOKEN:-}"
63
 
64
  # ----------------------------------------------------------------
65
+ # One-time setup (config write, webhook registration, seed files)
66
  # ----------------------------------------------------------------
67
  log "Running setup..."
68
  node /app/spaces/huggingface/setup-hf-config.mjs || true
69
  log "Setup done."
70
 
71
+ # ----------------------------------------------------------------
72
+ # Security audit (non-fatal)
73
+ # ----------------------------------------------------------------
74
  if [ -f /app/security-check.sh ]; then
75
  sh /app/security-check.sh || true
76
  fi
77
 
78
  # ----------------------------------------------------------------
79
+ # Auto-approve pending device pairings (background)
80
  # ----------------------------------------------------------------
81
  (
82
  DEVICES_DIR="$OPENCLAW_HOME/.openclaw/devices"
83
  mkdir -p "$DEVICES_DIR"
84
+ log "Device auto-pairing watcher started"
85
  while true; do
86
  sleep 8
87
  PENDING="$DEVICES_DIR/pending.json"
 
101
  let paired = [];
102
  try { paired = JSON.parse(fs.readFileSync(pair, 'utf-8')); } catch(e) {}
103
  if (!Array.isArray(paired)) paired = [];
104
+ const ids = new Set(paired.map(function(d){ return d.id||d.deviceId||d.name; }));
105
+ const todo = pending.filter(function(d){ return !ids.has(d.id||d.deviceId||d.name); });
106
  if (todo.length === 0) process.exit(0);
107
  const now = new Date().toISOString();
108
+ paired = paired.concat(todo.map(function(d){
109
+ return Object.assign({}, d, { approved: true, approvedAt: now });
110
+ }));
111
  fs.writeFileSync(pair, JSON.stringify(paired, null, 2));
112
  fs.writeFileSync(pend, '[]');
113
  console.log('[auto-pair] Approved ' + todo.length + ' device(s)');
114
+ } catch(e) { /* ignore */ }
115
  JSEOF
116
  fi
117
  done
 
136
  WAITED=0
137
  while nc -z 127.0.0.1 7860 2>/dev/null; do
138
  if [ $WAITED -eq 0 ]; then
139
+ log "Port 7860 still held (spawned child running) - waiting..."
140
  fi
141
  sleep 2
142
  WAITED=$((WAITED + 2))
 
146
  fi
147
  done
148
 
149
+ if [ $WAITED -gt 0 ]; then
150
+ log "Port free after ${WAITED}s"
151
+ fi
152
+
153
  sleep 1
154
  log "Restarting gateway..."
155
+ done