代码拉取完成,页面将自动刷新
#!/bin/bash
# Chatwoot 快速启动脚本
# 用于快速启动解锁企业版功能的 Chatwoot
set -e # 遇到错误立即退出
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 打印带颜色的消息
print_success() {
echo -e "${GREEN}✅ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
print_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_header() {
echo ""
echo -e "${BLUE}================================================${NC}"
echo -e "${BLUE}$1${NC}"
echo -e "${BLUE}================================================${NC}"
echo ""
}
# 检查命令是否存在
check_command() {
if command -v $1 &> /dev/null; then
print_success "$1 已安装"
return 0
else
print_error "$1 未安装"
return 1
fi
}
# 检查服务是否运行
check_service() {
if pgrep -x $1 > /dev/null; then
print_success "$1 服务正在运行"
return 0
else
print_warning "$1 服务未运行"
return 1
fi
}
# 显示欢迎信息
print_header "🚀 Chatwoot 快速启动脚本"
print_info "企业版功能已解锁 - 用于开发和测试"
echo ""
# 1. 检查依赖
print_header "📋 步骤 1/6: 检查系统依赖"
all_dependencies_ok=true
# 检查 Ruby
if check_command ruby; then
ruby_version=$(ruby -v | awk '{print $2}')
print_info "Ruby 版本: $ruby_version"
else
print_error "请先安装 Ruby 3.2+"
all_dependencies_ok=false
fi
# 检查 Node.js
if check_command node; then
node_version=$(node -v)
print_info "Node.js 版本: $node_version"
else
print_error "请先安装 Node.js 20+"
all_dependencies_ok=false
fi
# 检查 pnpm
if check_command pnpm; then
pnpm_version=$(pnpm -v)
print_info "pnpm 版本: $pnpm_version"
else
print_error "请先安装 pnpm: npm install -g pnpm"
all_dependencies_ok=false
fi
# 检查 PostgreSQL
if check_command psql; then
psql_version=$(psql --version | awk '{print $3}')
print_info "PostgreSQL 版本: $psql_version"
else
print_error "请先安装 PostgreSQL 12+"
all_dependencies_ok=false
fi
# 检查 Redis
if check_command redis-cli; then
if redis-cli ping &> /dev/null; then
print_success "Redis 服务正常"
else
print_warning "Redis 未运行,正在尝试启动..."
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo systemctl start redis-server 2>/dev/null || true
elif [[ "$OSTYPE" == "darwin"* ]]; then
brew services start redis 2>/dev/null || true
fi
sleep 2
if redis-cli ping &> /dev/null; then
print_success "Redis 已启动"
else
print_error "无法启动 Redis,请手动启动"
all_dependencies_ok=false
fi
fi
else
print_error "请先安装 Redis"
all_dependencies_ok=false
fi
if [ "$all_dependencies_ok" = false ]; then
print_error "请先安装所有必需的依赖"
echo ""
print_info "Ubuntu/Debian:"
echo " sudo apt install ruby postgresql redis-server"
echo ""
print_info "macOS:"
echo " brew install ruby postgresql redis"
echo ""
exit 1
fi
# 2. 安装项目依赖
print_header "📦 步骤 2/6: 安装项目依赖"
print_info "安装 Ruby gems..."
if bundle install; then
print_success "Ruby gems 安装完成"
else
print_error "Ruby gems 安装失败"
exit 1
fi
print_info "安装 Node packages..."
if pnpm install; then
print_success "Node packages 安装完成"
else
print_error "Node packages 安装失败"
exit 1
fi
# 3. 配置环境变量
print_header "⚙️ 步骤 3/6: 配置环境变量"
if [ ! -f .env ]; then
print_info "创建 .env 文件..."
cp .env.example .env
# 生成密钥
SECRET_KEY=$(openssl rand -hex 64)
echo "" >> .env
echo "# Generated by quick-start.sh" >> .env
echo "SECRET_KEY_BASE=$SECRET_KEY" >> .env
echo "FRONTEND_URL=http://localhost:3000" >> .env
echo "REDIS_URL=redis://localhost:6379" >> .env
print_success ".env 文件已创建"
else
print_warning ".env 文件已存在,跳过创建"
fi
# 4. 配置数据库
print_header "🗄️ 步骤 4/6: 配置数据库"
# 确保 PostgreSQL 运行
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo systemctl start postgresql 2>/dev/null || true
elif [[ "$OSTYPE" == "darwin"* ]]; then
brew services start postgresql@14 2>/dev/null || brew services start postgresql 2>/dev/null || true
fi
sleep 2
print_info "创建数据库..."
if bundle exec rails db:create 2>/dev/null; then
print_success "数据库创建成功"
else
print_warning "数据库可能已存在"
fi
print_info "运行数据库迁移..."
if bundle exec rails db:migrate; then
print_success "数据库迁移完成"
else
print_error "数据库迁移失败"
exit 1
fi
# 5. 创建管理员账户
print_header "👤 步骤 5/6: 创建管理员账户"
print_info "创建管理员账户..."
bundle exec rails runner "
begin
user = User.find_or_create_by!(email: 'admin@example.com') do |u|
u.name = 'Admin'
u.password = 'Password123!'
u.password_confirmation = 'Password123!'
end
account = Account.find_or_create_by!(name: 'Acme Inc')
AccountUser.find_or_create_by!(account: account, user: user) do |au|
au.role = :administrator
end
puts '管理员账户创建成功'
rescue => e
puts \"账户可能已存在: \#{e.message}\"
end
" 2>/dev/null
print_success "管理员账户准备完成"
# 6. 启动服务
print_header "🎉 步骤 6/6: 启动服务"
echo ""
print_success "准备完成!"
echo ""
echo -e "${GREEN}================================================${NC}"
echo -e "${GREEN} Chatwoot 已准备就绪!${NC}"
echo -e "${GREEN}================================================${NC}"
echo ""
echo -e "${BLUE}📋 登录信息:${NC}"
echo -e " 邮箱: ${GREEN}admin@example.com${NC}"
echo -e " 密码: ${GREEN}Password123!${NC}"
echo ""
echo -e "${BLUE}🌐 访问地址:${NC}"
echo -e " ${GREEN}http://localhost:3000${NC}"
echo ""
echo -e "${BLUE}✨ 企业版功能:${NC}"
echo -e " ${GREEN}✅ 审计日志${NC}"
echo -e " ${GREEN}✅ SLA 策略${NC}"
echo -e " ${GREEN}✅ 自定义角色${NC}"
echo -e " ${GREEN}✅ SAML 登录${NC}"
echo -e " ${GREEN}✅ AI 助手${NC}"
echo -e " ${GREEN}✅ 无限用户${NC}"
echo ""
echo -e "${YELLOW}⚠️ 重要提示:${NC}"
echo -e " - 仅用于开发和测试"
echo -e " - 请立即修改默认密码"
echo -e " - 定期备份数据"
echo ""
# 检查是否安装了 overmind
if command -v overmind &> /dev/null; then
print_info "使用 overmind 启动服务..."
echo ""
echo -e "${BLUE}正在启动服务...${NC}"
echo -e "${YELLOW}按 Ctrl+C 停止所有服务${NC}"
echo ""
sleep 2
overmind start -f Procfile.dev
else
print_warning "未找到 overmind,请手动启动服务:"
echo ""
echo -e "${YELLOW}方式 1: 安装 overmind 后运行${NC}"
echo " brew install overmind # macOS"
echo " sudo apt install overmind # Ubuntu"
echo " overmind start -f Procfile.dev"
echo ""
echo -e "${YELLOW}方式 2: 手动在 3 个终端中分别运行${NC}"
echo " 终端 1: bundle exec rails server"
echo " 终端 2: pnpm dev"
echo " 终端 3: bundle exec sidekiq -C config/sidekiq.yml"
echo ""
# 询问是否启动 Rails 服务器
read -p "是否启动 Rails 服务器?(y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
print_info "启动 Rails 服务器..."
echo ""
echo -e "${YELLOW}请在其他终端运行:${NC}"
echo " pnpm dev"
echo " bundle exec sidekiq -C config/sidekiq.yml"
echo ""
bundle exec rails server
fi
fi
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。