e
File size: 4,635 Bytes
87feb79
81c81ae
87feb79
0757bb8
2ae12c9
 
 
 
 
5f675c9
 
 
 
2ae12c9
 
 
062a8c7
2ae12c9
 
 
 
96b5600
2ae12c9
f700426
 
 
 
 
 
 
 
 
 
 
 
 
 
2ae12c9
 
 
 
 
c65aeea
 
 
f700426
 
 
 
 
 
 
 
 
 
 
 
 
 
2ae12c9
f700426
 
 
 
2ae12c9
5f675c9
062a8c7
 
 
 
 
bf255d5
 
2ae12c9
c65aeea
2ae12c9
f64dbae
df0d213
d2aca0b
87feb79
8a8b86f
a1d8121
f64dbae
 
 
8a8b86f
 
2ae12c9
 
06df3d2
 
 
 
 
 
 
 
 
 
 
 
eb50eff
 
 
 
 
 
c65aeea
 
 
eb50eff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c240398
8a8b86f
a1d8121
8a8b86f
 
 
c240398
b531f74
c240398
b66013a
989858a
203f5bc
 
 
 
 
 
 
 
 
989858a
 
a1d8121
957f938
eb50eff
 
8a8b86f
 
 
eb50eff
 
 
957f938
eb50eff
 
 
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/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