#!/bin/bash

# 参数检查
[[ ! "$1" || ! "$2" ]] && echo "$0 area_id name" && exit 1

area_id=$1
name=$2

dir=/data/web

# 执行nginx配置
sudo /root/nginx.sh

# 切换到目标目录
cd $dir || exit 1

# 下载并设置权限
sudo wget http://82.157.161.32/p23.json || exit 1
sudo chown -R game:game p23.json

# 获取公网IP并替换配置
ip_wan=$(curl -s icanhazip.com) || exit 1
echo "ip_wan:$ip_wan"

# 替换配置文件中的值
sed -i "s/82.157.161.32/$ip_wan/g" p23.json
sed -i "s/\"1\"/\"$area_id\"/g" p23.json
sed -i "s/鬼杀/$name/g" p23.json
