#!/bin/bash

# 載入 gamerc
source ~/.gamerc

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

# 台版場景對應 CSV 同步到 Ctrl 機, 並更新到 node2db
scp /tmp/class2db_tw.csv ctrl:/tmp

ssh ctrl "psql -U postgres WebTool -c \"CREATE TABLE IF NOT EXISTS class2db (class_id integer primary key, classname text)\""
ssh ctrl "psql -U postgres WebTool -c \"TRUNCATE class2db\""
ssh ctrl "psql -U postgres WebTool -c \"COPY class2db (class_id,classname) FROM '/tmp/class2db_tw.csv' csv\""
