#!/bin/sh # build.sh # This script for build go projects. # @version 170227:1 # @author zhangxuhong # # [config] echo "-[config]-" # ----------------------------[manual config here]------------------------------ # REPO_SRC=/data/repo/collection_set_api # BUILD_TARGET=collection_set_api # ------------------------------------------------------------------------------ echo -e "\033[34mREPO_SRC set to: ${REPO_SRC}\033[0m" echo -e "\033[34mBUILD_TARGET set to: ${BUILD_TARGET}\033[0m" echo "" sleep 1 # [set env] echo "-[set env]-" # $GOBIN export GOBIN="${REPO_SRC}/bin" echo -e "\033[34mGOBIN set to: ${GOBIN}\033[0m" # $GOPATH export GOPATH="${REPO_SRC}" echo -e "\033[34mGOPATH set to: ${GOPATH}\033[0m" echo "" sleep 1 # [check old build target] echo "-[check old build target]-" if [ ! -d $GOBIN ]; then mkdir $GOBIN; fi if [ -f "${GOBIN}/${BUILD_TARGET}" ]; then echo -e "\033[43m[WARRING!] build target alerady exists, will remove it. \033[0m"; echo "old build_target detail:" ls -alh "${GOBIN}/${BUILD_TARGET}"; oldShaSum=`shasum "${GOBIN}/${BUILD_TARGET}" | awk -F' ' '{print $1}'`; echo "target sha: ${oldShaSum}"; rm -rf "${GOBIN}/${BUILD_TARGET}"; echo "old build target removed."; fi echo "done." echo "" sleep 1 # [build] echo "-[build]-" echo "build start: " echo "go build -o ${GOBIN}/${BUILD_TARGET}" cd "${GOPATH}/src" go build -o "${GOBIN}/${BUILD_TARGET}" ls -alh "${GOBIN}/${BUILD_TARGET}" newShaSum=`shasum "${GOBIN}/${BUILD_TARGET}" | awk -F' ' '{print $1}'`; echo "target sha: ${newShaSum}"; if [ "$oldShaSum" == "$newShaSum" ];then echo -e "\033[43m[WARRING!] old build target shasum is equals to new build target. \033[0m" fi echo "done."