my-moltbot / start.sh
simler's picture
Update start.sh
eadd45d verified
#!/bin/bash
# --- 1. 配置 Git 凭证 ---
echo "Configuring Git credentials..."
git config --global user.email "moltbot@huggingface.co"
git config --global user.name "Moltbot Cloud"
git config --global credential.helper store
echo "https://${GIT_USER}:${GIT_TOKEN}@github.com" > ~/.git-credentials
# --- 2. 准备记忆仓库 ---
echo "Restoring memory from GitHub..."
if [ ! -d "moltbot-memory" ]; then
git clone https://github.com/${GIT_USER}/${GIT_REPO}.git moltbot-memory || echo "Clone failed..."
else
cd moltbot-memory && git pull && cd ..
fi
# --- 3. 记忆植入 (软链接) ---
APP_CONFIG_DIR="$HOME/.clawdbot"
if [ -d "$APP_CONFIG_DIR" ] && [ ! -L "$APP_CONFIG_DIR" ]; then rm -rf "$APP_CONFIG_DIR"; fi
if [ ! -L "$APP_CONFIG_DIR" ]; then ln -s "$(pwd)/moltbot-memory" "$APP_CONFIG_DIR"; fi
# --- 4. 🧠 修正配置注入 ---
echo "⚙️ Configuring Moltbot..."
# 尝试强制写入 OpenAI 兼容配置 (如果 Secrets 存在)
if [ -n "$OPENAI_API_KEY" ]; then
export CLAWDBOT_OPENAI_API_KEY="$OPENAI_API_KEY"
fi
if [ -n "$OPENAI_BASE_URL" ]; then
export CLAWDBOT_OPENAI_BASE_URL="$OPENAI_BASE_URL"
fi
# 尝试修正模型配置 Key
if [ -n "$GATEWAY_AGENT_MODEL" ]; then
echo "Updating Model to: $GATEWAY_AGENT_MODEL"
# 方案 A: 尝试设置全局 agent.model
npm exec -- moltbot config set agent.model "$GATEWAY_AGENT_MODEL" || true
# 方案 B: 尝试设置全局 model (以防万一)
npm exec -- moltbot config set model "$GATEWAY_AGENT_MODEL" || true
fi
# --- 5. 后台自动保存 ---
sync_memory() {
while true; do
sleep 300
if [ -d "moltbot-memory" ]; then
cd moltbot-memory
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit -m "Auto-save: $(date)"
git push
fi
cd ..
fi
done
}
sync_memory &
# --- 6. 启动服务 ---
if [ -z "$GATEWAY_TOKEN" ]; then
export CLAWDBOT_GATEWAY_TOKEN=$(cat /proc/sys/kernel/random/uuid)
echo "⚠️ Random Token: $CLAWDBOT_GATEWAY_TOKEN"
else
export CLAWDBOT_GATEWAY_TOKEN="$GATEWAY_TOKEN"
fi
echo "🚀 Starting Moltbot on internal port 3000..."
# 启动 Moltbot
npm exec -- moltbot gateway --port 3000 --allow-unconfigured &
echo "🌉 Starting Socat Bridge (0.0.0.0:7860 -> 127.0.0.1:3000)..."
exec socat TCP-LISTEN:7860,fork,bind=0.0.0.0 TCP:127.0.0.1:3000