#!/bin/bash PROPERTIES="build.properties" module_server="DCMP_SERVER" DEPENDENCY="dependency" RED_COLOE='\E[31m' GREEN_COLOR='\E[32m' YELLOW_COLOR='\E[33m' BLUE_COLOR='\E[34m' REDB_COLOE='\E[1;31m' GREENB_COLOR='\E[1;32m' YELLOWB_COLOR='\E[1;33m' BLUEB_COLOR='\E[1;34m' RES='\E[0m' log_info() { echo -e "${GREEN_COLOR}$1${RES}" } log_info_wait() { echo -en "${GREEN_COLOR}$1${RES}" } log_error() { echo -e "${REDB_COLOE}$1${RES}" } log_success() { echo -e "${GREENB_COLOR}$1${RES}" } clean_up() { rm -rf ${BUILD} exit 1 } die() { log_error "$1" clean_up } PARAMNUM=$# if [ "$PARAMNUM" -ne "2" ];then echo "-p project_name" echo "demo: sh build.sh -p DCMP_Server" exit 1 fi DCMP_CODE_DIR="/home/sviauto/.jenkins/workspace/Docker_DCMP_server" TAGS_DIR="${DCMP_CODE_DIR}/dcmp/tags_dir" bulid(){ BULID_DIR="${DCMP_CODE_DIR}/dcmp/bulid_dir" if [ -d ${BULID_DIR} ]; then echo "${BULID_DIR} exits." rm -rf ${BULID_DIR} mkdir -p ${BULID_DIR} else echo "${BULID_DIR} not exits." mkdir -p ${BULID_DIR} fi cd ${BULID_DIR} if [ -f "${BULID_DIR}/dist/dcmpServer" ]; then echo "dcmpServer exe exits." rm -rf dcmpServer fi echo "${DCMP_CODE_DIR}/src/dcmpServer.py" pyinstaller -F "${DCMP_CODE_DIR}/src/dcmpServer.py" if [ $? -ne 0 ]; then die "[bulid FAIL]" else echo " [bulid OK]" fi } cp_exe() { if [ -d ${TAGS_DIR} ]; then echo "${TAGS_DIR} exits." rm -rf ${TAGS_DIR} mkdir -p ${TAGS_DIR} else echo "${TAGS_DIR} not exits." mkdir -p ${TAGS_DIR} fi cd ${TAGS_DIR} mkdir "sql" mkdir "software" if [ -f "${BULID_DIR}/dist/dcmpServer" ]; then cp "${BULID_DIR}/dist/dcmpServer" "${TAGS_DIR}/software/" else echo "dcmpServer exe not exits." exit 0 fi if [ $? -ne 0 ]; then die "[cp exe FAIL]" else log_success "[cp exe OK]" fi } cp_utils(){ cp -r ${DCMP_CODE_DIR}/src/utils ${TAGS_DIR}/software/ if [ ! -d "${TAGS_DIR}/software/utils" ];then die "cp utils FAIL" exit 0 else log_success "cp utils success" cd "${TAGS_DIR}/software/utils" pwd rm -rf ./*/*.py rm -rf *.py fi cp ${DCMP_CODE_DIR}/src/utils/docker_config.ini ${TAGS_DIR}/software/utils/config.ini cp -r ${DCMP_CODE_DIR}/src/lib ${TAGS_DIR}/ cp -rp ${DCMP_CODE_DIR}/docker/* ${TAGS_DIR} cp ${DCMP_CODE_DIR}/etc/* ${TAGS_DIR}/sql/ cp ${DCMP_CODE_DIR}/src/utils/casclient/docker_casclient.ini ${TAGS_DIR}/software/utils/casclient/casclient.ini cp ${DCMP_CODE_DIR}/src/utils/authclient/docker_licenseclient.conf ${TAGS_DIR}/software/utils/authclient/licenseclient.conf cp ${DCMP_CODE_DIR}/src/utils/logsuite/docker_logdb.conf ${TAGS_DIR}/software/utils/logsuite/logdb.conf } NEName="DCMP_SERVER" Version=$(grep 'ProductVersion=' ${DCMP_CODE_DIR}/build/build.properies | cut -d'=' -f2) Module=$(grep 'Module=' ${DCMP_CODE_DIR}/build/build.properies | cut -d'=' -f2) Provider="Sowell 视维" BuildTime=$(date +"%Y-%m-%d %H:%M:%S") BuildVersion=$(date +"%Y%m%d") write_version(){ echo "NEName=${NEName}" > ${TAGS_DIR}/version echo "Version=${Version}" echo "Version=${Version}" >> ${TAGS_DIR}/version echo "Provider=${Provider}" >> ${TAGS_DIR}/version echo "BuildTime=${BuildTime}" >> ${TAGS_DIR}/version } tags_dir(){ cd ${DCMP_CODE_DIR}/dcmp cp -r tags_dir ${module_server}_${Version}_${BuildVersion}_${Module} TAG=${module_server}_${Version}_${BuildVersion}_${Module} tar -zcvf ${module_server}_${Version}_${BuildVersion}_${Module}.tar.gz ${TAG} --exclude=.svn if [ $? -eq 0 ]; then log_success " [OK]" else die " [FAIL]" fi rm -rf ${TAG} } #安装依赖�? #编译 bulid #cp可执行程�? cp_exe #cp工具和sql、以及命�? cp_utils #写版�? write_version #打包 tags_dir exit 0