Update entrypoint.sh
Browse files- entrypoint.sh +13 -22
entrypoint.sh
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
#!/bin/sh
|
| 2 |
-
# OpenClaw HF Spaces
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
-
OPENCLAW_BIN="${OPENCLAW_APP:-/home/node/.openclaw/app}/openclaw.mjs"
|
| 6 |
|
| 7 |
ts() { date -u +"%H:%M:%S"; }
|
| 8 |
log() { echo "[$(ts)] [entrypoint] $*"; }
|
|
@@ -39,12 +37,12 @@ export OPENCLAW_HOME
|
|
| 39 |
log "OPENCLAW_HOME=$OPENCLAW_HOME"
|
| 40 |
|
| 41 |
# ----------------------------------------------------------------
|
| 42 |
-
# Clean up stale
|
| 43 |
# ----------------------------------------------------------------
|
| 44 |
EXTENSIONS_DIR="$OPENCLAW_HOME/.openclaw/extensions"
|
| 45 |
if [ -d "$EXTENSIONS_DIR" ]; then
|
| 46 |
-
log "Removing stale extensions dir
|
| 47 |
-
rm -rf "$EXTENSIONS_DIR" ||
|
| 48 |
fi
|
| 49 |
|
| 50 |
CONFIG_PATH="$OPENCLAW_HOME/.openclaw/openclaw.json"
|
|
@@ -60,12 +58,12 @@ try {
|
|
| 60 |
fs.writeFileSync(p, JSON.stringify(cfg, null, 2), 'utf-8');
|
| 61 |
console.log('[entrypoint] Removed stale plugins config');
|
| 62 |
}
|
| 63 |
-
} catch(e) {
|
| 64 |
JSEOF
|
| 65 |
fi
|
| 66 |
|
| 67 |
# ----------------------------------------------------------------
|
| 68 |
-
# Export provider API keys
|
| 69 |
# ----------------------------------------------------------------
|
| 70 |
for VAR in $(env | cut -d= -f1); do
|
| 71 |
case "$VAR" in
|
|
@@ -101,7 +99,6 @@ fi
|
|
| 101 |
(
|
| 102 |
DEVICES_DIR="$OPENCLAW_HOME/.openclaw/devices"
|
| 103 |
mkdir -p "$DEVICES_DIR"
|
| 104 |
-
log "Device auto-pairing watcher started"
|
| 105 |
while true; do
|
| 106 |
sleep 8
|
| 107 |
PENDING="$DEVICES_DIR/pending.json"
|
|
@@ -121,13 +118,11 @@ try {
|
|
| 121 |
let paired = [];
|
| 122 |
try { paired = JSON.parse(fs.readFileSync(pair, 'utf-8')); } catch(e) {}
|
| 123 |
if (!Array.isArray(paired)) paired = [];
|
| 124 |
-
const ids = new Set(paired.map(
|
| 125 |
-
const todo = pending.filter(
|
| 126 |
if (todo.length === 0) process.exit(0);
|
| 127 |
const now = new Date().toISOString();
|
| 128 |
-
paired = paired.concat(todo.map(
|
| 129 |
-
return Object.assign({}, d, { approved: true, approvedAt: now });
|
| 130 |
-
}));
|
| 131 |
fs.writeFileSync(pair, JSON.stringify(paired, null, 2));
|
| 132 |
fs.writeFileSync(pend, '[]');
|
| 133 |
console.log('[auto-pair] Approved ' + todo.length + ' device(s)');
|
|
@@ -138,15 +133,14 @@ JSEOF
|
|
| 138 |
) &
|
| 139 |
|
| 140 |
# ----------------------------------------------------------------
|
| 141 |
-
# Gateway loop
|
| 142 |
# ----------------------------------------------------------------
|
| 143 |
log "Starting gateway loop..."
|
| 144 |
-
log "Using OpenClaw binary: $OPENCLAW_BIN"
|
| 145 |
|
| 146 |
while true; do
|
| 147 |
log "Gateway starting..."
|
| 148 |
|
| 149 |
-
|
| 150 |
--allow-unconfigured \
|
| 151 |
--bind lan \
|
| 152 |
--port 7860
|
|
@@ -167,10 +161,7 @@ while true; do
|
|
| 167 |
fi
|
| 168 |
done
|
| 169 |
|
| 170 |
-
|
| 171 |
-
log "Port free after ${WAITED}s"
|
| 172 |
-
fi
|
| 173 |
-
|
| 174 |
sleep 1
|
| 175 |
log "Restarting gateway..."
|
| 176 |
done
|
|
|
|
| 1 |
#!/bin/sh
|
| 2 |
+
# OpenClaw HF Spaces — Entrypoint
|
| 3 |
+
# openclaw installed globally via npm → available as `openclaw` in PATH
|
|
|
|
|
|
|
| 4 |
|
| 5 |
ts() { date -u +"%H:%M:%S"; }
|
| 6 |
log() { echo "[$(ts)] [entrypoint] $*"; }
|
|
|
|
| 37 |
log "OPENCLAW_HOME=$OPENCLAW_HOME"
|
| 38 |
|
| 39 |
# ----------------------------------------------------------------
|
| 40 |
+
# Clean up stale extensions (uid mismatch fix)
|
| 41 |
# ----------------------------------------------------------------
|
| 42 |
EXTENSIONS_DIR="$OPENCLAW_HOME/.openclaw/extensions"
|
| 43 |
if [ -d "$EXTENSIONS_DIR" ]; then
|
| 44 |
+
log "Removing stale extensions dir..."
|
| 45 |
+
rm -rf "$EXTENSIONS_DIR" || true
|
| 46 |
fi
|
| 47 |
|
| 48 |
CONFIG_PATH="$OPENCLAW_HOME/.openclaw/openclaw.json"
|
|
|
|
| 58 |
fs.writeFileSync(p, JSON.stringify(cfg, null, 2), 'utf-8');
|
| 59 |
console.log('[entrypoint] Removed stale plugins config');
|
| 60 |
}
|
| 61 |
+
} catch(e) {}
|
| 62 |
JSEOF
|
| 63 |
fi
|
| 64 |
|
| 65 |
# ----------------------------------------------------------------
|
| 66 |
+
# Export provider API keys from Secrets
|
| 67 |
# ----------------------------------------------------------------
|
| 68 |
for VAR in $(env | cut -d= -f1); do
|
| 69 |
case "$VAR" in
|
|
|
|
| 99 |
(
|
| 100 |
DEVICES_DIR="$OPENCLAW_HOME/.openclaw/devices"
|
| 101 |
mkdir -p "$DEVICES_DIR"
|
|
|
|
| 102 |
while true; do
|
| 103 |
sleep 8
|
| 104 |
PENDING="$DEVICES_DIR/pending.json"
|
|
|
|
| 118 |
let paired = [];
|
| 119 |
try { paired = JSON.parse(fs.readFileSync(pair, 'utf-8')); } catch(e) {}
|
| 120 |
if (!Array.isArray(paired)) paired = [];
|
| 121 |
+
const ids = new Set(paired.map(d => d.id||d.deviceId||d.name));
|
| 122 |
+
const todo = pending.filter(d => !ids.has(d.id||d.deviceId||d.name));
|
| 123 |
if (todo.length === 0) process.exit(0);
|
| 124 |
const now = new Date().toISOString();
|
| 125 |
+
paired = paired.concat(todo.map(d => Object.assign({}, d, { approved: true, approvedAt: now })));
|
|
|
|
|
|
|
| 126 |
fs.writeFileSync(pair, JSON.stringify(paired, null, 2));
|
| 127 |
fs.writeFileSync(pend, '[]');
|
| 128 |
console.log('[auto-pair] Approved ' + todo.length + ' device(s)');
|
|
|
|
| 133 |
) &
|
| 134 |
|
| 135 |
# ----------------------------------------------------------------
|
| 136 |
+
# Gateway loop
|
| 137 |
# ----------------------------------------------------------------
|
| 138 |
log "Starting gateway loop..."
|
|
|
|
| 139 |
|
| 140 |
while true; do
|
| 141 |
log "Gateway starting..."
|
| 142 |
|
| 143 |
+
openclaw gateway \
|
| 144 |
--allow-unconfigured \
|
| 145 |
--bind lan \
|
| 146 |
--port 7860
|
|
|
|
| 161 |
fi
|
| 162 |
done
|
| 163 |
|
| 164 |
+
[ $WAITED -gt 0 ] && log "Port free after ${WAITED}s"
|
|
|
|
|
|
|
|
|
|
| 165 |
sleep 1
|
| 166 |
log "Restarting gateway..."
|
| 167 |
done
|