#!/bin/bash

# 載入 gamerc
source ~/.gamerc

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

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

ssh ctrl "psql -U postgres WebTool -c \"CREATE TABLE IF NOT EXISTS title2db (title_id integer primary key, titlename text)\""
ssh ctrl "psql -U postgres WebTool -c \"TRUNCATE title2db\""
ssh ctrl "psql -U postgres WebTool -c \"COPY title2db (title_id,titlename) FROM '/tmp/title2db_tw.csv' csv\""
