Subsequently commited on
Commit
ca370ca
·
verified ·
1 Parent(s): 32b3f1b

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +85 -39
entrypoint.sh CHANGED
@@ -225,47 +225,93 @@ log "Doctor step done."
225
  chmod -R go-w "$OPENCLAW_HOME/.openclaw/npm" "$OPENCLAW_HOME/.openclaw/extensions" 2>/dev/null || true
226
 
227
  # ----------------------------------------------------------------
228
- # Auto-approve pending device pairings (background)
229
  # ----------------------------------------------------------------
230
- (
231
- DEVICES_DIR="$OPENCLAW_HOME/.openclaw/devices"
232
- mkdir -p "$DEVICES_DIR"
233
- log "Device auto-pairing watcher started"
234
- while true; do
235
- sleep 8
236
- PENDING="$DEVICES_DIR/pending.json"
237
- PAIRED="$DEVICES_DIR/paired.json"
238
- if [ -f "$PENDING" ]; then
239
- node - << 'JSEOF'
240
- const fs = require('fs');
241
- const dir = process.env.OPENCLAW_HOME + '/.openclaw/devices';
242
- const pend = dir + '/pending.json';
243
- const pair = dir + '/paired.json';
244
- try {
245
- const raw = fs.readFileSync(pend, 'utf-8').trim();
246
- if (!raw || raw === '[]' || raw === '{}') process.exit(0);
247
- let pending = JSON.parse(raw);
248
- if (!Array.isArray(pending)) pending = Object.values(pending);
249
- if (pending.length === 0) process.exit(0);
250
- let paired = [];
251
- try { paired = JSON.parse(fs.readFileSync(pair, 'utf-8')); } catch(e) {}
252
- if (!Array.isArray(paired)) paired = [];
253
- const ids = new Set(paired.map(function(d){ return d.id||d.deviceId||d.name; }));
254
- const todo = pending.filter(function(d){ return !ids.has(d.id||d.deviceId||d.name); });
255
- if (todo.length === 0) process.exit(0);
256
- const now = new Date().toISOString();
257
- paired = paired.concat(todo.map(function(d){
258
- return Object.assign({}, d, { approved: true, approvedAt: now });
259
- }));
260
- fs.writeFileSync(pair, JSON.stringify(paired, null, 2));
261
- fs.writeFileSync(pend, '[]');
262
- console.log('[auto-pair] Approved ' + todo.length + ' device(s)');
263
- } catch(e) { /* ignore */ }
264
- JSEOF
265
- fi
266
- done
267
- ) &
268
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  # ----------------------------------------------------------------
270
  # Gateway loop
271
  # ----------------------------------------------------------------
 
225
  chmod -R go-w "$OPENCLAW_HOME/.openclaw/npm" "$OPENCLAW_HOME/.openclaw/extensions" 2>/dev/null || true
226
 
227
  # ----------------------------------------------------------------
228
+
229
  # ----------------------------------------------------------------
230
+ # One-time browser owner bootstrap
231
+ # ----------------------------------------------------------------
232
+
233
+ if [ "${ENABLE_OWNER_BOOTSTRAP_LINK:-0}" = "1" ]; then
234
+
235
+ (
236
+ log "Waiting for Gateway before owner bootstrap..."
237
+
238
+ i=0
239
+
240
+ while [ "$i" -lt 60 ]; do
241
+
242
+ if openclaw gateway status >/dev/null 2>&1; then
243
+
244
+ log "Gateway ready. Generating owner bootstrap..."
245
+
246
+ if [ -z "${SPACE_HOST:-}" ]; then
247
+ log "ERROR: SPACE_HOST is missing"
248
+ exit 1
249
+ fi
250
+
251
+ DASH_JSON="$(openclaw dashboard --json)" || {
252
+ log "ERROR: dashboard bootstrap failed"
253
+ exit 1
254
+ }
255
+
256
+ OWNER_URL="$(
257
+ printf '%s' "$DASH_JSON" |
258
+ SPACE_HOST="$SPACE_HOST" node -e '
259
+ const fs = require("fs");
260
+
261
+ const data = JSON.parse(fs.readFileSync(0, "utf8"));
262
+
263
+ if (!data.ok || !data.browserUrl) {
264
+ process.exit(2);
265
+ }
 
 
266
 
267
+ const host = process.env.SPACE_HOST;
268
+ const url = new URL(data.browserUrl);
269
+
270
+ // Replace container loopback with HF public origin.
271
+ url.protocol = "https:";
272
+ url.hostname = host;
273
+ url.port = "";
274
+
275
+ // Update Gateway WebSocket destination.
276
+ const params = new URLSearchParams(
277
+ url.hash.replace(/^#/, "")
278
+ );
279
+
280
+ if (!params.has("gatewayUrl")) {
281
+ process.exit(3);
282
+ }
283
+
284
+ params.set("gatewayUrl", "wss://" + host);
285
+ url.hash = params.toString();
286
+
287
+ process.stdout.write(url.toString());
288
+ '
289
+ )" || {
290
+ log "ERROR: unable to construct external browser URL"
291
+ exit 1
292
+ }
293
+
294
+ echo ""
295
+ echo "========== OWNER BOOTSTRAP =========="
296
+ echo "$OWNER_URL"
297
+ echo "========== END BOOTSTRAP ============"
298
+ echo ""
299
+
300
+ unset DASH_JSON OWNER_URL
301
+
302
+ exit 0
303
+ fi
304
+
305
+ sleep 2
306
+ i=$((i+1))
307
+
308
+ done
309
+
310
+ log "ERROR: Gateway did not become ready"
311
+
312
+ ) &
313
+
314
+ fi
315
  # ----------------------------------------------------------------
316
  # Gateway loop
317
  # ----------------------------------------------------------------