update.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. # 设置工作目录为脚本所在的目录
  3. cd "$(dirname "$0")" || exit 1
  4. # 临时下载最新的 lib.sh 到当前目录(覆盖旧版本)
  5. curl -o scripts/lib.sh https://raw.githubusercontent.com/ProxyPanel/ProxyPanel/master/scripts/lib.sh
  6. # 引入依赖脚本
  7. source scripts/lib.sh
  8. print_message "Starting panel update..." "开始面板更新..."
  9. print_logo
  10. # 更新代码
  11. print_message "updating Code..." "更新代码..."
  12. git fetch -f && git reset -q --hard origin/master && git pull
  13. # 更新数据库
  14. print_message "Updating database..." "更新数据库..."
  15. php artisan migrate --force
  16. # 如果是演示环境,询问是否重置数据库
  17. if [[ $(grep -E '^APP_ENV=demo' .env) ]]; then
  18. read -p "Reset demo database? [Y/N] " -n 1 -r
  19. echo
  20. if [[ $REPLY =~ ^[Yy]$ ]]; then
  21. print_message "Resetting demo database..." "重置演示数据库..."
  22. php artisan migrate:fresh --seed --force
  23. fi
  24. fi
  25. # 优化缓存
  26. print_message "Optimizing application cache..." "优化应用缓存..."
  27. php artisan optimize
  28. # ===============================================
  29. # 系统依赖安装与检查
  30. # ===============================================
  31. # 确保 Supervisor 存在,供 Horizon/Reverb 使用
  32. print_message "Checking and installing Supervisor..." "检查并安装 Supervisor..."
  33. install_supervisor
  34. # 确保 Node.js/npm 存在,供前端构建使用
  35. print_message "Checking and installing Node.js/npm..." "检查并安装 Node.js/npm..."
  36. install_nodejs_npm
  37. # 检查Composer
  38. print_message "Checking Composer..." "检查Composer..."
  39. check_composer
  40. # 执行Composer更新
  41. print_message "Updating packages via Composer..." "通过Composer更新程序包..."
  42. composer update --no-interaction --no-dev --optimize-autoloader
  43. # ===============================================
  44. # 服务配置和资源构建
  45. # ===============================================
  46. # 设置权限
  47. set_permissions
  48. # 更新旧的队列设置
  49. update_old_queue
  50. print_message "Updating .env configuration..." "更新 .env 配置..."
  51. if [[ -f ".env" ]]; then
  52. # 将 FORCE_HTTPS 替换为 SESSION_SECURE_COOKIE
  53. if grep -q "^FORCE_HTTPS=" .env; then
  54. sed -i 's/^FORCE_HTTPS=/SESSION_SECURE_COOKIE=/' .env
  55. print_message "Updated FORCE_HTTPS to SESSION_SECURE_COOKIE in .env" ".env 中的 FORCE_HTTPS 已更新为 SESSION_SECURE_COOKIE"
  56. else
  57. print_message "No FORCE_HTTPS found in .env" ".env 中未找到 FORCE_HTTPS"
  58. fi
  59. else
  60. print_message ".env file not found" "未找到 .env 文件"
  61. fi
  62. # 配置Reverb WebSocket服务
  63. print_message "Configuring Reverb WebSocket service..." "配置Reverb WebSocket服务..."
  64. configure_reverb
  65. # 构建前端资源
  66. print_message "Building frontend assets..." "构建前端资源..."
  67. build_frontend_assets
  68. # 检查最新的IP数据库文件
  69. print_message "Updating IP database files..." "更新本地IP数据库文件..."
  70. cd scripts/ && bash download_dbs.sh
  71. print_message "Panel update completed successfully!" "面板更新完成!"