#!/bin/bash  
  
# 定义备份根目录  
BACKUP_ROOT="./bak"  
  
# 生成年月日时分格式的子目录名称  
TIMESTAMP=$(date +"%Y%m%d%H%M%S")  
SUB_DIR="$BACKUP_ROOT/$TIMESTAMP"  
  
# 创建备份文件夹的子文件夹（如果不存在）  
mkdir -p "$SUB_DIR"  

# # 把gadmin、console两个文件放入备份文件夹的子文件夹中  
mv gadmin "$SUB_DIR/"  
mv console "$SUB_DIR/" 
  
# 备份resource/public/gadmin/文件夹到子文件夹中  
mv ./resource/public/gadmin/ "$SUB_DIR/gadmin2"  

mkdir -p "./resource/public/"
  
# 下载两个文件并赋予执行权限  
# 注意：这里使用wget或curl作为示例，具体取决于您的系统配置和偏好  
wget -O "./gadmin" "https://gravecs.mg.xhgame.com/serverupgrade/webserver/gadmin" && chmod +x "./gadmin"  
wget -O "./console" "https://gravecs.mg.xhgame.com/serverupgrade/webserver/console" && chmod +x "./console"  
  
# 下载dist.zip并解压到resource/public/gadmin文件夹中  
wget -O "./dist.zip" "https://gravecs.mg.xhgame.com/serverupgrade/webserver/dist.zip"  
unzip -o "./dist.zip" -d "./resource/public/"
mv "./resource/public/dist" "./resource/public/gadmin"

# mkdir -p "./resource/public/bin/"
wget -O "./resource/public/gadmin/jsonConvert" "https://gravecs.mg.xhgame.com/serverupgrade/webserver/jsonConvert" && chmod +x "./resource/public/gadmin/jsonConvert" 
  
# 脚本结束，可以添加一些输出或检查以确认操作是否成功  
echo "All operations completed successfully."

# wget -O "./deploy.sh" "https://gravecs.mg.xhgame.com/serverupgrade/webserver/deploy.sh" && chmod +x "./deploy.sh"

# wget -O "./product.json" "https://gravecs.mg.xhgame.com/serverupgrade/webserver/product.json"