Update entrypoint.sh
Browse files- entrypoint.sh +99 -34
entrypoint.sh
CHANGED
|
@@ -189,12 +189,12 @@ clear_stale_locks
|
|
| 189 |
run_doctor
|
| 190 |
if doctor_locked; then
|
| 191 |
warn "doctor blocked by state ownership lock - diagnostics follow"
|
| 192 |
-
log "now (UTC): $(date -u +%Y-%m-%dT%H:%M:%S)"
|
|
|
|
| 193 |
for p in /proc/[0-9]*; do
|
| 194 |
c=$(tr '\0' ' ' < "$p/cmdline" 2>/dev/null)
|
| 195 |
[ -n "$c" ] && echo "[proc] ${p#/proc/}: $(echo "$c" | cut -c1-160)"
|
| 196 |
done
|
| 197 |
-
|
| 198 |
dump_owner "$STATE_DB" 2>/dev/null
|
| 199 |
find "$OPENCLAW_HOME/.openclaw/tmp" -maxdepth 3 2>/dev/null | head -n 30
|
| 200 |
warn "retrying doctor in 30s..."
|
|
@@ -211,46 +211,111 @@ log "Doctor step done."
|
|
| 211 |
chmod -R go-w "$OPENCLAW_HOME/.openclaw/npm" "$OPENCLAW_HOME/.openclaw/extensions" 2>/dev/null || true
|
| 212 |
|
| 213 |
# ----------------------------------------------------------------
|
| 214 |
-
#
|
| 215 |
# ----------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
(
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
while true; do
|
| 221 |
-
sleep
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
const fs = require('fs');
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
const
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
if (
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
fs.writeFileSync(pair, JSON.stringify(paired, null, 2));
|
| 247 |
-
fs.writeFileSync(pend, '[]');
|
| 248 |
-
console.log('[auto-pair] Approved ' + todo.length + ' device(s)');
|
| 249 |
-
} catch(e) { /* ignore */ }
|
| 250 |
JSEOF
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
done
|
| 253 |
) &
|
|
|
|
| 254 |
|
| 255 |
# ----------------------------------------------------------------
|
| 256 |
# Gateway loop
|
|
|
|
| 189 |
run_doctor
|
| 190 |
if doctor_locked; then
|
| 191 |
warn "doctor blocked by state ownership lock - diagnostics follow"
|
| 192 |
+
log "now (UTC): $(date -u +%Y-%m-%dT%H:%M:%S)"
|
| 193 |
+
log "processes in this container:"
|
| 194 |
for p in /proc/[0-9]*; do
|
| 195 |
c=$(tr '\0' ' ' < "$p/cmdline" 2>/dev/null)
|
| 196 |
[ -n "$c" ] && echo "[proc] ${p#/proc/}: $(echo "$c" | cut -c1-160)"
|
| 197 |
done
|
|
|
|
| 198 |
dump_owner "$STATE_DB" 2>/dev/null
|
| 199 |
find "$OPENCLAW_HOME/.openclaw/tmp" -maxdepth 3 2>/dev/null | head -n 30
|
| 200 |
warn "retrying doctor in 30s..."
|
|
|
|
| 211 |
chmod -R go-w "$OPENCLAW_HOME/.openclaw/npm" "$OPENCLAW_HOME/.openclaw/extensions" 2>/dev/null || true
|
| 212 |
|
| 213 |
# ----------------------------------------------------------------
|
| 214 |
+
# Make the CLI default to the same gateway we start below
|
| 215 |
# ----------------------------------------------------------------
|
| 216 |
+
GW_URL="ws://127.0.0.1:7860"
|
| 217 |
+
GW_TOKEN="${OPENCLAW_GATEWAY_TOKEN:-}"
|
| 218 |
+
for kv in "gateway.mode local" "gateway.port 7860"; do
|
| 219 |
+
set -- $kv
|
| 220 |
+
if openclaw config set "$1" "$2" </dev/null >/tmp/cfg.out 2>&1; then
|
| 221 |
+
log "config set $1 = $2"
|
| 222 |
+
else
|
| 223 |
+
warn "config set $1 failed: $(head -c 200 /tmp/cfg.out | tr '\n' ' ')"
|
| 224 |
+
fi
|
| 225 |
+
done
|
| 226 |
+
|
| 227 |
+
if [ "${#GW_TOKEN}" -lt 24 ]; then
|
| 228 |
+
warn "OPENCLAW_GATEWAY_TOKEN is only ${#GW_TOKEN} chars - with password-only access it should be 32+ letters/digits"
|
| 229 |
+
fi
|
| 230 |
+
|
| 231 |
+
# ----------------------------------------------------------------
|
| 232 |
+
# Password-only access (no manual device approval).
|
| 233 |
+
# A pairing request exists only AFTER the gateway password/token was accepted,
|
| 234 |
+
# so approving pending requests == "correct password gets in".
|
| 235 |
+
# Security therefore depends entirely on OPENCLAW_GATEWAY_TOKEN being long.
|
| 236 |
+
# Set AUTO_APPROVE_PAIRING=0 (Space variable) to switch this off.
|
| 237 |
+
# Request IDs are collected from two places:
|
| 238 |
+
# 1) `openclaw devices list --json`
|
| 239 |
+
# 2) the gateway log ("pairing required ... requestId: <uuid>")
|
| 240 |
+
# ----------------------------------------------------------------
|
| 241 |
+
UUID_RE='[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}'
|
| 242 |
+
|
| 243 |
+
try_approve() {
|
| 244 |
+
ID="$1"
|
| 245 |
+
grep -qx "$ID" /tmp/approved.ids 2>/dev/null && return 0
|
| 246 |
+
N=$(cat "/tmp/fail.$ID" 2>/dev/null || echo 0)
|
| 247 |
+
[ "$N" -ge 2 ] && return 0
|
| 248 |
+
if openclaw devices approve "$ID" --url "$GW_URL" --token "$GW_TOKEN" </dev/null >/tmp/approve.out 2>&1 \
|
| 249 |
+
|| openclaw devices approve "$ID" </dev/null >/tmp/approve.out 2>&1; then
|
| 250 |
+
echo "$ID" >> /tmp/approved.ids
|
| 251 |
+
log "Approved pairing request $ID"
|
| 252 |
+
else
|
| 253 |
+
echo $((N+1)) > "/tmp/fail.$ID"
|
| 254 |
+
warn "approve failed for $ID: $(head -c 300 /tmp/approve.out | tr '\n' ' ')"
|
| 255 |
+
fi
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
if [ "${AUTO_APPROVE_PAIRING:-1}" = "1" ]; then
|
| 259 |
(
|
| 260 |
+
log "Pairing auto-approver started (only requests that already passed gateway auth)"
|
| 261 |
+
FAILS=0
|
| 262 |
+
SAMPLED=0
|
| 263 |
while true; do
|
| 264 |
+
sleep 4
|
| 265 |
+
|
| 266 |
+
# source 1: CLI device list
|
| 267 |
+
IDS=""
|
| 268 |
+
if openclaw devices list --json --url "$GW_URL" --token "$GW_TOKEN" </dev/null >/tmp/devices.json 2>/tmp/devices.err \
|
| 269 |
+
|| openclaw devices list --json </dev/null >/tmp/devices.json 2>/tmp/devices.err; then
|
| 270 |
+
if [ $SAMPLED -eq 0 ]; then
|
| 271 |
+
log "devices list sample: $(head -c 300 /tmp/devices.json | tr '\n' ' ')"
|
| 272 |
+
SAMPLED=1
|
| 273 |
+
fi
|
| 274 |
+
IDS=$(node - <<'JSEOF'
|
| 275 |
const fs = require('fs');
|
| 276 |
+
let data;
|
| 277 |
+
try { data = JSON.parse(fs.readFileSync('/tmp/devices.json', 'utf8')); } catch (e) { process.exit(0); }
|
| 278 |
+
const out = [];
|
| 279 |
+
(function walk(v, key) {
|
| 280 |
+
if (Array.isArray(v)) {
|
| 281 |
+
const pending = /pending/i.test(key || '');
|
| 282 |
+
for (const x of v) {
|
| 283 |
+
if (pending && x && typeof x === 'object') {
|
| 284 |
+
const id = x.requestId || x.id;
|
| 285 |
+
if (typeof id === 'string') out.push(id);
|
| 286 |
+
} else {
|
| 287 |
+
walk(x, key);
|
| 288 |
+
}
|
| 289 |
+
}
|
| 290 |
+
} else if (v && typeof v === 'object') {
|
| 291 |
+
for (const k of Object.keys(v)) walk(v[k], k);
|
| 292 |
+
}
|
| 293 |
+
})(data, '');
|
| 294 |
+
console.log(out.join('\n'));
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
JSEOF
|
| 296 |
+
)
|
| 297 |
+
else
|
| 298 |
+
FAILS=$((FAILS+1))
|
| 299 |
+
if [ $FAILS -eq 8 ] || [ $((FAILS % 30)) -eq 0 ]; then
|
| 300 |
+
warn "devices list keeps failing: $(head -c 300 /tmp/devices.err | tr '\n' ' ') | $(head -c 200 /tmp/devices.json | tr '\n' ' ')"
|
| 301 |
+
fi
|
| 302 |
+
fi
|
| 303 |
+
|
| 304 |
+
# source 2: request IDs printed by the gateway when a browser is waiting for approval
|
| 305 |
+
LOGIDS=""
|
| 306 |
+
LATEST=$(ls -t /tmp/openclaw/openclaw-*.log 2>/dev/null | head -n 1)
|
| 307 |
+
if [ -n "$LATEST" ]; then
|
| 308 |
+
LOGIDS=$(tail -n 300 "$LATEST" 2>/dev/null \
|
| 309 |
+
| grep -o "requestId[^0-9a-f]\{0,4\}$UUID_RE" \
|
| 310 |
+
| grep -o "$UUID_RE" | sort -u)
|
| 311 |
fi
|
| 312 |
+
|
| 313 |
+
for ID in $IDS $LOGIDS; do
|
| 314 |
+
try_approve "$ID"
|
| 315 |
+
done
|
| 316 |
done
|
| 317 |
) &
|
| 318 |
+
fi
|
| 319 |
|
| 320 |
# ----------------------------------------------------------------
|
| 321 |
# Gateway loop
|