Spaces:
Sleeping
Sleeping
Update start.sh
Browse files
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. 后台自动保存
|
| 38 |
sync_memory() {
|
| 39 |
while true; do
|
| 40 |
-
sleep 300
|
| 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. 启动
|
| 58 |
echo "Starting Moltbot Gateway..."
|
| 59 |
-
|
| 60 |
-
#
|
| 61 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|