#!/usr/bin/bash
# Author : yingjian
# Version : v1.0
# Date : 2023-03-23


#/usr/local/ta-logBus/conf/logBus.conf

if [ $# -ne 1 ];then
    echo "当前传入参数错误。"
    echo "Please bash \$0 \$1 {例如 P7} "
    exit 2
fi

#获取脚本目录
cd `dirname $0`
script_dir=`pwd`

#项目目录
project_dir=$1

#清理暂存文件
echo -n "" > ${script_dir}/get_log_path.txt
echo -n "" > ${script_dir}/tmp_game_server_id.txt

#获取游戏服id
get_game_server_id () {
/bin/ls /${project_dir} > ${script_dir}/platform_dir.txt

while read line
do
  if [ -d /${project_dir}/${line} ];then
    /bin/ls /${project_dir}/${line} |grep ^[0-9]*$ |tee -a >> ${script_dir}/tmp_game_server_id.txt
else
  continue
  fi
done < ${script_dir}/platform_dir.txt
}

set_logbus_path () {
while read line
do
  while read var
  do
  if [ -d /${project_dir}/${line}/${var} ];then
    echo -ne "/${project_dir}/${line}/${var}/log/shushu_log/log.yingjian*" >> ${script_dir}/get_log_path.txt
  fi
  done< ${script_dir}/tmp_game_server_id.txt
done < ${script_dir}/platform_dir.txt

if [ -s ${script_dir}/get_log_path.txt ];then
  sed -i '/^TAIL_FILE/d' /usr/local/ta-logBus/conf/logBus.conf
  for i in `cat ${script_dir}/get_log_path.txt`
  do
  OLDIFS="$IFS"  #备份旧的IFS变量
  IFS=$'\n'   #修改分隔符为换行符
  echo -e "TAIL_FILE=${i}" >> /usr/local/ta-logBus/conf/logBus.conf
  IFS="$OLDIFS"
  done
else

  exit 3
fi

sed -i 's/yingjian//g' /usr/local/ta-logBus/conf/logBus.conf

}


get_game_server_id

sleep 2

set_logbus_path


