From 9296d5d3daa98f552f4ec69bdf155620c837d505 Mon Sep 17 00:00:00 2001 From: BrettonYe Date: Thu, 27 Jun 2024 22:27:53 +0800 Subject: [PATCH] Clean bash code --- .gitignore | 2 ++ install.sh | 22 ++++++++++++---------- scripts/lib.sh | 5 +++++ update.sh | 16 +++++++++------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 901ba4eb..332b437a 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ yarn-error.log _ide_helper.php _ide_helper_models.php composer.lock +.prettierrc +package-lock.json diff --git a/install.sh b/install.sh index aaa895e5..a220f734 100644 --- a/install.sh +++ b/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 diff --git a/scripts/lib.sh b/scripts/lib.sh index cf7f8054..e41d8590 100644 --- a/scripts/lib.sh +++ b/scripts/lib.sh @@ -1,5 +1,10 @@ #!/bin/bash +# 定义输出函数 +function print_message() { + echo -e "\e[34m========= $1 | $2 =========\e[0m" +} + # 安装依赖 install_dependencies() { # 判断系统 diff --git a/update.sh b/update.sh index f5af434d..7d572f94 100644 --- a/update.sh +++ b/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 ../ \ No newline at end of file +print_message "Updating IP database files..." "更新本地IP数据库文件..." +cd scripts/ && bash download_dbs.sh \ No newline at end of file