#!/bin/bash
source $HOME/.gamerc

CLIENT_PATCH_DIRECTORY="${HOME}/www/${GAME_TYPE}-TEST/"
LOG_OUTPUT="/tmp/check_translate_file_count_monitor.log"

file_cnt_arr=()

if [ -f "${LOG_OUTPUT}" ]; then rm -rf ${LOG_OUTPUT}; fi

cd ${CLIENT_PATCH_DIRECTORY}
for file in $(ls GameDataTranslateFileList_*); do 
	country=$(echo ${file}|sed 's/GameDataTranslateFileList_//;s/.txt//');
	num=$(cat ${file} | head -n 1);
	file_cnt_arr+=("${num}")
	echo "${country} => ${num}" | tee -a ${LOG_OUTPUT}
done

count_compare=0
for count in "${file_cnt_arr[@]}"; do
	if [ "${count_compare}" == '0' ]; then
		count_compare=${count}
	else
		if [ "${count_compare}" != "${count}" ]; then
			exec send_messages ERROR check_translate_file_count "翻譯檔 檔案數目異常 請確認"
		fi
	fi
done

echo "Successfully..."
