#!/bin/bash

# 載入 gamerc
source ~/.gamerc

# 台版任務ID與名稱對應
cat ${WORKING_DIRECTORY}/common-${SOURCE_OF_SYNC_TO_LIVE}/Data/db/s_equipup.ini | egrep '^[0-9].*' | sed 's/,/=>/g' | awk -F"|" '{print $1","$2","$3","$4}' | grep '^[0-9]\{1,2\},' > /tmp/equipup2db_tw.csv

# 台版任務對應 CSV 同步到 Ctrl 機, 並更新到 equipup2db
scp /tmp/equipup2db_tw.csv ctrl:/tmp

ssh ctrl "psql -U postgres WebTool -c \"CREATE TABLE IF NOT EXISTS equipup2db (level integer primary key, display_level integer, display_real_star integer, display_total_star integer)\""
ssh ctrl "psql -U postgres WebTool -c \"TRUNCATE equipup2db\""
ssh ctrl "psql -U postgres WebTool -c \"COPY equipup2db (level,display_level,display_real_star,display_total_star) FROM '/tmp/equipup2db_tw.csv' csv\""
