chore: CRM-NEW baseline
This commit is contained in:
Executable
+65
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
# 一键启动本套 LibreDesk(独立 pg/redis,端口与旧 crm 栈隔离)。
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
if [ ! -f .env ]; then
|
||||
echo "==> 未找到 .env,从 .env.example 生成并填充随机密钥"
|
||||
cp .env.example .env
|
||||
node - "$ROOT" <<'NODE'
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
const p = path.join(process.argv[2], '.env');
|
||||
let s = fs.readFileSync(p, 'utf8');
|
||||
const set = (k, v) => {
|
||||
const re = new RegExp('^' + k + '=.*$', 'm');
|
||||
s = re.test(s) ? s.replace(re, `${k}=${v}`) : `${s}\n${k}=${v}`;
|
||||
};
|
||||
if (/^ENCRYPTION_KEY=$/m.test(s)) set('ENCRYPTION_KEY', crypto.randomBytes(16).toString('hex'));
|
||||
if (/^POSTGRES_PASSWORD=change-me-please$/m.test(s)) set('POSTGRES_PASSWORD', crypto.randomBytes(12).toString('hex'));
|
||||
if (/^TOOLS_SHARED_KEY=change-me-please$/m.test(s)) set('TOOLS_SHARED_KEY', crypto.randomBytes(16).toString('hex'));
|
||||
const strongPassword = () => `Yehwang${crypto.randomInt(1000, 9999)}!${crypto.randomBytes(4).toString('hex')}`;
|
||||
if (/^LIBREDESK_SYSTEM_USER_PASSWORD=change-me-please$/m.test(s)) set('LIBREDESK_SYSTEM_USER_PASSWORD', strongPassword());
|
||||
fs.writeFileSync(p, s, { mode: 0o600 });
|
||||
NODE
|
||||
echo " 已生成 .env(含随机密钥,勿提交)"
|
||||
fi
|
||||
|
||||
echo "==> 渲染 config/config.toml"
|
||||
node scripts/render-config.js
|
||||
|
||||
mkdir -p uploads
|
||||
touch uploads/.gitkeep
|
||||
|
||||
echo "==> 启动 LibreDesk(首次会拉取镜像,约 1-3 分钟)"
|
||||
docker compose up -d
|
||||
|
||||
echo "==> 等待 http://localhost:9000/health"
|
||||
for i in $(seq 1 90); do
|
||||
if curl -fsS --max-time 2 http://localhost:9000/health >/dev/null 2>&1; then
|
||||
echo " LibreDesk 已就绪(${i} 次探测)"
|
||||
break
|
||||
fi
|
||||
if [ "$i" -eq 90 ]; then
|
||||
echo "!! 等待超时,查看日志:docker logs -f libredesk_app" >&2
|
||||
exit 1
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
set -a; . ./.env; set +a
|
||||
echo
|
||||
echo "==================== 启动完成 ===================="
|
||||
echo " 后台地址 : http://localhost:9000"
|
||||
echo " 登录用户 : System"
|
||||
echo " 登录密码 : ${LIBREDESK_SYSTEM_USER_PASSWORD}"
|
||||
echo
|
||||
echo " 下一步:"
|
||||
echo " 1. 启动工具服务:bash scripts/start-tools.sh"
|
||||
echo " 2. 按 docs/libredesk-setup.md 配置 AI Provider / Actions"
|
||||
echo " 3. 自动注册工具(可选):node scripts/register-tools.js"
|
||||
echo "================================================="
|
||||
Reference in New Issue
Block a user