#!/bin/bash

# 載入 gamerc
source ~/.gamerc

# 台版任務ID與名稱對應
cat ${WORKING_DIRECTORY}/common-${SOURCE_OF_SYNC_TO_LIVE}/Data/db/S_Achievement.ini | awk -F"|" '$1 ~ /^[0-9]+$/ {print $1","$3}' > /tmp/achievement2db_tw.csv

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

ssh ctrl "psql -U postgres WebTool -c \"CREATE TABLE IF NOT EXISTS achievement2db (achievement_id integer primary key, achievementname text)\""
ssh ctrl "psql -U postgres WebTool -c \"TRUNCATE achievement2db\""
ssh ctrl "psql -U postgres WebTool -c \"COPY achievement2db (achievement_id,achievementname) FROM '/tmp/achievement2db_tw.csv' csv\""
