Selaa lähdekoodia

Clean bash code

BrettonYe 1 vuosi sitten
vanhempi
sitoutus
9296d5d3da
4 muutettua tiedostoa jossa 28 lisäystä ja 17 poistoa
  1. 2 0
      .gitignore
  2. 12 10
      install.sh
  3. 5 0
      scripts/lib.sh
  4. 9 7
      update.sh

+ 2 - 0
.gitignore

@@ -19,3 +19,5 @@ yarn-error.log
 _ide_helper.php
 _ide_helper_models.php
 composer.lock
+.prettierrc
+package-lock.json

+ 12 - 10
install.sh

@@ -1,7 +1,9 @@
 #!/bin/bash
+# 设置工作目录为脚本所在的目录
+cd "$(dirname "$0")" || exit
 
 # 引入依赖脚本
-source ./scripts/lib.sh
+source scripts/lib.sh
 
 # 信号处理
 trap 'rm -f .env; exit' SIGINT SIGTSTP SIGTERM
@@ -10,36 +12,36 @@ trap 'rm -f .env; exit' SIGINT SIGTSTP SIGTERM
 clean_files
 
 # 安装依赖
-echo -e "\e[34m========= Checking server environment... | 检查服务器环境... =========\e[0m"
+print_message "Checking server environment..." "检查服务器环境..."
 install_dependencies
 
 # 检查环境
-echo -e "\e[34m========= Checking the panel environment... | 检查面板运行环境... =========\e[0m"
+print_message "Checking the panel environment..." "检查面板运行环境..."
 check_env
 
 # 设置权限
-echo -e "\e[34m========= Setting Folder Permissions... | 设置文件夹权限... =========\e[0m"
+print_message "Setting Folder Permissions..." "设置文件夹权限..."
 set_permissions
 
 # 检查Composer
-echo -e "\e[34m========= Checking Composer... | 检查Composer... =========\e[0m"
+print_message "Checking Composer..." "检查Composer..."
 check_composer
 
 # 执行Composer安装
-echo -e "\e[34m========= Installing packages via Composer... | 通过Composer安装程序包... =========\e[0m"
+print_message "Installing packages via Composer..." "通过Composer安装程序包..."
 composer install --no-interaction --no-dev --optimize-autoloader
 
 # 执行Panel安装
 php artisan panel:install
 
 # 设置定时任务
-echo -e "\e[34m========= Enabling Panel schedule tasks... | 开启面板定时任务... =========\e[0m"
+print_message "Enabling Panel schedule tasks..." "开启面板定时任务..."
 set_schedule
 
 # 设置Horizon
-echo -e "\e[34m========= Setting Horizon daemon... | 设置Horizon守护程序... =========\e[0m"
+print_message "Setting Horizon daemon..." "设置Horizon守护程序..."
 set_horizon
 
 # 下载IP数据库文件
-echo -e "\e[34m========= Downloading IP database files... | 下载IP数据库文件... =========\e[0m"
-cd scripts/ && bash download_dbs.sh && cd ../
+print_message "Downloading IP database files..." "下载IP数据库文件..."
+cd scripts/ && bash download_dbs.sh

+ 5 - 0
scripts/lib.sh

@@ -1,5 +1,10 @@
 #!/bin/bash
 
+# 定义输出函数
+function print_message() {
+    echo -e "\e[34m========= $1 | $2 =========\e[0m"
+}
+
 # 安装依赖
 install_dependencies() {
   # 判断系统

+ 9 - 7
update.sh

@@ -1,22 +1,24 @@
 #!/bin/bash
+# 设置工作目录为脚本所在的目录
+cd "$(dirname "$0")" || exit
 
 # 引入依赖脚本
-source ./scripts/lib.sh
+source scripts/lib.sh
 
 # 更新代码
-echo -e "\e[34m========= Checking server environment... | 检查服务器环境... =========\e[0m"
+print_message "Checking server environment..." "检查服务器环境..."
 git fetch -f && git reset -q --hard origin/master && git pull
 
 # 检查Composer
-echo -e "\e[34m========= Checking Composer... | 检查Composer... =========\e[0m"
+print_message "Checking Composer..." "检查Composer..."
 check_composer
 
 # 清理优化缓存
-echo -e "\e[34m========= Cleaning panel cache... | 清理面板缓存... =========\e[0m"
+print_message "Cleaning panel cache..." "清理面板缓存..."
 php artisan optimize:clear
 
 # 执行Composer更新
-echo -e "\e[34m========= Updating packages via Composer... | 通过Composer更新程序包... =========\e[0m"
+print_message "Updating packages via Composer..." "通过Composer更新程序包..."
 composer update --no-interaction --no-dev --optimize-autoloader
 
 # 执行Panel更新
@@ -29,5 +31,5 @@ set_permissions
 update_old_queue
 
 # 检查最新的IP数据库文件
-echo -e "\e[34m========= Updating IP database files... | 更新本地IP数据库文件... =========\e[0m"
-cd scripts/ && bash download_dbs.sh && cd ../
+print_message "Updating IP database files..." "更新本地IP数据库文件..."
+cd scripts/ && bash download_dbs.sh