#!/bin/bash

export CWG_REL_TAG=${CWG_TAG:-"4.0.1b0"}
export CWG_REL_DATE=$(date +%Y%m%d-%H%M)
export CWG_REL=${CWG_REL_TAG}-${CWG_REL_DATE}
export CWG_REL_BIN=cwgbin-${CWG_REL}
export CWG_REL_DOC=cwgdoc-${CWG_REL_TAG}
export CWG_SRC_DIR=~/git/carbonwg-pic
export CWG_DOC_DIR=~/git/carbonwg-doc
export CWG_REL_TOP=${CWG_SRC_DIR}/releases
export CWG_REL_DIR=cwg-${CWG_REL}
export CWG_REL_PATH=${CWG_REL_TOP}/${CWG_REL_DIR}
export TAR_EXCL="--exclude=*/.DS_Store --exclude=*/__pycache__"

cd ${CWG_DOC_DIR}
./mkdoc/mkdoc-release.sh

cd ${CWG_SRC_DIR}
mkdir -p ${CWG_REL_PATH}
mkdir ${CWG_REL_PATH}/${CWG_REL_DOC}
mv ${CWG_DOC_DIR}/${CWG_REL_DOC}/* ${CWG_REL_PATH}/${CWG_REL_DOC}
COPYFILE_DISABLE=1 tar czvf ${CWG_REL_PATH}/cwg-bl-${CWG_REL_TAG}.tar.gz -s /cwg-pic.*production/cwg-boot/g cwg-pic.X/dist/cwg_boot/production/* 
COPYFILE_DISABLE=1 tar czvf ${CWG_REL_PATH}/cwg-nb-${CWG_REL_TAG}.tar.gz -s /cwg-pic.*production/cwg-nonboot/g cwg-pic.X/dist/cwg_nonboot/production/* 
COPYFILE_DISABLE=1 tar czvf ${CWG_REL_PATH}/cwg-utils-${CWG_REL_TAG}.tar.gz ${TAR_EXCL} utils

cd ${CWG_REL_PATH}
COPYFILE_DISABLE=1 tar czvf ${CWG_REL_DOC}.tar.gz ${TAR_EXCL}  ${CWG_REL_DOC}
rm -r ${CWG_REL_PATH}/${CWG_REL_DOC}
rm -r ${CWG_DOC_DIR}/${CWG_REL_DOC}
cd ${CWG_REL_TOP}
 
COPYFILE_DISABLE=1 tar czvf ${CWG_REL_TOP}/cwg-${CWG_REL}.tar.gz ${TAR_EXCL} ${CWG_REL_DIR}

