#!/bin/bash

# 載入 gamerc
source ~/.gamerc

# 台版道具ID與名稱對應
cat ${WORKING_DIRECTORY}/common-${SOURCE_OF_SYNC_TO_LIVE}/Data/db/S_Item.ini ${WORKING_DIRECTORY}/common-${SOURCE_OF_SYNC_TO_LIVE}/Data/db/S_ItemMall.ini | egrep '^[0-9].*' | awk -F"|" '{print $1","$8}' | egrep -v ',$' > /tmp/powerupitem_tw.csv

# 台版道具對應 CSV 同步到 Ctrl 機, 並更新到 powerupitem
rsync -avz /tmp/powerupitem_tw.csv ctrl:/tmp

ssh ctrl "psql -U postgres WebTool -c \"CREATE TABLE IF NOT EXISTS powerupitem (item_id integer primary key, itemname text)\""
ssh ctrl "psql -U postgres WebTool -c \"TRUNCATE powerupitem\""
ssh ctrl "psql -U postgres WebTool -c \"COPY powerupitem (item_id,itemname) FROM '/tmp/powerupitem_tw.csv' csv\""
