@blockrun/clawrouter 0.12.110 → 0.12.112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/reinstall.sh +138 -0
- package/scripts/update.sh +33 -0
package/package.json
CHANGED
package/scripts/reinstall.sh
CHANGED
|
@@ -62,6 +62,20 @@ run_dependency_install() {
|
|
|
62
62
|
|
|
63
63
|
trap restore_previous_install EXIT
|
|
64
64
|
|
|
65
|
+
# Pre-flight: validate openclaw.json is parseable before touching anything
|
|
66
|
+
validate_config() {
|
|
67
|
+
local config_path="$HOME/.openclaw/openclaw.json"
|
|
68
|
+
if [ ! -f "$config_path" ]; then return 0; fi
|
|
69
|
+
if ! node -e "JSON.parse(require('fs').readFileSync('$config_path','utf8'))" 2>/dev/null; then
|
|
70
|
+
echo ""
|
|
71
|
+
echo "✗ openclaw.json is corrupt (invalid JSON)."
|
|
72
|
+
echo " Fix it first: openclaw doctor --fix"
|
|
73
|
+
echo " Then re-run this script."
|
|
74
|
+
echo ""
|
|
75
|
+
exit 1
|
|
76
|
+
fi
|
|
77
|
+
}
|
|
78
|
+
|
|
65
79
|
kill_port_processes() {
|
|
66
80
|
local port="$1"
|
|
67
81
|
local pids=""
|
|
@@ -87,6 +101,9 @@ kill_port_processes() {
|
|
|
87
101
|
echo "🦞 ClawRouter Reinstall"
|
|
88
102
|
echo ""
|
|
89
103
|
|
|
104
|
+
# Pre-flight: fail fast if config is corrupt
|
|
105
|
+
validate_config
|
|
106
|
+
|
|
90
107
|
# 0. Back up wallet key BEFORE removing anything
|
|
91
108
|
echo "→ Backing up wallet..."
|
|
92
109
|
if [ -f "$WALLET_FILE" ]; then
|
|
@@ -312,6 +329,26 @@ if [ -d "$CREDS_DIR" ] && [ "$(ls -A "$CREDS_DIR" 2>/dev/null)" ]; then
|
|
|
312
329
|
echo " ✓ Backed up OpenClaw credentials"
|
|
313
330
|
fi
|
|
314
331
|
|
|
332
|
+
# Extract channel config (Telegram tokens, etc.) from openclaw.json before install
|
|
333
|
+
# openclaw plugins install can overwrite config and wipe channel settings
|
|
334
|
+
CHANNEL_CONFIG_BACKUP=""
|
|
335
|
+
if [ -f "$CONFIG_PATH" ]; then
|
|
336
|
+
CHANNEL_CONFIG_BACKUP="$(mktemp)"
|
|
337
|
+
node -e "
|
|
338
|
+
const fs = require('fs');
|
|
339
|
+
try {
|
|
340
|
+
const config = JSON.parse(fs.readFileSync('$CONFIG_PATH', 'utf8'));
|
|
341
|
+
// Save channels block and gateway block (gateway.mode etc.)
|
|
342
|
+
const preserved = {};
|
|
343
|
+
if (config.channels) preserved.channels = config.channels;
|
|
344
|
+
if (config.gateway) preserved.gateway = config.gateway;
|
|
345
|
+
fs.writeFileSync('$CHANNEL_CONFIG_BACKUP', JSON.stringify(preserved, null, 2));
|
|
346
|
+
const channelCount = Object.keys(config.channels || {}).length;
|
|
347
|
+
if (channelCount > 0) console.log(' ✓ Preserved config for channels: ' + Object.keys(config.channels).join(', '));
|
|
348
|
+
} catch (e) { fs.writeFileSync('$CHANNEL_CONFIG_BACKUP', '{}'); }
|
|
349
|
+
"
|
|
350
|
+
fi
|
|
351
|
+
|
|
315
352
|
echo "→ Installing ClawRouter..."
|
|
316
353
|
openclaw plugins install @blockrun/clawrouter
|
|
317
354
|
|
|
@@ -323,6 +360,59 @@ if [ -n "$CREDS_BACKUP" ] && [ -d "$CREDS_BACKUP" ]; then
|
|
|
323
360
|
rm -rf "$(dirname "$CREDS_BACKUP")"
|
|
324
361
|
fi
|
|
325
362
|
|
|
363
|
+
# Restore channel config (Telegram tokens etc.) that may have been wiped by plugin install
|
|
364
|
+
if [ -n "$CHANNEL_CONFIG_BACKUP" ] && [ -f "$CHANNEL_CONFIG_BACKUP" ] && [ -f "$CONFIG_PATH" ]; then
|
|
365
|
+
node -e "
|
|
366
|
+
const fs = require('fs');
|
|
367
|
+
function atomicWrite(filePath, data) {
|
|
368
|
+
const tmpPath = filePath + '.tmp.' + process.pid;
|
|
369
|
+
fs.writeFileSync(tmpPath, data);
|
|
370
|
+
fs.renameSync(tmpPath, filePath);
|
|
371
|
+
}
|
|
372
|
+
try {
|
|
373
|
+
const config = JSON.parse(fs.readFileSync('$CONFIG_PATH', 'utf8'));
|
|
374
|
+
const preserved = JSON.parse(fs.readFileSync('$CHANNEL_CONFIG_BACKUP', 'utf8'));
|
|
375
|
+
let changed = false;
|
|
376
|
+
|
|
377
|
+
// Restore channels block if it was wiped or is now empty
|
|
378
|
+
if (preserved.channels && Object.keys(preserved.channels).length > 0) {
|
|
379
|
+
if (!config.channels || Object.keys(config.channels).length === 0) {
|
|
380
|
+
config.channels = preserved.channels;
|
|
381
|
+
changed = true;
|
|
382
|
+
console.log(' ✓ Restored channel config (Telegram/WhatsApp/etc.)');
|
|
383
|
+
} else {
|
|
384
|
+
// Merge: restore any channels that are now missing
|
|
385
|
+
let merged = 0;
|
|
386
|
+
for (const [ch, val] of Object.entries(preserved.channels)) {
|
|
387
|
+
if (!config.channels[ch]) {
|
|
388
|
+
config.channels[ch] = val;
|
|
389
|
+
merged++;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (merged > 0) {
|
|
393
|
+
changed = true;
|
|
394
|
+
console.log(' ✓ Merged ' + merged + ' missing channel(s) back into config');
|
|
395
|
+
} else {
|
|
396
|
+
console.log(' Channel config intact');
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// Restore gateway.mode if missing
|
|
402
|
+
if (preserved.gateway?.mode && (!config.gateway || !config.gateway.mode)) {
|
|
403
|
+
if (!config.gateway) config.gateway = {};
|
|
404
|
+
config.gateway.mode = preserved.gateway.mode;
|
|
405
|
+
changed = true;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (changed) atomicWrite('$CONFIG_PATH', JSON.stringify(config, null, 2));
|
|
409
|
+
} catch (e) {
|
|
410
|
+
console.log(' Warning: could not restore channel config:', e.message);
|
|
411
|
+
}
|
|
412
|
+
"
|
|
413
|
+
rm -f "$CHANNEL_CONFIG_BACKUP"
|
|
414
|
+
fi
|
|
415
|
+
|
|
326
416
|
# 6.1. Verify installation and force-update if openclaw installed a stale cached version
|
|
327
417
|
echo "→ Verifying installation..."
|
|
328
418
|
DIST_PATH="$PLUGIN_DIR/dist/index.js"
|
|
@@ -519,6 +609,54 @@ if (fs.existsSync(configPath)) {
|
|
|
519
609
|
}
|
|
520
610
|
"
|
|
521
611
|
|
|
612
|
+
# 8. Ensure gateway.mode is set (required by OpenClaw v2026.4.5+)
|
|
613
|
+
echo "→ Ensuring gateway.mode is set..."
|
|
614
|
+
node -e "
|
|
615
|
+
const os = require('os');
|
|
616
|
+
const fs = require('fs');
|
|
617
|
+
const path = require('path');
|
|
618
|
+
const configPath = path.join(os.homedir(), '.openclaw', 'openclaw.json');
|
|
619
|
+
function atomicWrite(filePath, data) {
|
|
620
|
+
const tmpPath = filePath + '.tmp.' + process.pid;
|
|
621
|
+
fs.writeFileSync(tmpPath, data);
|
|
622
|
+
fs.renameSync(tmpPath, filePath);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
if (fs.existsSync(configPath)) {
|
|
626
|
+
try {
|
|
627
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
628
|
+
if (!config.gateway) config.gateway = {};
|
|
629
|
+
if (!config.gateway.mode) {
|
|
630
|
+
config.gateway.mode = 'local';
|
|
631
|
+
atomicWrite(configPath, JSON.stringify(config, null, 2));
|
|
632
|
+
console.log(' Set gateway.mode = local (required by OpenClaw v2026.4.5+)');
|
|
633
|
+
} else {
|
|
634
|
+
console.log(' gateway.mode already set: ' + config.gateway.mode);
|
|
635
|
+
}
|
|
636
|
+
} catch (e) {
|
|
637
|
+
console.log(' Could not update config:', e.message);
|
|
638
|
+
console.log(' Fix manually: openclaw config set gateway.mode local');
|
|
639
|
+
}
|
|
640
|
+
} else {
|
|
641
|
+
console.log(' No openclaw.json found, skipping');
|
|
642
|
+
}
|
|
643
|
+
"
|
|
644
|
+
|
|
645
|
+
# Clean up stale plugin backups — these cause "duplicate plugin" warnings on restart
|
|
646
|
+
echo "→ Cleaning up stale plugin backups..."
|
|
647
|
+
CLEANED=0
|
|
648
|
+
for backup_dir in "$HOME/.openclaw/extensions/clawrouter.backup."*; do
|
|
649
|
+
if [ -d "$backup_dir" ]; then
|
|
650
|
+
rm -rf "$backup_dir"
|
|
651
|
+
CLEANED=$((CLEANED + 1))
|
|
652
|
+
fi
|
|
653
|
+
done
|
|
654
|
+
if [ "$CLEANED" -gt 0 ]; then
|
|
655
|
+
echo " ✓ Removed $CLEANED stale backup(s)"
|
|
656
|
+
else
|
|
657
|
+
echo " ✓ No stale backups found"
|
|
658
|
+
fi
|
|
659
|
+
|
|
522
660
|
# Final: verify wallet survived reinstall
|
|
523
661
|
echo "→ Verifying wallet integrity..."
|
|
524
662
|
if [ -f "$WALLET_FILE" ]; then
|
package/scripts/update.sh
CHANGED
|
@@ -405,6 +405,39 @@ try {
|
|
|
405
405
|
}
|
|
406
406
|
"
|
|
407
407
|
|
|
408
|
+
# Ensure gateway.mode is set (required by OpenClaw v2026.4.5+)
|
|
409
|
+
echo "→ Ensuring gateway.mode is set..."
|
|
410
|
+
node -e "
|
|
411
|
+
const os = require('os');
|
|
412
|
+
const fs = require('fs');
|
|
413
|
+
const path = require('path');
|
|
414
|
+
const configPath = path.join(os.homedir(), '.openclaw', 'openclaw.json');
|
|
415
|
+
function atomicWrite(filePath, data) {
|
|
416
|
+
const tmpPath = filePath + '.tmp.' + process.pid;
|
|
417
|
+
fs.writeFileSync(tmpPath, data);
|
|
418
|
+
fs.renameSync(tmpPath, filePath);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (fs.existsSync(configPath)) {
|
|
422
|
+
try {
|
|
423
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
424
|
+
if (!config.gateway) config.gateway = {};
|
|
425
|
+
if (!config.gateway.mode) {
|
|
426
|
+
config.gateway.mode = 'local';
|
|
427
|
+
atomicWrite(configPath, JSON.stringify(config, null, 2));
|
|
428
|
+
console.log(' Set gateway.mode = local (required by OpenClaw v2026.4.5+)');
|
|
429
|
+
} else {
|
|
430
|
+
console.log(' gateway.mode already set: ' + config.gateway.mode);
|
|
431
|
+
}
|
|
432
|
+
} catch (e) {
|
|
433
|
+
console.log(' Could not update config:', e.message);
|
|
434
|
+
console.log(' Fix manually: openclaw config set gateway.mode local');
|
|
435
|
+
}
|
|
436
|
+
} else {
|
|
437
|
+
console.log(' No openclaw.json found, skipping');
|
|
438
|
+
}
|
|
439
|
+
"
|
|
440
|
+
|
|
408
441
|
# ── Summary ─────────────────────────────────────────────────────
|
|
409
442
|
echo ""
|
|
410
443
|
echo "✓ ClawRouter updated successfully!"
|