update_script/main.sh

394 lines
11 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/bash
#删除命令乱码解决
stty erase ^h
# 定义ANSI颜色转义码
#red='\033[0;31m' #红色
#green='\033[0;32m' #绿色
#yellow='\033[0;33m' #黄色
#NC='\033[0m'
#文字颜色:
red='\033[31m'
green='\033[32m'
yellow='\033[33m'
blue='\033[34m'
purple='\033[35m'
cyan='\033[36m'
white='\033[37m'
NC='\033[0m' # 恢复默认颜色
# 定义函数,用于展示菜单选项
show_menu() {
echo -e "================================"
echo -e "欢迎使用${blue}戒灵更新脚本${NC}"
echo -e "1. ${yellow}游戏服更新${NC}"
echo -e "2. ${yellow}gm更新${NC}"
echo -e "3. ${yellow}登陆服更新${NC}"
echo -e "4. ${yellow}支付服更新${NC}"
echo -e "5. ${yellow}敏感词服更新${NC}"
echo -e "0. ${red}退出${NC}"
}
show_file(){
filer=$1
ls /data/update/$filer/ | tr ' ' '\n'
}
# 定义函数,用于处理用户输入
handle_input() {
read -p "请输入选项编号: " choice
case $choice in
1)
# 在这里编写选项一的代码
game
;;
2)
echo -e "${yellow}开始更新gm服${NC}"
# 在这里编写选项二的代码
gm
;;
3)
echo -e "${yellow}开始更新登陆服${NC}"
# 在这里编写选项三的代码
login
;;
4)
echo -e "${yellow}开始更新支付服${NC}"
# 在这里编写选项四的代码
pay
;;
5)
echo -e "${yellow}开始更新敏感词服${NC}"
# 在这里编写选项五的代码
mingan
;;
0)
echo -e "${red}谢谢使用,再见!${NC}"
exit 0
;;
*)
echo -e "${red}无效的选项,请重新输入${NC}"
handle_input
;;
esac
}
# 源服务器上的tar压缩包路径
source_tar="/data/update/package/"
# 目标服务器上的目标目录路径
destination_dir="/data/"
#单服发送
send_one_ip(){
package=${1}.tar.gz
ip=${2}
# 单服务器更新
echo "正在处理服务器 $ip "
scp "$source_tar/$package" "$ip:$destination_dir"
ssh "$ip" "tar -zxvf $destination_dir/$package -C $destination_dir/jieling/server/"
ssh "$ip" "rm -rf $destination_dir/$package"
echo "处理完成服务器 $ip "
}
#多服发送
send_many_ip(){
package=${1}.tar.gz
iptxt=${2}.txt
reboot=$3
for i in `awk '{print $2}' /data/update/script/txt/$iptxt`
do
echo "正在处理服务器 $i "
scp "$source_tar/$package" "$i:$destination_dir"
ssh "$i" "tar -zxvf $destination_dir/$package -C $destination_dir/jieling/server/"
ssh "$i" "rm -rf $destination_dir/$package"
echo "处理完成服务器 $i "
if [ ! -z $reboot ];then
ssh "$i" "supervisorctl restart all"
echo "重启服务器 $i "
fi
done
}
#游戏服更新
game(){
echo -e "================================"
echo -e "开始更新${green}游戏服${NC}"
echo -e "1. ${yellow}打包${NC}"
echo -e "2. ${yellow}单服更新发送${NC}"
echo -e "3. ${yellow}渠道更新发送${NC}"
echo -e "4. ${yellow}单服更新并重启${NC}"
echo -e "5. ${yellow}渠道更新并重启${NC}"
echo -e "0. ${green}返回主菜单${NC}"
echo -e "*. ${red}其他任意键退出程序${NC}"
read -p "请输入选项编号: " choice
case $choice in
1)
echo -e "${yellow}打包${NC}"
show_file project
read -p "请输入项目地址: " project
show_file package
read -p "请输入包名(不需要带文件后缀): " package
echo -e "开始打包 项目:$project, 包名:$package"
bash update_game.sh $project $package
game
;;
2)
echo -e "${yellow}单独发送${NC}"
show_file package
read -p "请输入包名(不需要带文件后缀): " package
read -p "请输入游戏服ip: " ip
echo -e "开始发送 包名:$package, ip$ip"
send_one_ip $package $ip
game
;;
3)
echo -e "${yellow}渠道发送${NC}"
show_file package
read -p "请输入包名(不需要带文件后缀): " package
show_file script/txt
read -p "请输入文件名称(不需要带文件后缀): " iptxt
echo -e "开始发送 包名:$package, 渠道:$iptxt"
send_many_ip $package $iptxt
game
;;
4)
echo -e "${yellow}单独发送并重启${NC}"
show_file package
read -p "请输入包名(不需要带文件后缀): " package
read -p "请输入游戏服ip: " ip
echo -e "开始发送 包名:$package, ip$ip"
send_one_ip $package $ip
ssh $ip "bash /data/jieling/server/bin/reboot.sh core1"
game
;;
5)
echo -e "${yellow}渠道发送并重启${NC}"
show_file package
read -p "请输入包名(不需要带文件后缀): " package
show_file script/txt
read -p "请输入文件名称(不需要带文件后缀): " iptxt
echo -e "开始发送 包名:$package, 渠道:$iptxt"
send_many_ip $package $iptxt
game
;;
0)
show_menu
handle_input
;;
*)
echo -e "${red}谢谢使用,再见!${NC}"
exit 0
;;
esac
}
#gm更新
gm(){
echo -e "================================"
echo -e "开始更新${green}gm服${NC}"
echo -e "1. ${yellow}单渠道更新${NC}"
echo -e "2. ${yellow}多渠道更新${NC}"
echo -e "0. ${green}返回主菜单${NC}"
echo -e "*. ${red}其他任意键退出程序${NC}"
read -p "请输入选项编号: " choice
case $choice in
1)
echo -e "${yellow}单渠道更新${NC}"
show_file project
read -p "请输入表所在游戏项目地址: " project
read -p "请输入gm服ip: " ip
echo -e "开始更新gm ip$ip"
bash update_gm.sh $project $ip
gm
;;
2)
echo -e "${yellow}多渠道更新${NC}"
show_file project
read -p "请输入项目地址: " project
echo -e "开始更新gm"
bash update_gm.sh $project
gm
;;
0)
show_menu
handle_input
;;
*)
echo -e "${red}谢谢使用,再见!${NC}"
exit 0
;;
esac
}
#登陆 ssh $i "sh /data/jieling/gm/gm_restart.sh"
login(){
echo -e "================================"
echo -e "开始更新${green}登陆服${NC}"
echo -e "1. ${yellow}更新登陆服代码${NC}"
echo -e "2. ${yellow}重启登陆服${NC}"
echo -e "0. ${green}返回主菜单${NC}"
echo -e "*. ${red}其他任意键退出程序${NC}"
read -p "请输入选项编号: " choice
case $choice in
1)
echo -e "${yellow}登陆服更新${NC}"
read -p "请输入登陆服ip: " ip
echo -e "开始更新登陆服 ip$ip"
bash update_login.sh $ip
read -r -p "更新完毕是否需要重启Y/N: " input
case $input in
[yY][eE][sS]|[yY])
login_reboot $ip
;;
*)
echo "over..."
exit 0
;;
esac
login
;;
2)
echo -e "${yellow}登陆服重启${NC}"
read -p "请输入登陆服ip: " ip
echo -e "开始重启登陆服 ip$ip"
login_reboot
login
;;
0)
show_menu
handle_input
;;
*)
echo -e "${red}谢谢使用,再见!${NC}"
exit 0
;;
esac
}
login_reboot(){
ip=${1}
ssh $ip "bash /usr/local/apache-tomcat-7.0.79/login_reboot.sh"
ssh $ip "ps -ef|grep tomcat"
echo "登陆服重启完毕"
}
#支付
pay(){
echo -e "================================"
echo -e "开始更新${green}支付服${NC}"
echo -e "1. ${yellow}更新支付服代码${NC}"
echo -e "2. ${yellow}重启支付服${NC}"
echo -e "0. ${green}返回主菜单${NC}"
echo -e "*. ${red}其他任意键退出程序${NC}"
read -p "请输入选项编号: " choice
case $choice in
1)
echo -e "${yellow}支付服更新${NC}"
read -p "请输入支付服ip: " ip
echo -e "开始更新支付服 ip$ip"
bash update_delivery.sh $ip
read -r -p "更新完毕是否需要重启Y/N: " input
case $input in
[yY][eE][sS]|[yY])
pay_reboot $ip
;;
*)
echo "over..."
exit 0
;;
esac
pay
;;
2)
echo -e "${yellow}支付服重启${NC}"
read -p "请输入支付服ip: " ip
echo -e "开始重启支付服 ip$ip"
pay_reboot $ip
login
;;
0)
show_menu
handle_input
;;
*)
echo -e "${red}谢谢使用,再见!${NC}"
exit 0
;;
esac
}
pay_reboot(){
ip=${1}
ssh $ip "bash /data/jieling/delivery-server/pay_reboot.sh"
ssh $ip "ps -ef|grep delivery"
echo "支付服重启完毕"
}
#敏感词
mingan(){
echo -e "================================"
echo -e "开始更新${green}敏感词服${NC}"
echo -e "1. ${yellow}更新敏感词服代码${NC}"
echo -e "2. ${yellow}重启敏感词服${NC}"
echo -e "0. ${green}返回主菜单${NC}"
echo -e "*. ${red}其他任意键退出程序${NC}"
read -p "请输入选项编号: " choice
case $choice in
1)
echo -e "${yellow}敏感词服更新${NC}"
read -p "请输入敏感词服ip: " ip
echo -e "开始更新敏感词服 ip$ip"
bash update_sensitive.sh $ip
read -r -p "更新完毕是否需要重启Y/N: " input
case $input in
[yY][eE][sS]|[yY])
mingan_reboot $ip
;;
*)
echo "over..."
exit 0
;;
esac
mingan
;;
2)
echo -e "${yellow}敏感词服重启${NC}"
read -p "请输入敏感词服ip: " ip
echo -e "开始重启敏感词服 ip$ip"
mingan_reboot
login
;;
0)
show_menu
handle_input
;;
*)
echo -e "${red}谢谢使用,再见!${NC}"
exit 0
;;
esac
}
mingan_reboot(){
ip=${1}
ssh $ip "bash /data/jieling/sensitiveWordFilter/bin/mingan_reboot.sh"
ssh $ip "ps -ef|grep sensitive"
echo "敏感字服重启完毕"
}
# 主循环,展示菜单并处理用户输入
while true; do
show_menu
handle_input
done