source ./common.sh

work_dir=`pwd`
dir_name=`basename $PWD`

if [ -f "custom_init.sh" ]; then
    source ./custom_init.sh
fi

reg='\.*D[1-9]$'
if [[ $dir_name =~  $reg  ]]
then
    touch bin/is_test_env
    cd ${SOURCE_DIR}
    git pull
    git checkout release
    cd $work_dir
fi

echo $dir_name|grep _bt
if [[ $? -eq 0 ]]; then
    cd ${SOURCE_DIR}
    git pull
    git checkout bt
    cd $work_dir
fi

cd ${SOURCE_PATH}
echo ${PRE_COMPILE_CMD}|sh
echo ${COMPILE_CMD}|sh
pwd
echo ${POST_COMPILE_CMD}|sh
pwd
cd $work_dir

tag_name=`git status |grep '# On branch '|sed 's/# On branch //g'`
package_name=${dir_name}.tar.gz

if [[ IS_DEV_ENV -eq 1 ]]; then
    rm -rf new_lib
    mkdir -p new_lib
    cp -rf lib/* new_lib/
else
    tar --exclude=*.git -chzf target/${package_name} bin common.sh reload.sh restart.sh start_instance.sh manage.py config lib ${EXT_PKG_FILES}
fi
