Spaces:
Runtime error
Runtime error
File size: 2,997 Bytes
0635916 41f946d 0635916 41f946d 0635916 41f946d 0635916 41f946d 0635916 41f946d c036184 0635916 41f946d 0635916 41f946d 0635916 41f946d 0635916 bcf1893 0635916 41f946d 0635916 41f946d 0635916 c036184 0635916 41f946d 935ed9d 0635916 41f946d 0635916 41f946d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #!/bin/bash
# ปิด Script ทันทีหากเกิด Error และห้ามใช้ตัวแปรที่ไม่ได้ประกาศ
set -euo pipefail
# 1. สร้างไดเรกทอรีที่จำเป็น (ใช้บรรทัดเดียวรวมกัน)
mkdir -p /root/.openclaw/{agents/main/sessions,credentials,sessions}
# 2. เรียกคืนข้อมูล (Restore) ก่อนเริ่มงาน
python3 /app/sync_manager.py restore
# 3. จัดการ API Base URL ให้สะอาด (ลบ /v1 หรือ /chat/completions ที่เกินมา)
# ใช้ Parameter Expansion ของ bash แทน sed เพื่อความเร็ว
CLEAN_BASE="${OPENAI_API_BASE%/chat/completions}"
CLEAN_BASE="${CLEAN_BASE%/}"
CLEAN_BASE="${CLEAN_BASE%/v1}"
# 4. สร้างไฟล์ openclaw.json (ตัดคอมมาเกิน และจัดรูปแบบให้เป๊ะ)
if [ ! -f "/root/.openclaw/openclaw.json" ]; then
echo "🆕 Creating new openclaw.json from environment variables..."
cat > /root/.openclaw/openclaw.json <<EOF
{
"logging": {
"level": "debug",
"consoleLevel": "debug",
"consoleStyle": "pretty",
"redactSensitive": "tools"
},
"session": { "dmScope": "per-channel-peer" },
"models": {
"providers": {
"nvidia": {
"baseUrl": "${CLEAN_BASE}/v1",
"apiKey": "$OPENAI_API_KEY",
"api": "openai-completions",
"models": [
{ "id": "$MODEL", "name": "$MODEL", "contextWindow": 128000 }
]
}
}
},
"agents": { "defaults": { "model": { "primary": "nvidia/$MODEL" } } },
"commands": { "restart": true },
"gateway": {
"mode": "local",
"bind": "lan",
"port": $PORT,
"trustedProxies": ["0.0.0.0/0"],
"auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },
"controlUi": {
"allowedOrigins": ["https://r1000-openclawai.hf.space"],
"enabled": true,
"allowInsecureAuth": true,
"dangerouslyDisableDeviceAuth": true,
"dangerouslyAllowHostHeaderOriginFallback": true
}
},
"tools": {
"agentToAgent": {
"enabled": true,
"allow": ["assistant", "coder", "designer"]
},
"allow": ["exec", "read", "write", "edit", "process", "bash", "sessions_spawn", "sessions_send", "sessions_list", "message", "gateway", "cron"],
"elevated": {
"enabled": true,
"allowFrom": { "line": ["*"], "discord": ["*"] }
}
}
}
EOF
fi
# 7. ตั้งค่าสิทธิ์ไฟล์
chmod -R 700 /root/.openclaw
# 5. เริ่มระบบ Backup อัตโนมัติ (ใส่ & เพื่อรัน background)
python3 sync_manager.py backup &
# 6. ตรวจสอบระบบและรัน Gateway
openclaw doctor --fix
echo "🚀 Starting OpenClaw Gateway on port $PORT..."
exec openclaw gateway run --port "$PORT"
|