e / start-openclaw.sh
sharween's picture
Update start-openclaw.sh
4330ee2 verified
#!/bin/bash
set -e
echo "🚀 Starting OpenClaw with WeChat ClawBot..."
# ================================================
# 1. 补全必要目录
# ================================================
mkdir -p /root/.openclaw/agents/main/sessions
mkdir -p /root/.openclaw/credentials
mkdir -p /root/.openclaw/sessions
echo "✅ 目录创建完成"
# ================================================
# 2. 处理 API 地址
# ================================================
CLEAN_BASE=$(echo "$OPENAI_API_BASE" | sed "s|/chat/completions||g" | sed "s|/v1/|/v1|g" | sed "s|/v1$|/v1|g")
# ================================================
# 3. 生成基础配置文件
# ================================================
cat > /root/.openclaw/openclaw.json <<EOF
{
"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" }
}
},
"plugins": {
"allow": ["openclaw-weixin"]
},
"commands": {
"restart": true
},
"gateway": {
"mode": "local",
"bind": "lan",
"port": $PORT,
"trustedProxies": ["0.0.0.0/0"],
"auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },
"controlUi": {
"enabled": true,
"allowInsecureAuth": true,
"dangerouslyDisableDeviceAuth": true,
"dangerouslyAllowHostHeaderOriginFallback": true
}
}
}
EOF
echo "✅ 基础配置文件生成完成"
# ================================================
# 4. 执行备份恢复
# ================================================
python3 /app/sync.py restore
# ================================================
# 5. 微信插件激活
# ================================================
echo "🔄 微信 ClawBot 激活流程..."
ACCOUNTS_JSON="/root/.openclaw/openclaw-weixin/accounts.json"
if [[ -f "$ACCOUNTS_JSON" ]]; then
echo "✅ 检测到 accounts.json 文件 → 执行快速激活"
openclaw config set plugins.entries.openclaw-weixin.enabled true || true
openclaw channels enable openclaw-weixin 2>/dev/null || true
else
echo "⚠️ 未检测到 accounts.json 文件 → 执行完整重新安装(需要扫码)..."
rm -rf "/root/.openclaw/openclaw-weixin" 2>/dev/null || true
cat > /root/.openclaw/openclaw.json <<EOF
{
"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" }
}
},
"plugins": {
"allow": ["openclaw-weixin"]
},
"commands": {
"restart": true
},
"gateway": {
"mode": "local",
"bind": "lan",
"port": $PORT,
"trustedProxies": ["0.0.0.0/0"],
"auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },
"controlUi": {
"enabled": true,
"allowInsecureAuth": true,
"dangerouslyDisableDeviceAuth": true,
"dangerouslyAllowHostHeaderOriginFallback": true
}
}
}
EOF
npx -y @tencent-weixin/openclaw-weixin-cli@latest install
fi
echo "✅ 微信插件激活流程完成"
# ================================================
# 7. 执行 doctor --fix
# ================================================
echo "🔧 执行 openclaw doctor --fix ..."
openclaw doctor --fix || true
# ================================================
# 6. 安装飞书
# ================================================
#npx -y @larksuite/openclaw-lark install
#npx -y @larksuite/openclaw-lark-tools install
echo "正在检查并批准飞书 pairing 请求..."
# 批准 coder_bot(你现在能用的那个)
openclaw pairing approve feishu --account coder_bot --notify || true
# 批准 main_bot(你想让它也正常工作的那个)
openclaw pairing approve feishu --account main_bot --notify || true
echo "配对处理完成"
# ================================================
# 8. 启动定时备份
# ================================================
echo "⏰ 启动定时备份任务(每1小时)..."
(while true; do
sleep 3600;
python3 /app/sync.py backup;
done) &
# ================================================
# 9. 启动 OpenClaw Gateway
# ================================================
echo "🌟 启动 OpenClaw Gateway..."
exec openclaw gateway run --port $PORT