simler commited on
Commit
865310c
·
verified ·
1 Parent(s): 255b3f8

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +20 -16
start.sh CHANGED
@@ -9,35 +9,28 @@ echo "https://${GIT_USER}:${GIT_TOKEN}@github.com" > ~/.git-credentials
9
 
10
  # --- 2. 准备记忆仓库 ---
11
  echo "Restoring memory from GitHub..."
12
- # 如果文件夹不存在则 clone
13
  if [ ! -d "moltbot-memory" ]; then
14
  git clone https://github.com/${GIT_USER}/${GIT_REPO}.git moltbot-memory || echo "Clone failed, continuing..."
15
  else
16
  cd moltbot-memory && git pull && cd ..
17
  fi
18
 
19
- # --- 3. 🧠 核心步骤:记忆植入 (软链接) ---
20
- # Moltbot 默认把数据存放在 ~/.clawdbot 目录
21
- # 我们把这个目录“偷梁换柱”指向我们的 Git 仓库
22
- # 这样 Moltbot 产生的所有数据都会自动落入 git 管理的文件夹
23
  APP_CONFIG_DIR="$HOME/.clawdbot"
24
-
25
- # 如果系统里已经有默认配置文件夹,先删掉,防止冲突
26
  if [ -d "$APP_CONFIG_DIR" ] && [ ! -L "$APP_CONFIG_DIR" ]; then
27
  rm -rf "$APP_CONFIG_DIR"
28
  fi
29
-
30
- # 建立软链接:让 ~/.clawdbot 实际上就是 ./moltbot-memory
31
- # 注意:第一次运行仓库是空的,Moltbot 启动后会自动往里填入默认配置
32
  if [ ! -L "$APP_CONFIG_DIR" ]; then
33
  ln -s "$(pwd)/moltbot-memory" "$APP_CONFIG_DIR"
34
  echo "Symlink created: $APP_CONFIG_DIR -> $(pwd)/moltbot-memory"
35
  fi
36
 
37
- # --- 4. 后台自动保存 (每5分钟同步一次) ---
38
  sync_memory() {
39
  while true; do
40
- sleep 300 # 改为5分钟,更安全
41
  echo "Syncing memory..."
42
  if [ -d "moltbot-memory" ]; then
43
  cd moltbot-memory
@@ -54,9 +47,20 @@ sync_memory() {
54
  }
55
  sync_memory &
56
 
57
- # --- 5. 启动 Moltbot 网关 ---
58
  echo "Starting Moltbot Gateway..."
59
- # 🔧 关键修复:
60
- # 1. --port 7860: 适配 HF Space
61
- # 2. --allow-unconfigured: 允许首次无配置启动 (会自动生成并保存到我们的 Git 仓库)
 
 
 
 
 
 
 
 
 
 
 
62
  npm exec -- moltbot gateway --port 7860 --allow-unconfigured
 
9
 
10
  # --- 2. 准备记忆仓库 ---
11
  echo "Restoring memory from GitHub..."
 
12
  if [ ! -d "moltbot-memory" ]; then
13
  git clone https://github.com/${GIT_USER}/${GIT_REPO}.git moltbot-memory || echo "Clone failed, continuing..."
14
  else
15
  cd moltbot-memory && git pull && cd ..
16
  fi
17
 
18
+ # --- 3. 记忆植入 (软链接) ---
 
 
 
19
  APP_CONFIG_DIR="$HOME/.clawdbot"
20
+ # 清理旧目录防止冲突
 
21
  if [ -d "$APP_CONFIG_DIR" ] && [ ! -L "$APP_CONFIG_DIR" ]; then
22
  rm -rf "$APP_CONFIG_DIR"
23
  fi
24
+ # 建立链接
 
 
25
  if [ ! -L "$APP_CONFIG_DIR" ]; then
26
  ln -s "$(pwd)/moltbot-memory" "$APP_CONFIG_DIR"
27
  echo "Symlink created: $APP_CONFIG_DIR -> $(pwd)/moltbot-memory"
28
  fi
29
 
30
+ # --- 4. 后台自动保存 ---
31
  sync_memory() {
32
  while true; do
33
+ sleep 300
34
  echo "Syncing memory..."
35
  if [ -d "moltbot-memory" ]; then
36
  cd moltbot-memory
 
47
  }
48
  sync_memory &
49
 
50
+ # --- 5. 设置认证密码并启动 ---
51
  echo "Starting Moltbot Gateway..."
52
+
53
+ # 🛡️ 核心修复:注入密码
54
+ # 如果你在 Secrets 里设了 GATEWAY_TOKEN,就用你的;如果没有,就随机生成一个防止报错
55
+ if [ -z "$GATEWAY_TOKEN" ]; then
56
+ export CLAWDBOT_GATEWAY_TOKEN=$(cat /proc/sys/kernel/random/uuid)
57
+ echo "⚠️ 警告: 你没有在 Secrets 设置 GATEWAY_TOKEN。系统生成了一个随机密码: $CLAWDBOT_GATEWAY_TOKEN"
58
+ echo "请在日志里复制这个密码用于连接,或者去 Secrets 里手动设置一个。"
59
+ else
60
+ export CLAWDBOT_GATEWAY_TOKEN="$GATEWAY_TOKEN"
61
+ echo "✅ 使用 Secrets 中配置的密码启动..."
62
+ fi
63
+
64
+ # 启动!
65
+ # 这里的环境变量 CLAWDBOT_GATEWAY_TOKEN 会被 Moltbot 自动识别
66
  npm exec -- moltbot gateway --port 7860 --allow-unconfigured