Update entrypoint.sh
Browse files- entrypoint.sh +35 -90
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 |
-
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,101 +211,46 @@ 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 |
-
# Password-only access.
|
| 216 |
-
# A pairing request only exists AFTER the gateway password/token was accepted,
|
| 217 |
-
# so approving pending requests = "correct password gets in".
|
| 218 |
-
# Security therefore depends entirely on OPENCLAW_GATEWAY_TOKEN being long.
|
| 219 |
-
# Set AUTO_APPROVE_PAIRING=0 (Space variable) to switch this off.
|
| 220 |
-
# ----------------------------------------------------------------
|
| 221 |
-
if [ "${AUTO_APPROVE_PAIRING:-1}" = "1" ]; then
|
| 222 |
(
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 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
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 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
|
| 243 |
-
IDS=$(node - <<'JSEOF'
|
| 244 |
-
const fs = require('fs');
|
| 245 |
-
let data;
|
| 246 |
-
try { data = JSON.parse(fs.readFileSync('/tmp/devices.json', 'utf8')); } catch (e) { process.exit(0); }
|
| 247 |
-
const out = [];
|
| 248 |
-
(function walk(v, key) {
|
| 249 |
-
if (Array.isArray(v)) {
|
| 250 |
-
const pending = /pending/i.test(key || '');
|
| 251 |
-
for (const x of v) {
|
| 252 |
-
if (pending && x && typeof x === 'object') {
|
| 253 |
-
const id = x.requestId || x.id;
|
| 254 |
-
if (typeof id === 'string') out.push(id);
|
| 255 |
-
} else {
|
| 256 |
-
walk(x, key);
|
| 257 |
-
}
|
| 258 |
-
}
|
| 259 |
-
} else if (v && typeof v === 'object') {
|
| 260 |
-
for (const k of Object.keys(v)) walk(v[k], k);
|
| 261 |
-
}
|
| 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 |
-
|
| 279 |
-
|
| 280 |
-
const
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
JSEOF
|
| 298 |
-
|
| 299 |
-
for ID in $IDS; do
|
| 300 |
-
if openclaw devices approve "$ID" </dev/null >/tmp/approve.out 2>&1; then
|
| 301 |
-
log "Approved pairing request $ID"
|
| 302 |
-
else
|
| 303 |
-
warn "approve failed for $ID: $(head -c 200 /tmp/approve.out | tr '\n' ' ')"
|
| 304 |
-
fi
|
| 305 |
-
done
|
| 306 |
done
|
| 307 |
) &
|
| 308 |
-
fi
|
| 309 |
|
| 310 |
# ----------------------------------------------------------------
|
| 311 |
# 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)" log "processes in this container:"
|
|
|
|
| 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 |
chmod -R go-w "$OPENCLAW_HOME/.openclaw/npm" "$OPENCLAW_HOME/.openclaw/extensions" 2>/dev/null || true
|
| 212 |
|
| 213 |
# ----------------------------------------------------------------
|
| 214 |
+
# Auto-approve pending device pairings (background)
|
| 215 |
# ----------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
(
|
| 217 |
+
DEVICES_DIR="$OPENCLAW_HOME/.openclaw/devices"
|
| 218 |
+
mkdir -p "$DEVICES_DIR"
|
| 219 |
+
log "Device auto-pairing watcher started"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
while true; do
|
| 221 |
+
sleep 8
|
| 222 |
+
PENDING="$DEVICES_DIR/pending.json"
|
| 223 |
+
PAIRED="$DEVICES_DIR/paired.json"
|
| 224 |
+
if [ -f "$PENDING" ]; then
|
| 225 |
+
node - << 'JSEOF'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
const fs = require('fs');
|
| 227 |
+
const dir = process.env.OPENCLAW_HOME + '/.openclaw/devices';
|
| 228 |
+
const pend = dir + '/pending.json';
|
| 229 |
+
const pair = dir + '/paired.json';
|
| 230 |
+
try {
|
| 231 |
+
const raw = fs.readFileSync(pend, 'utf-8').trim();
|
| 232 |
+
if (!raw || raw === '[]' || raw === '{}') process.exit(0);
|
| 233 |
+
let pending = JSON.parse(raw);
|
| 234 |
+
if (!Array.isArray(pending)) pending = Object.values(pending);
|
| 235 |
+
if (pending.length === 0) process.exit(0);
|
| 236 |
+
let paired = [];
|
| 237 |
+
try { paired = JSON.parse(fs.readFileSync(pair, 'utf-8')); } catch(e) {}
|
| 238 |
+
if (!Array.isArray(paired)) paired = [];
|
| 239 |
+
const ids = new Set(paired.map(function(d){ return d.id||d.deviceId||d.name; }));
|
| 240 |
+
const todo = pending.filter(function(d){ return !ids.has(d.id||d.deviceId||d.name); });
|
| 241 |
+
if (todo.length === 0) process.exit(0);
|
| 242 |
+
const now = new Date().toISOString();
|
| 243 |
+
paired = paired.concat(todo.map(function(d){
|
| 244 |
+
return Object.assign({}, d, { approved: true, approvedAt: now });
|
| 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
|