Update entrypoint.sh
Browse files- entrypoint.sh +45 -34
entrypoint.sh
CHANGED
|
@@ -189,7 +189,8 @@ 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)"
|
|
@@ -210,46 +211,56 @@ log "Doctor step done."
|
|
| 210 |
chmod -R go-w "$OPENCLAW_HOME/.openclaw/npm" "$OPENCLAW_HOME/.openclaw/extensions" 2>/dev/null || true
|
| 211 |
|
| 212 |
# ----------------------------------------------------------------
|
| 213 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
# ----------------------------------------------------------------
|
|
|
|
| 215 |
(
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
log "Device auto-pairing watcher started"
|
| 219 |
while true; do
|
| 220 |
-
sleep
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
| 225 |
const fs = require('fs');
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
const
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
if (
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
fs.writeFileSync(pair, JSON.stringify(paired, null, 2));
|
| 246 |
-
fs.writeFileSync(pend, '[]');
|
| 247 |
-
console.log('[auto-pair] Approved ' + todo.length + ' device(s)');
|
| 248 |
-
} catch(e) { /* ignore */ }
|
| 249 |
JSEOF
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
done
|
| 252 |
) &
|
|
|
|
| 253 |
|
| 254 |
# ----------------------------------------------------------------
|
| 255 |
# 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)"
|
|
|
|
| 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,
|
| 216 |
+
# so approving pending requests = "correct password gets in".
|
| 217 |
+
# Security therefore depends entirely on OPENCLAW_GATEWAY_TOKEN being long.
|
| 218 |
+
# Set AUTO_APPROVE_PAIRING=0 (Space variable) to switch this off.
|
| 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 || continue
|
| 227 |
+
if [ $SAMPLED -eq 0 ] && [ -s /tmp/devices.json ]; then
|
| 228 |
+
log "devices list sample: $(head -c 300 /tmp/devices.json | tr '\n' ' ')"
|
| 229 |
+
SAMPLED=1
|
| 230 |
+
fi
|
| 231 |
+
IDS=$(node - <<'JSEOF'
|
| 232 |
const fs = require('fs');
|
| 233 |
+
let data;
|
| 234 |
+
try { data = JSON.parse(fs.readFileSync('/tmp/devices.json', 'utf8')); } catch (e) { process.exit(0); }
|
| 235 |
+
const out = [];
|
| 236 |
+
(function walk(v, key) {
|
| 237 |
+
if (Array.isArray(v)) {
|
| 238 |
+
const pending = /pending/i.test(key || '');
|
| 239 |
+
for (const x of v) {
|
| 240 |
+
if (pending && x && typeof x === 'object') {
|
| 241 |
+
const id = x.requestId || x.id;
|
| 242 |
+
if (typeof id === 'string') out.push(id);
|
| 243 |
+
} else {
|
| 244 |
+
walk(x, key);
|
| 245 |
+
}
|
| 246 |
+
}
|
| 247 |
+
} else if (v && typeof v === 'object') {
|
| 248 |
+
for (const k of Object.keys(v)) walk(v[k], k);
|
| 249 |
+
}
|
| 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
|
| 256 |
+
log "Approved pairing request $ID"
|
| 257 |
+
else
|
| 258 |
+
warn "approve failed for $ID: $(head -c 200 /tmp/approve.out | tr '\n' ' ')"
|
| 259 |
+
fi
|
| 260 |
+
done
|
| 261 |
done
|
| 262 |
) &
|
| 263 |
+
fi
|
| 264 |
|
| 265 |
# ----------------------------------------------------------------
|
| 266 |
# Gateway loop
|