#!/bin/bash

source ~/.gamerc

COREDUMP_ROOT_DIRECTORY="${WORKING_DIRECTORY}/www/core"
COREDUMP_OLD_DIRECTORY="${WORKING_DIRECTORY}/www/core/live_core_dump"
#TIME_INTERVAL="5"
#CHECK_TIME_INTERVAL=$(date --date="${TIME_INTERVAL} minutes ago" +'%Y-%m-%d %H:%M') 
TEST_SERVER_IP=${TEST_SERVER_GLOBAL_IP}
PATCH_SERVER_IP=${REMOTE_PATCH_SERVER}
REMOTE_DIRECTORY_ON_PATCH="upload/${COUNTRY_CODE}"
TODAY=$(date +'%Y%m%d')


cd ${COREDUMP_ROOT_DIRECTORY}

#find . -name "${GAME_TYPE}-${COUNTRY_CODE}-*.core_dump.*.tar.gz" -newermt "${CHECK_TIME_INTERVAL}" | xargs ls {}

#lftp -e 'mput test_core*; quit' http://60.199.246.187/upload/HK/ 
lftp -e "mput ${GAME_TYPE}-${COUNTRY_CODE}-*.core_dump.*.tar.gz ; quit" http://${PATCH_SERVER_IP}/${REMOTE_DIRECTORY_ON_PATCH} 

ls ${GAME_TYPE}-${COUNTRY_CODE}-*.core_dump.*.tar.gz -hltra | awk -F" " '{print $9}' | sed "s/^/\/upload\/${COUNTRY_CODE}\//"

if [ ! -d ${COREDUMP_OLD_DIRECTORY}/${TODAY} ] ; then
	mkdir -p ${COREDUMP_OLD_DIRECTORY}/${TODAY}
fi

mv ${GAME_TYPE}-${COUNTRY_CODE}-*.core_dump.*.tar.gz ${COREDUMP_OLD_DIRECTORY}/${TODAY}
