Update entrypoint.sh
Browse files- entrypoint.sh +47 -2
entrypoint.sh
CHANGED
|
@@ -210,6 +210,7 @@ log "Doctor step done."
|
|
| 210 |
# Plugins must not be world-writable or OpenClaw blocks them
|
| 211 |
chmod -R go-w "$OPENCLAW_HOME/.openclaw/npm" "$OPENCLAW_HOME/.openclaw/extensions" 2>/dev/null || true
|
| 212 |
|
|
|
|
| 213 |
# ----------------------------------------------------------------
|
| 214 |
# Password-only access.
|
| 215 |
# A pairing request only exists AFTER the gateway password/token was accepted,
|
|
@@ -219,12 +220,23 @@ chmod -R go-w "$OPENCLAW_HOME/.openclaw/npm" "$OPENCLAW_HOME/.openclaw/extension
|
|
| 219 |
# ----------------------------------------------------------------
|
| 220 |
if [ "${AUTO_APPROVE_PAIRING:-1}" = "1" ]; then
|
| 221 |
(
|
|
|
|
| 222 |
log "Pairing auto-approver started (only requests that already passed gateway auth)"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
SAMPLED=0
|
| 224 |
while true; do
|
| 225 |
sleep 5
|
| 226 |
-
openclaw devices list --json </dev/null >/tmp/devices.json 2>/tmp/devices.err
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
log "devices list sample: $(head -c 300 /tmp/devices.json | tr '\n' ' ')"
|
| 229 |
SAMPLED=1
|
| 230 |
fi
|
|
@@ -250,6 +262,39 @@ const out = [];
|
|
| 250 |
})(data, '');
|
| 251 |
console.log(out.join('\n'));
|
| 252 |
JSEOF
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
)
|
| 254 |
for ID in $IDS; do
|
| 255 |
if openclaw devices approve "$ID" </dev/null >/tmp/approve.out 2>&1; then
|
|
|
|
| 210 |
# Plugins must not be world-writable or OpenClaw blocks them
|
| 211 |
chmod -R go-w "$OPENCLAW_HOME/.openclaw/npm" "$OPENCLAW_HOME/.openclaw/extensions" 2>/dev/null || true
|
| 212 |
|
| 213 |
+
# ----------------------------------------------------------------
|
| 214 |
# ----------------------------------------------------------------
|
| 215 |
# Password-only access.
|
| 216 |
# A pairing request only exists AFTER the gateway password/token was accepted,
|
|
|
|
| 220 |
# ----------------------------------------------------------------
|
| 221 |
if [ "${AUTO_APPROVE_PAIRING:-1}" = "1" ]; then
|
| 222 |
(
|
| 223 |
+
GW_URL="ws://127.0.0.1:7860"
|
| 224 |
log "Pairing auto-approver started (only requests that already passed gateway auth)"
|
| 225 |
+
if [ -z "${OPENCLAW_GATEWAY_TOKEN:-}" ]; then
|
| 226 |
+
warn "OPENCLAW_GATEWAY_TOKEN is empty - auto-approver cannot authenticate"
|
| 227 |
+
fi
|
| 228 |
+
FAILS=0
|
| 229 |
SAMPLED=0
|
| 230 |
while true; do
|
| 231 |
sleep 5
|
| 232 |
+
if ! openclaw devices list --json --url "$GW_URL" --token "${OPENCLAW_GATEWAY_TOKEN:-}" </dev/null >/tmp/devices.json 2>/tmp/devices.err; then
|
| 233 |
+
if [ $((FAILS % 12)) -eq 0 ]; then
|
| 234 |
+
warn "devices list failed: $(head -c 300 /tmp/devices.err | tr '\n' ' ') | $(head -c 200 /tmp/devices.json | tr '\n' ' ')"
|
| 235 |
+
fi
|
| 236 |
+
FAILS=$((FAILS+1))
|
| 237 |
+
continue
|
| 238 |
+
fi
|
| 239 |
+
if [ $SAMPLED -eq 0 ]; then
|
| 240 |
log "devices list sample: $(head -c 300 /tmp/devices.json | tr '\n' ' ')"
|
| 241 |
SAMPLED=1
|
| 242 |
fi
|
|
|
|
| 262 |
})(data, '');
|
| 263 |
console.log(out.join('\n'));
|
| 264 |
JSEOF
|
| 265 |
+
)
|
| 266 |
+
for ID in $IDS; do
|
| 267 |
+
if openclaw devices approve "$ID" --url "$GW_URL" --token "${OPENCLAW_GATEWAY_TOKEN:-}" </dev/null >/tmp/approve.out 2>&1; then
|
| 268 |
+
log "Approved pairing request $ID"
|
| 269 |
+
else
|
| 270 |
+
warn "approve failed for $ID: $(head -c 200 /tmp/approve.out | tr '\n' ' ')"
|
| 271 |
+
fi
|
| 272 |
+
done
|
| 273 |
+
done
|
| 274 |
+
) &
|
| 275 |
+
fi
|
| 276 |
+
IDS=$(node - <<'JSEOF'
|
| 277 |
+
const fs = require('fs');
|
| 278 |
+
let data;
|
| 279 |
+
try { data = JSON.parse(fs.readFileSync('/tmp/devices.json', 'utf8')); } catch (e) { process.exit(0); }
|
| 280 |
+
const out = [];
|
| 281 |
+
(function walk(v, key) {
|
| 282 |
+
if (Array.isArray(v)) {
|
| 283 |
+
const pending = /pending/i.test(key || '');
|
| 284 |
+
for (const x of v) {
|
| 285 |
+
if (pending && x && typeof x === 'object') {
|
| 286 |
+
const id = x.requestId || x.id;
|
| 287 |
+
if (typeof id === 'string') out.push(id);
|
| 288 |
+
} else {
|
| 289 |
+
walk(x, key);
|
| 290 |
+
}
|
| 291 |
+
}
|
| 292 |
+
} else if (v && typeof v === 'object') {
|
| 293 |
+
for (const k of Object.keys(v)) walk(v[k], k);
|
| 294 |
+
}
|
| 295 |
+
})(data, '');
|
| 296 |
+
console.log(out.join('\n'));
|
| 297 |
+
JSEOF
|
| 298 |
)
|
| 299 |
for ID in $IDS; do
|
| 300 |
if openclaw devices approve "$ID" </dev/null >/tmp/approve.out 2>&1; then
|