OpenClawAI / entrypoint.sh.bak
R1000's picture
Rename entrypoint.sh to entrypoint.sh.bak
dc6fd72 verified
#!/bin/bash
# 1. สร้างโฟลเดอร์หลักก่อนเสมอ
mkdir -p /root/.openclaw
# 2. Restore ข้อมูลจาก Cloud ก่อน (ถ้ามี)
python3 sync_manager.py restore
# 3. จัดการที่อยู่ API ให้สะอาด (Sanitize)
# ใช้ CLEAN_BASE ใน baseUrl แทนค่าดิบ เพื่อป้องกัน Path ซ้ำซ้อน
CLEAN_BASE=$(echo "$OPENAI_API_BASE" | sed "s|/chat/completions||g" | sed "s|/v1/|/v1|g" | sed "s|/v1$|/v1|g")
# 4. สร้างไฟล์ openclaw.json เฉพาะกรณีที่ยังไม่มีจากการ Restore เท่านั้น
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",
"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": 7860,
"trustedProxies": ["0.0.0.0/0"],
"auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },
"controlUi": {
"allowedOrigins": ["*"],
"enabled": true,
"allowInsecureAuth": true,
"dangerouslyDisableDeviceAuth": true,
"dangerouslyAllowHostHeaderOriginFallback": true
}
},
"tools": {
"agentToAgent": {
"enabled": true,
"allow": ["*"]
},
"allow": ["exec", "read", "write", "edit", "process", "bash", "sessions_spawn", "sessions_send", "sessions_list", "message", "gateway", "cron"],
"deny": [],
"elevated": {
"enabled": true,
"allowFrom": {
"line": ["*"],
"discord": ["*"]
}
}
},
"channels": {
"discord": {
"enabled": true,
"token": "${DISCORD_BOT_TOKEN}",
"dangerouslyAllowNameMatching": true,
"dm": {
"enabled": true,
"allowFrom": ["${DISCORD_ALLOWED_USER_ID}"]
}
}
}
}
EOF
fi
# 5. ตั้งค่าสิทธิ์ไฟล์ (ป้องกัน Doctor เตือนเรื่อง Permissions)
chmod -R 700 /root/.openclaw
# 6. เริ่มระบบ Backup ใน Background (ทุก 60 นาที)
python3 sync_manager.py backup &
echo "=== Running openclaw doctor to fix config ==="
node /app/openclaw.mjs doctor --fix || echo "⚠️ Doctor fix failed, continuing anyway..."
echo "✅ Config fixed"
# 7. รัน OpenClaw
echo "🚀 Starting OpenClaw on port 7860..."
exec node /app/openclaw.mjs gateway --port 7860 --bind lan --allow-unconfigured