#! /bin/tcsh -f
#
#	メッセージツールをアップデート
#
#	send.sh
#

###### 
# ツールロム ディレクトリ
# set DIR_ToolRom=/auto/srd036J/usr/people/forest3/forest/src/rom_d
set DIR_ToolRom=/auto/pre-komatu/usr/people/forest3/forest/src/rom_d

# メッセージデータ ディレクトリ
# set DIR_MsgData=/auto/ikuiku/home/mnt01/srd00/srd/FOREST/message_msg
set DIR_MsgData=/auto/ikuiku/home/forest/FOREST/message_msg

# 転送先 ディレクトリ
# set DIR_MsgTool=/auto/ikuiku/home/mnt01/srd00/srd/FOREST/message_tool
set DIR_MsgTool=/auto/ikuiku/home/forest/FOREST/message_tool

# コンバート作業 ディレクトリ
set DIR_data_shape=/project/forest/data/shape/MESSAGE/JPN
set DIR_MsgConv=$DIR_data_shape/MSG/conv
set DIR_SelectConv=$DIR_data_shape/SELECT/conv
set DIR_HandbillConv=$DIR_data_shape/HANDBILL/conv
set DIR_StringConv=$DIR_data_shape/STRING/conv
set DIR_HandbillzConv=$DIR_data_shape/HANDBILLZ/conv

# ツール転送元 ディレクトリ
set DIR_forest_m=/project/forest/forest_tool/

# ネットワークチェック文字列
set NET_CHECK="$DIR_ToolRom $DIR_MsgData $DIR_MsgTool $DIR_data_shape $DIR_forest_m"


###### ネットワーク接続の確認。
echo ""
echo "ネットワークの接続を確認しています。"

@ flag_net_err = 0

foreach dir ($NET_CHECK)
    if (! -d $dir) then
	echo $dir
	@ flag_net_err = 1
    endif
end
if ($flag_net_err != 0) then
    echo "↑繋がっていません！！"
    goto errors
endif


###### rom 確認
if (! -e $DIR_ToolRom/rom) then
    echo "rom がありません！！"
    goto errors
endif


###### ユーザがダウンロード中でないかを確認。
\ls -l $DIR_MsgTool/msg_download_now_* >& /dev/null
if ($status == 0) then
    \ls -l $DIR_MsgTool/msg_download_now_*
    echo -n "只今、ダウンロード中のようです。強行しますか？(y/n)"
    set ans=$<
    if ($ans != "y" && $ans != "Y" && $ans != "yes" && $ans != "YES" && $ans != "YES") then
	goto errors
    endif
endif


###### 更新中を示すファイルを生成
echo "メッセージツールアップデート開始します。"
\touch $DIR_MsgTool/msg_update_now


###### Decl. をカレントディレクトリにコピー
\cp $DIR_MsgConv/convert.decl .
echo "tool" >> convert.decl

\cp $DIR_SelectConv/convert.decl select.decl
echo "tool" >> select.decl

\cp $DIR_HandbillConv/convert.decl mail.decl
echo "tool" >> mail.decl

\cp $DIR_StringConv/convert.decl string.decl
echo "tool" >> string.decl

echo "p.1"


###### 各種データを転送
\cp $DIR_ToolRom/rom $DIR_MsgTool

echo "p.2"
\cp tool_load6102.sh $DIR_MsgTool
\cp tool_load6105.sh $DIR_MsgTool

\cp $DIR_forest_m/forest_m $DIR_MsgTool
\cp /usr/local/bin/nkf $DIR_MsgTool

echo "p.3"
\cp convert.sh $DIR_MsgTool
\cp convert.decl $DIR_MsgTool
\cp select.decl $DIR_MsgTool
\cp string.decl $DIR_MsgTool
\cp mail.decl $DIR_MsgTool
\cp test.msg $DIR_MsgTool
\cp test.mail $DIR_MsgTool
\cp test.super $DIR_MsgTool
\cp test.ps $DIR_MsgTool
\cp test.string $DIR_MsgTool
\cp tool.ps $DIR_MsgTool
\cp tool.super $DIR_MsgTool
\cp tool.mail $DIR_MsgTool
\cp tool.string $DIR_MsgTool

echo "p.4"
\cp tool.msg $DIR_MsgTool
\cp $DIR_MsgData/effect.msg $DIR_MsgTool/tool_eff.msg

echo "p.5"
# (log)
\date +"%y/%m/%d-%T" >> msg_tool_version.log
\cp msg_tool_version.log $DIR_MsgTool

echo "p.6"

# (enum.)
\cp $DIR_MsgConv/message_data_enum.h $DIR_MsgTool
\cp $DIR_SelectConv/select_data_enum.h $DIR_MsgTool
\cp $DIR_HandbillConv/mail_data_enum.h $DIR_MsgTool
\cp $DIR_StringConv/string_data_enum.h $DIR_MsgTool
\cp $DIR_HandbillzConv/handbillz_data_enum.h $DIR_MsgTool


###### 更新中を示すファイルを削除
\rm -f $DIR_MsgTool/msg_update_now

###### 無事終了
echo "終了。"
exit 0


###### エラー処置
errors:
echo "アップデートを中止します。"
exit 1
