install.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/bin/bash
  2. #安装依赖
  3. install_dependencies() {
  4. #判断系统
  5. if [[ -f /etc/debian_version ]]; then
  6. PM=apt-get
  7. elif [[ -f /etc/redhat-release ]]; then
  8. PM=yum
  9. elif [[ -f /etc/SuSE-release ]]; then
  10. PM=zypper
  11. elif [[ -f /etc/arch-release ]]; then
  12. PM=pacman
  13. elif [[ -f /etc/alpine-release ]]; then
  14. PM=apk
  15. else
  16. echo "不支持的Linux发行版。"
  17. exit 1
  18. fi
  19. if which supervisorctl >/dev/null; then
  20. echo -e "\e[32mSupervisor installed! | Supervisor 已完成!\e[0m"
  21. else
  22. echo -e "\e[31mSupervisor did not installed! | Supervisor 未安装!\e[0m"
  23. # Install Supervisor
  24. case $PM in
  25. apt-get)
  26. sudo apt-get update
  27. sudo apt-get install -y supervisor
  28. ;;
  29. yum)
  30. sudo yum install -y epel-release
  31. sudo yum install -y supervisor
  32. ;;
  33. zypper)
  34. sudo zypper install -y supervisor
  35. ;;
  36. apk)
  37. sudo apk add supervisor
  38. ;;
  39. pacman)
  40. sudo pacman -S supervisor
  41. ;;
  42. esac
  43. #激活
  44. case $PM in
  45. yum)
  46. sudo service supervisord start
  47. sudo chkconfig supervisord on
  48. ;;
  49. *)
  50. sudo systemctl start supervisor.service
  51. sudo systemctl enable supervisor.service
  52. ;;
  53. esac
  54. echo -e "\e[32mSupervisor installation completed! | Supervisor 安装完成!\e[0m"
  55. fi
  56. }
  57. #清理不需要的文件
  58. clean_files() {
  59. if [ -f .user.ini ]; then
  60. chattr -i .user.ini
  61. fi
  62. rm -rf .htaccess 404.html index.html .user.ini
  63. }
  64. check_available() {
  65. tools=$1
  66. available=$(command -v $tools >/dev/null 2>&1)
  67. if $available; then
  68. echo -e "\e[32m$tools Installed! | $tools 已安装!\e[0m"
  69. case $tools in
  70. redis-cli)
  71. redis-cli ping
  72. ;;
  73. php)
  74. php -v
  75. ;;
  76. esac
  77. else
  78. echo -e "\e[31m$tools did not installed! | $tools 未安装!\e[0m"
  79. fi
  80. }
  81. #检查环境
  82. check_env() {
  83. echo "========= Checking for Software dependency | 检查依赖软件是否安装/运行 ========="
  84. # 需要检查的软件数组
  85. check_list=(redis-cli php)
  86. for item in "${check_list[@]}"; do
  87. check_available "$item"
  88. done
  89. if which nginx >/dev/null || which httpd >/dev/null; then
  90. echo -e "\e[32mNginx/Apache Installed! | Nginx 或 Apache 已安装!\e[0m"
  91. if which nginx >/dev/null; then
  92. nginx -v
  93. else
  94. httpd -v
  95. fi
  96. else
  97. echo -e "\e[31mNginx/Apache did not installed! | Nginx 或 Apache 未安装!\e[0m"
  98. fi
  99. }
  100. #检查composer是否安装
  101. check_composer() {
  102. if [ ! -f "/usr/bin/composer" ]; then
  103. curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
  104. else
  105. if [[ $(composer -n --version --no-ansi | cut -d" " -f3) < 2.2.0 ]]; then
  106. composer self-update
  107. fi
  108. fi
  109. }
  110. # 设置权限
  111. set_permissions() {
  112. if [ ! -d "/home/www" ]; then
  113. mkdir -p /home/www
  114. chown www:www /home/www
  115. fi
  116. chown -R www:www ./
  117. chmod -R 755 ./
  118. chmod -R 777 storage/
  119. }
  120. set_schedule() {
  121. cmd="php $PWD/artisan schedule:run >> /dev/null 2>&1"
  122. cronjob="* * * * * $cmd"
  123. (
  124. crontab -u www -l | grep -v -F "$cmd"
  125. echo "$cronjob"
  126. ) | crontab -u www -
  127. }
  128. set_horizon() {
  129. if [ ! -f /etc/supervisor/conf.d/horizon.conf ]; then
  130. echo "
  131. [program:horizon]
  132. process_name=%(program_name)s
  133. command=php $PWD/artisan horizon
  134. autostart=true
  135. autorestart=true
  136. user=www
  137. redirect_stderr=true
  138. stdout_logfile=$PWD/storage/logs/horizon.log
  139. stopwaitsecs=3600" >>/etc/supervisor/conf.d/horizon.conf
  140. sudo supervisorctl reread
  141. sudo supervisorctl update
  142. sudo supervisorctl start horizon
  143. fi
  144. }
  145. clean_files
  146. install_dependencies
  147. check_env
  148. check_composer
  149. composer install
  150. php artisan panel:install
  151. set_permissions
  152. set_schedule
  153. set_horizon
  154. echo -e "\e[32mGoing to Download some IP database files... | 将下载一些IP数据附件文件...\e[0m"
  155. cd scripts/ && bash download_dbs.sh && cd ../