From 5d72b90407c71d0abe4b79c96a6696136829211b Mon Sep 17 00:00:00 2001 From: grimm <1769111741@qq.com> Date: Wed, 17 Jul 2024 11:23:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=84=9A=E6=9C=AC=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.sh | 419 +------------------------------ shikong.sh => shikong_main.sh | 2 +- taichuxing_main.sh | 450 ++++++++++++++++++++++++++++++++++ 3 files changed, 458 insertions(+), 413 deletions(-) rename shikong.sh => shikong_main.sh (99%) create mode 100644 taichuxing_main.sh diff --git a/main.sh b/main.sh index 1536074..02da0c0 100644 --- a/main.sh +++ b/main.sh @@ -5,7 +5,9 @@ stty erase ^h # 文字颜色 red='\033[31m' +# shellcheck disable=SC2034 green='\033[32m' +# shellcheck disable=SC2034 yellow='\033[33m' blue='\033[34m' # shellcheck disable=SC2034 @@ -16,425 +18,18 @@ cyan='\033[36m' white='\033[37m' NC='\033[0m' # 恢复默认颜色 -# 判断一个字符串是否是合法的IP地址 -is_valid_ip() { - local ip=$1 - local pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$" - - if [[ $ip =~ $pattern ]]; then - # 检查每个数字是否在0到255之间 - local IFS='.' - read -ra octets <<< "$ip" - for octet in "${octets[@]}"; do - if (( octet < 0 || octet > 255 )); then - return 1 - fi - done - return 0 - else - return 1 - fi -} - -# 显示指定目录下的文件或目录 -show_file(){ - filer=$1 - find /data/update/"$filer" -maxdepth 1 \( -type f -o -type d \) -printf "%T@\t%-20f\n" | sort -n | awk '{print strftime("%Y-%m-%d %H:%M:%S", $1)"\t"$2}' -} - -# 获取当前时间,精确到秒,格式年月日时分秒 -get_current_time() { - local current_time - current_time=$(date +"%Y%m%d_%H%M%S") - echo "$current_time" -} - -# 发包并解压缩 -unzip_package(){ - # 服务器地址 - local ip=${1} - # tar 包名 - local package=${2}.tar.gz - # 源服务器上的tar压缩包路径 - local source_tar=${3} - # 游戏服目标服务器上的目标目录路径 - local destination_dir=${4} - if [ -e $source_tar ]; then - echo "正在处理服务器 $ip" - scp "$source_tar/$package" "$ip:$destination_dir" || { echo "SCP 失败"; exit 1; } - ssh "$ip" "tar -zxvf $destination_dir/$package -C $destination_dir" - ssh "$ip" "rm -f $destination_dir/$package" - echo "处理完成服务器 $ip " - else - echo "$source_tar/$package 不存在,请先去打包!" - return - fi -} - -# 通用的重启函数 -restart_server() { - local server_name=$1 - local ip=$2 - local restart_script="" - - case $server_name in - "tomcat") - restart_script="bash /usr/local/apache-tomcat-7.0.79/login_reboot.sh" - ;; - "delivery") - restart_script="bash /data/jieling/delivery-server/pay_reboot.sh" - ;; - "sensitive") - restart_script="bash /data/jieling/sensitiveWordFilter/bin/mingan_reboot.sh" - ;; - "admin") - restart_script="bash /data/jieling/gm/gm_reboot.sh" - ;; - "super") - server_name=core - restart_script="supervisorctl restart all" - ;; - "coreStop") - server_name=core1 - restart_script="bash /data/jieling/server/bin/stop.sh core1" - ;; - "coreStart") - server_name=core1 - restart_script="bash /data/jieling/server/bin/start.sh core1" - ;; - "coreRestart") - server_name=core - restart_script="bash /data/jieling/server/bin/reboot_all.sh" - ;; - *) - echo -e "${red}无效的服务器名称${NC}" - exit 1 - ;; - esac - - ssh "$ip" "$restart_script" - ssh "$ip" "ps -ef | grep $server_name" - echo "${server_name} ${ip} 重启完成" -} - -# 游戏代码发送包并重启 -game_send_package() { - local channel=${1} # ip还是文本更新 - local package=${2} # 包名 - local reboot=${3} # 是否重启(分辨热更) - local source_tar="/data/update/package/" - local destination_dir="/data/jieling/server" - - # 停服更新 - if [[ $reboot -eq 1 ]]; then - if is_valid_ip "$channel"; then - unzip_package $channel $package $source_tar $destination_dir - read -r -p "更新完毕,是否需要重启(Y/N): " input - case $input in - [yY][eE][sS]|[yY]) - restart_server "coreRestart" "$channel" - ;; - *) - echo "over..." - exit 0 - ;; - esac - else - for ip in $(awk '{print $2}' "txt/$channel") - do - unzip_package $ip $package $source_tar $destination_dir - restart_server "super" "$ip" - done - fi - else - # 热更新 - if is_valid_ip "$channel"; then - unzip_package $channel $package $source_tar $destination_dir - else - for ip in $(awk '{print $2}' "txt/$channel") - do - unzip_package $ip $package $source_tar $destination_dir - done - fi - fi -} - -# 通用的更新函数 -update_code() { - local server_name=$1 - local update_script=$2 - - echo -e "${yellow}${server_name}更新${NC}" - read -rp "请输入${server_name}的ip地址: " ip - echo -e "开始更新${server_name},ip:$ip" - bash "${update_script}" "$ip" - - read -r -p "更新完毕,是否需要重启(Y/N): " input - case $input in - [yY][eE][sS]|[yY]) - restart_server "$server_name" "$ip" - ;; - *) - echo "over..." - exit 0 - ;; - esac -} - -# 通用的重启判断函数 -restart_bol() { - local server_name=$1 - echo -e "${yellow}${server_name}重启${NC}" - read -rp "请输入${server_name}的ip地址: " ip - echo -e "开始重启${server_name},ip:$ip" - restart_server "$server_name" "$ip" -} - -# 退出脚本 -exit_script() { - echo -e "${red}谢谢使用,再见!${NC}" - exit 0 -} - -# 游戏服更新 -update_game(){ - while true; do - echo -e "${blue}************************************${NC}" - echo -e "${purple}开始更新游戏服...${NC}" - echo -e "1.更新包" - echo -e "2.正式服更新" - echo -e "3.测试服更新" - echo -e "4.热更包" - echo -e "5.正式服热更" - echo -e "6.测试服热更" - echo -e "0.返回主菜单" - echo -e "*.${red}其他任意键退出程序${NC}" - echo -e "${blue}************************************${NC}" - read -rp "请输入选项编号: " choice - case $choice in - 1) game_update_option "create_update_package" ;; # 游戏服更新:打更新包 - 2) game_update_option "official_reboot" ;; # 游戏服更新:正式服停服更新 - 3) game_update_option "test_reboot" ;; # 游戏服更新:测试服停服更新 - 4) game_update_option "create_hotfix_package" ;; # 游戏服更新:打热更包 - 5) game_update_option "official_hotfix" ;; # 游戏服更新:正式服热更 - 6) game_update_option "test_hotfix" ;; # 游戏服更新:测试服热更 - 0) return ;; - *) exit_script ;; - esac - done -} - -# 通用游戏服更新函数 -game_update_option() { - local action=$1 - case $action in - "create_update_package") game_code_build "update" "update_game.sh" ;; - "official_reboot") game_code_official "update" "1" ;; - "test_reboot") game_code_test "update" "1" ;; - "create_hotfix_package") game_code_build "hotfix" "hotfix_game.sh" ;; - "official_hotfix") game_code_official "hotfix" "0" ;; - "test_hotfix") game_code_test "hotfix" "0" ;; - *) - echo -e "${red}无效的选项,请重新输入${NC}" - handle_menu - return - ;; - esac -} - -# 游戏代码打包 -game_code_build(){ - local type=$1 - local script=$2 - # shellcheck disable=SC2155 - local current_time=$(get_current_time) - show_file project | grep master - read -rp "请输入项目地址: " project - local package="${project}_${type}_${current_time}" - echo -e "包名: $package" - bash "${script}" "${project}" "${package}" -} -# 游戏代码正式更新 -game_code_official(){ - local type=$1 - local reboot=$2 - show_file package | grep "${type}" - read -rp "请输入包名(不需要带文件后缀):" package - show_file script/txt - read -rp "请输入文件名称(不需要带文件后缀): " channel - echo -e "开始发送 包名:$package, 渠道:$channel" - game_send_package "${channel}.txt" "$package" "${reboot}" -} -# 游戏代码测试更新 -game_code_test(){ - local type=$1 - local reboot=$2 - show_file package | grep "${type}" - read -rp "请输入包名(不需要带文件后缀):" package - read -rp "请输入游戏服ip: " ip - echo -e "开始发送 包名:$package, ip:$ip" - game_send_package "$ip" "$package" "${reboot}" -} - -# gm更新 -update_gm(){ - while true; do - echo -e "${blue}************************************${NC}" - echo -e "${purple}开始更新GM后台...${NC}" - echo -e "1.打包" - echo -e "2.单机器更新" - echo -e "3.批量更新" - echo -e "0.返回主菜单" - echo -e "*.${red}其他任意键退出程序${NC}" - echo -e "${blue}************************************${NC}" - read -rp "请输入选项编号: " choice - case $choice in - 1) gm_option "package" ;; # GM更新:打包 - 2) gm_option "single_update" ;; # GM更新:单机器更新 - 3) gm_option "batch_update" ;; # GM更新:批量更新 - 0) return ;; - *) exit_script ;; - esac - done -} - -# 通用GM更新函数 -gm_option() { - local action=$1 - # shellcheck disable=SC2155 - local current_time=$(get_current_time) - case $action in - "package") - show_file project | grep "master" - read -rp "请输入表所在游戏项目地址: " project - local package="gm_${project}_${current_time}" - bash "update_gm.sh" "$project" "$package" - echo -e "gm打包完成 $package" - ;; - "single_update") - read -rp "请输入游戏服ip: " ip - show_file package | grep "gm" - read -rp "请输入包名(不需要带文件后缀):" package - echo -e "开始更新gm $ip $package" - gm_send_package "$ip" "$package" - ;; - "batch_update") - show_file script/txt - read -rp "请输入文件名称(不需要带文件后缀): " channel - show_file package | grep "gm" - read -rp "请输入包名(不需要带文件后缀):" package - echo -e "开始更新gm $channel.txt $package" - gm_send_package "$channel.txt" "$package" - ;; - *) - echo -e "${red}无效的选项,请重新输入${NC}" - handle_menu - return - ;; - esac -} - -# 更新gm -gm_send_package() { - local channel=${1} - local package=${2} - local source_tar="/data/update/package" - local destination_dir="/data/jieling/gm" - - if is_valid_ip "$channel"; then - unzip_package "$channel" $package $source_tar $destination_dir - restart_server "admin" "$channel" - else - # shellcheck disable=SC2013 - for ip in $(awk '{print $2}' "txt/$channel") - do - unzip_package "$ip" $package $source_tar $destination_dir - restart_server "admin" "$ip" - done - fi -} - -# 登陆服更新 -update_login(){ - while true; do - echo -e "${blue}************************************${NC}" - echo -e "${purple}开始更新登陆服...${NC}" - echo -e "1.更新登陆服代码" - echo -e "2.重启登陆服" - echo -e "0.返回主菜单" - echo -e "*.${red}其他任意键退出程序${NC}" - echo -e "${blue}************************************${NC}" - read -rp "请输入选项编号: " choice - case $choice in - 1) update_code "tomcat" "update_login.sh" ;; - 2) restart_bol "tomcat" ;; - 0) return ;; - *) exit_script ;; - esac - done -} - -# 支付服更新 -update_pay(){ - while true; do - echo -e "${blue}************************************${NC}" - echo -e "${purple}开始更新支付服...${NC}" - echo -e "1.更新支付服代码" - echo -e "2.重启支付服" - echo -e "0.返回主菜单" - echo -e "*.${red}其他任意键退出程序${NC}" - echo -e "${blue}************************************${NC}" - read -rp "请输入选项编号: " choice - case $choice in - 1) update_code "delivery" "update_delivery.sh" ;; - 2) restart_bol "delivery" ;; - 0) return ;; - *) exit_script ;; - esac - done -} - -# 敏感词服更新 -update_mingan(){ - while true; do - echo -e "${blue}************************************${NC}" - echo -e "${purple}开始更新敏感词服...${NC}" - echo -e "1.更新敏感词服代码" - echo -e "2.重启敏感词服" - echo -e "0.返回主菜单" - echo -e "*.${red}其他任意键退出程序${NC}" - echo -e "${blue}************************************${NC}" - read -rp "请输入选项编号: " choice - case $choice in - 1) update_code "sensitive" "update_sensitive.sh" ;; - 2) restart_bol "sensitive" ;; - 0) return ;; - *) exit_script ;; - esac - done -} - # 处理用户输入 handle_menu() { - local current_time - current_time=$(get_current_time) echo -e "${blue}************************************${NC}" - echo -e "${purple}欢迎使用戒灵更新脚本...${current_time}${NC}" - echo -e "1.游戏服更新" - echo -e "2.gm后台更新" - echo -e "3.登陆服更新" - echo -e "4.支付服更新" - echo -e "5.敏感词更新" + echo -e "${purple}欢迎使用米多更新脚本...${NC}" + echo -e "1.太初行" + echo -e "2.时空战场" echo -e "0.${red}退出${NC}" echo -e "${blue}************************************${NC}" read -rp "请输入选项编号: " choice case $choice in - 1) update_game ;; - 2) update_gm ;; - 3) update_login ;; - 4) update_pay ;; - 5) update_mingan ;; - 0) exit_script ;; + 1) bash ./taichuxing_main.sh ;; + 2) bash ./shikong_main.sh ;; *) echo -e "${red}无效的选项,请重新输入${NC}" ;; esac } diff --git a/shikong.sh b/shikong_main.sh similarity index 99% rename from shikong.sh rename to shikong_main.sh index 7b0d5a0..de2ecab 100644 --- a/shikong.sh +++ b/shikong_main.sh @@ -123,7 +123,7 @@ server_code_build(){ local code=$1 # shellcheck disable=SC2155 local time=$(get_current_time) - show_file project | grep sk + show_file project | grep shikong read -rp "请输入项目地址: " project local package="${project}_${time}" case $code in diff --git a/taichuxing_main.sh b/taichuxing_main.sh new file mode 100644 index 0000000..1536074 --- /dev/null +++ b/taichuxing_main.sh @@ -0,0 +1,450 @@ +#!/bin/bash + +# 删除命令乱码解决 +stty erase ^h + +# 文字颜色 +red='\033[31m' +green='\033[32m' +yellow='\033[33m' +blue='\033[34m' +# shellcheck disable=SC2034 +purple='\033[35m' +# shellcheck disable=SC2034 +cyan='\033[36m' +# shellcheck disable=SC2034 +white='\033[37m' +NC='\033[0m' # 恢复默认颜色 + +# 判断一个字符串是否是合法的IP地址 +is_valid_ip() { + local ip=$1 + local pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$" + + if [[ $ip =~ $pattern ]]; then + # 检查每个数字是否在0到255之间 + local IFS='.' + read -ra octets <<< "$ip" + for octet in "${octets[@]}"; do + if (( octet < 0 || octet > 255 )); then + return 1 + fi + done + return 0 + else + return 1 + fi +} + +# 显示指定目录下的文件或目录 +show_file(){ + filer=$1 + find /data/update/"$filer" -maxdepth 1 \( -type f -o -type d \) -printf "%T@\t%-20f\n" | sort -n | awk '{print strftime("%Y-%m-%d %H:%M:%S", $1)"\t"$2}' +} + +# 获取当前时间,精确到秒,格式年月日时分秒 +get_current_time() { + local current_time + current_time=$(date +"%Y%m%d_%H%M%S") + echo "$current_time" +} + +# 发包并解压缩 +unzip_package(){ + # 服务器地址 + local ip=${1} + # tar 包名 + local package=${2}.tar.gz + # 源服务器上的tar压缩包路径 + local source_tar=${3} + # 游戏服目标服务器上的目标目录路径 + local destination_dir=${4} + if [ -e $source_tar ]; then + echo "正在处理服务器 $ip" + scp "$source_tar/$package" "$ip:$destination_dir" || { echo "SCP 失败"; exit 1; } + ssh "$ip" "tar -zxvf $destination_dir/$package -C $destination_dir" + ssh "$ip" "rm -f $destination_dir/$package" + echo "处理完成服务器 $ip " + else + echo "$source_tar/$package 不存在,请先去打包!" + return + fi +} + +# 通用的重启函数 +restart_server() { + local server_name=$1 + local ip=$2 + local restart_script="" + + case $server_name in + "tomcat") + restart_script="bash /usr/local/apache-tomcat-7.0.79/login_reboot.sh" + ;; + "delivery") + restart_script="bash /data/jieling/delivery-server/pay_reboot.sh" + ;; + "sensitive") + restart_script="bash /data/jieling/sensitiveWordFilter/bin/mingan_reboot.sh" + ;; + "admin") + restart_script="bash /data/jieling/gm/gm_reboot.sh" + ;; + "super") + server_name=core + restart_script="supervisorctl restart all" + ;; + "coreStop") + server_name=core1 + restart_script="bash /data/jieling/server/bin/stop.sh core1" + ;; + "coreStart") + server_name=core1 + restart_script="bash /data/jieling/server/bin/start.sh core1" + ;; + "coreRestart") + server_name=core + restart_script="bash /data/jieling/server/bin/reboot_all.sh" + ;; + *) + echo -e "${red}无效的服务器名称${NC}" + exit 1 + ;; + esac + + ssh "$ip" "$restart_script" + ssh "$ip" "ps -ef | grep $server_name" + echo "${server_name} ${ip} 重启完成" +} + +# 游戏代码发送包并重启 +game_send_package() { + local channel=${1} # ip还是文本更新 + local package=${2} # 包名 + local reboot=${3} # 是否重启(分辨热更) + local source_tar="/data/update/package/" + local destination_dir="/data/jieling/server" + + # 停服更新 + if [[ $reboot -eq 1 ]]; then + if is_valid_ip "$channel"; then + unzip_package $channel $package $source_tar $destination_dir + read -r -p "更新完毕,是否需要重启(Y/N): " input + case $input in + [yY][eE][sS]|[yY]) + restart_server "coreRestart" "$channel" + ;; + *) + echo "over..." + exit 0 + ;; + esac + else + for ip in $(awk '{print $2}' "txt/$channel") + do + unzip_package $ip $package $source_tar $destination_dir + restart_server "super" "$ip" + done + fi + else + # 热更新 + if is_valid_ip "$channel"; then + unzip_package $channel $package $source_tar $destination_dir + else + for ip in $(awk '{print $2}' "txt/$channel") + do + unzip_package $ip $package $source_tar $destination_dir + done + fi + fi +} + +# 通用的更新函数 +update_code() { + local server_name=$1 + local update_script=$2 + + echo -e "${yellow}${server_name}更新${NC}" + read -rp "请输入${server_name}的ip地址: " ip + echo -e "开始更新${server_name},ip:$ip" + bash "${update_script}" "$ip" + + read -r -p "更新完毕,是否需要重启(Y/N): " input + case $input in + [yY][eE][sS]|[yY]) + restart_server "$server_name" "$ip" + ;; + *) + echo "over..." + exit 0 + ;; + esac +} + +# 通用的重启判断函数 +restart_bol() { + local server_name=$1 + echo -e "${yellow}${server_name}重启${NC}" + read -rp "请输入${server_name}的ip地址: " ip + echo -e "开始重启${server_name},ip:$ip" + restart_server "$server_name" "$ip" +} + +# 退出脚本 +exit_script() { + echo -e "${red}谢谢使用,再见!${NC}" + exit 0 +} + +# 游戏服更新 +update_game(){ + while true; do + echo -e "${blue}************************************${NC}" + echo -e "${purple}开始更新游戏服...${NC}" + echo -e "1.更新包" + echo -e "2.正式服更新" + echo -e "3.测试服更新" + echo -e "4.热更包" + echo -e "5.正式服热更" + echo -e "6.测试服热更" + echo -e "0.返回主菜单" + echo -e "*.${red}其他任意键退出程序${NC}" + echo -e "${blue}************************************${NC}" + read -rp "请输入选项编号: " choice + case $choice in + 1) game_update_option "create_update_package" ;; # 游戏服更新:打更新包 + 2) game_update_option "official_reboot" ;; # 游戏服更新:正式服停服更新 + 3) game_update_option "test_reboot" ;; # 游戏服更新:测试服停服更新 + 4) game_update_option "create_hotfix_package" ;; # 游戏服更新:打热更包 + 5) game_update_option "official_hotfix" ;; # 游戏服更新:正式服热更 + 6) game_update_option "test_hotfix" ;; # 游戏服更新:测试服热更 + 0) return ;; + *) exit_script ;; + esac + done +} + +# 通用游戏服更新函数 +game_update_option() { + local action=$1 + case $action in + "create_update_package") game_code_build "update" "update_game.sh" ;; + "official_reboot") game_code_official "update" "1" ;; + "test_reboot") game_code_test "update" "1" ;; + "create_hotfix_package") game_code_build "hotfix" "hotfix_game.sh" ;; + "official_hotfix") game_code_official "hotfix" "0" ;; + "test_hotfix") game_code_test "hotfix" "0" ;; + *) + echo -e "${red}无效的选项,请重新输入${NC}" + handle_menu + return + ;; + esac +} + +# 游戏代码打包 +game_code_build(){ + local type=$1 + local script=$2 + # shellcheck disable=SC2155 + local current_time=$(get_current_time) + show_file project | grep master + read -rp "请输入项目地址: " project + local package="${project}_${type}_${current_time}" + echo -e "包名: $package" + bash "${script}" "${project}" "${package}" +} +# 游戏代码正式更新 +game_code_official(){ + local type=$1 + local reboot=$2 + show_file package | grep "${type}" + read -rp "请输入包名(不需要带文件后缀):" package + show_file script/txt + read -rp "请输入文件名称(不需要带文件后缀): " channel + echo -e "开始发送 包名:$package, 渠道:$channel" + game_send_package "${channel}.txt" "$package" "${reboot}" +} +# 游戏代码测试更新 +game_code_test(){ + local type=$1 + local reboot=$2 + show_file package | grep "${type}" + read -rp "请输入包名(不需要带文件后缀):" package + read -rp "请输入游戏服ip: " ip + echo -e "开始发送 包名:$package, ip:$ip" + game_send_package "$ip" "$package" "${reboot}" +} + +# gm更新 +update_gm(){ + while true; do + echo -e "${blue}************************************${NC}" + echo -e "${purple}开始更新GM后台...${NC}" + echo -e "1.打包" + echo -e "2.单机器更新" + echo -e "3.批量更新" + echo -e "0.返回主菜单" + echo -e "*.${red}其他任意键退出程序${NC}" + echo -e "${blue}************************************${NC}" + read -rp "请输入选项编号: " choice + case $choice in + 1) gm_option "package" ;; # GM更新:打包 + 2) gm_option "single_update" ;; # GM更新:单机器更新 + 3) gm_option "batch_update" ;; # GM更新:批量更新 + 0) return ;; + *) exit_script ;; + esac + done +} + +# 通用GM更新函数 +gm_option() { + local action=$1 + # shellcheck disable=SC2155 + local current_time=$(get_current_time) + case $action in + "package") + show_file project | grep "master" + read -rp "请输入表所在游戏项目地址: " project + local package="gm_${project}_${current_time}" + bash "update_gm.sh" "$project" "$package" + echo -e "gm打包完成 $package" + ;; + "single_update") + read -rp "请输入游戏服ip: " ip + show_file package | grep "gm" + read -rp "请输入包名(不需要带文件后缀):" package + echo -e "开始更新gm $ip $package" + gm_send_package "$ip" "$package" + ;; + "batch_update") + show_file script/txt + read -rp "请输入文件名称(不需要带文件后缀): " channel + show_file package | grep "gm" + read -rp "请输入包名(不需要带文件后缀):" package + echo -e "开始更新gm $channel.txt $package" + gm_send_package "$channel.txt" "$package" + ;; + *) + echo -e "${red}无效的选项,请重新输入${NC}" + handle_menu + return + ;; + esac +} + +# 更新gm +gm_send_package() { + local channel=${1} + local package=${2} + local source_tar="/data/update/package" + local destination_dir="/data/jieling/gm" + + if is_valid_ip "$channel"; then + unzip_package "$channel" $package $source_tar $destination_dir + restart_server "admin" "$channel" + else + # shellcheck disable=SC2013 + for ip in $(awk '{print $2}' "txt/$channel") + do + unzip_package "$ip" $package $source_tar $destination_dir + restart_server "admin" "$ip" + done + fi +} + +# 登陆服更新 +update_login(){ + while true; do + echo -e "${blue}************************************${NC}" + echo -e "${purple}开始更新登陆服...${NC}" + echo -e "1.更新登陆服代码" + echo -e "2.重启登陆服" + echo -e "0.返回主菜单" + echo -e "*.${red}其他任意键退出程序${NC}" + echo -e "${blue}************************************${NC}" + read -rp "请输入选项编号: " choice + case $choice in + 1) update_code "tomcat" "update_login.sh" ;; + 2) restart_bol "tomcat" ;; + 0) return ;; + *) exit_script ;; + esac + done +} + +# 支付服更新 +update_pay(){ + while true; do + echo -e "${blue}************************************${NC}" + echo -e "${purple}开始更新支付服...${NC}" + echo -e "1.更新支付服代码" + echo -e "2.重启支付服" + echo -e "0.返回主菜单" + echo -e "*.${red}其他任意键退出程序${NC}" + echo -e "${blue}************************************${NC}" + read -rp "请输入选项编号: " choice + case $choice in + 1) update_code "delivery" "update_delivery.sh" ;; + 2) restart_bol "delivery" ;; + 0) return ;; + *) exit_script ;; + esac + done +} + +# 敏感词服更新 +update_mingan(){ + while true; do + echo -e "${blue}************************************${NC}" + echo -e "${purple}开始更新敏感词服...${NC}" + echo -e "1.更新敏感词服代码" + echo -e "2.重启敏感词服" + echo -e "0.返回主菜单" + echo -e "*.${red}其他任意键退出程序${NC}" + echo -e "${blue}************************************${NC}" + read -rp "请输入选项编号: " choice + case $choice in + 1) update_code "sensitive" "update_sensitive.sh" ;; + 2) restart_bol "sensitive" ;; + 0) return ;; + *) exit_script ;; + esac + done +} + +# 处理用户输入 +handle_menu() { + local current_time + current_time=$(get_current_time) + echo -e "${blue}************************************${NC}" + echo -e "${purple}欢迎使用戒灵更新脚本...${current_time}${NC}" + echo -e "1.游戏服更新" + echo -e "2.gm后台更新" + echo -e "3.登陆服更新" + echo -e "4.支付服更新" + echo -e "5.敏感词更新" + echo -e "0.${red}退出${NC}" + echo -e "${blue}************************************${NC}" + read -rp "请输入选项编号: " choice + case $choice in + 1) update_game ;; + 2) update_gm ;; + 3) update_login ;; + 4) update_pay ;; + 5) update_mingan ;; + 0) exit_script ;; + *) echo -e "${red}无效的选项,请重新输入${NC}" ;; + esac +} + +# 主程序入口 +main() { + while true; do + handle_menu + done +} + +# 脚本开始执行 +main \ No newline at end of file