#!/bin/bash

GitRootDir=$(dirname $(dirname $(dirname $(realpath $0))))
BERootDir=${GitRootDir}/be.wfc
FERootDir=${GitRootDir}/fe.wfc
FEUserRootDir=${GitRootDir}/fe.wfc.user
BuildRootDir=${GitRootDir}/build.wfc
I18nResourcesDir=${BERootDir}/wfc-common/wfc-common-core/src/main/resources

WFCWorkDir=/opt/wfc
BuildDockerDir=${BuildRootDir}/build/docker

# 复制项目的文件到对应docker路径，便于一键生成镜像。
usage() {
	echo "Usage: sh copy.sh"
	exit 1
}

if [ $# -ne 1 ]; then
	GitRootDir=$1
fi

# copy sql
echo -n "Begin copy sql ... "
cp ${BERootDir}/sql/wfc_config_db/wfc_config_db.sql ${BuildDockerDir}/mysql/db
cp ${BERootDir}/sql/wfc_system_db/wfc_system_db.sql ${BuildDockerDir}/mysql/db
cp ${BERootDir}/sql/wfc_user_db/wfc_user_db.sql ${BuildDockerDir}/mysql/db
rm -rf ${BuildDockerDir}/mysql/db/upgrade/*
cp -rf ${BERootDir}/sql/upgrade ${BuildDockerDir}/mysql/db/
#ln -sf /tmp ${BuildDockerDir}/mysql/
echo "done"

# copy html
echo -n "Begin copy system html ... "
mkdir -p ${BuildDockerDir}/nginx/html/dist/sys
rm -rf ${BuildDockerDir}/nginx/html/dist/sys/*
cp -rf ${FERootDir}/dist/* ${BuildDockerDir}/nginx/html/dist/sys/
echo "done"

echo -n "Begin copy user html ... "
mkdir -p ${BuildDockerDir}/nginx/html/dist/u
rm -rf ${BuildDockerDir}/nginx/html/dist/u/*
cp -rf ${FEUserRootDir}/dist/* ${BuildDockerDir}/nginx/html/dist/u/
echo "done"

# copy i18n message resuorces
echo -n "Begin copy i18n message resources ... "
if [ ! -d ${BuildDockerDir}/conf/default/i18n ]; then
	mkdir -p ${BuildDockerDir}/conf/default/i18n
fi
cp -rf ${I18nResourcesDir}/i18n/* ${BuildDockerDir}/conf/default/i18n/
echo "done"

# copy jar
echo -n "Begin copy wfc-gateway ... "
cp ${BERootDir}/wfc-gateway/target/wfc-gateway.jar ${BuildDockerDir}/wfc/gateway/jar
echo "done"

echo -n "Begin copy wfc-auth ... "
cp ${BERootDir}/wfc-auth/target/wfc-auth.jar ${BuildDockerDir}/wfc/auth/jar
echo "done"

# echo -n "Begin copy wfc-visual ... "
# cp ${BERootDir}/wfc-visual/wfc-visual-monitor/target/wfc-visual-monitor.jar ${BuildDockerDir}/wfc/visual/monitor/jar
# echo "done"

echo -n "Begin copy wfc-modules-system ... "
cp ${BERootDir}/wfc-modules/wfc-system/target/wfc-modules-system.jar ${BuildDockerDir}/wfc/modules/system/jar
echo "done"

echo -n "Begin copy wfc-modules-user ... "
cp ${BERootDir}/wfc-modules/wfc-user/target/wfc-modules-user.jar ${BuildDockerDir}/wfc/modules/user/jar
echo "done"

echo -n "Begin copy wfc-modules-file ... "
cp ${BERootDir}/wfc-modules/wfc-file/target/wfc-modules-file.jar ${BuildDockerDir}/wfc/modules/file/jar
echo "done"

echo -n "Begin copy wfc-modules-job ... "
cp ${BERootDir}/wfc-modules/wfc-job/target/wfc-modules-job.jar ${BuildDockerDir}/wfc/modules/job/jar
echo "done"

# echo -n "Begin copy wfc-modules-gen ... "
# cp ${BERootDir}/wfc-modules/wfc-gen/target/wfc-modules-gen.jar ${BuildDockerDir}/wfc/modules/gen/jar
# echo "done"

echo -n "Begin copy wfc-modules-payment ... "
cp -rf ${BERootDir}/wfc-modules/wfc-payment/target/wfc-modules-payment.jar ${BuildDockerDir}/wfc/modules/payment/jar
echo "done"

