#!/bin/bash # front-end Catalog WebDir=/root/omc.git/fe.ems.vue3 WebBranch=main-v2 BuildWeb="" # back-end Catalog ApiDir=/root/omc.git/be.ems ApiBranch=main-v2 BuildApi="" # Package Catalog BuildDir=/root/omc.git/build.ems BuildBranch=main-v2 # Default Version Value VERSION="2.2508.1" # usage usage() { echo "Usage: bash $0 [OPTION]" echo echo "Build Software Package OPTION:" echo " -v Specify the version" echo " --web Build Web ($WebDir) Branch ($WebBranch)" echo " --api Build Api ($ApiDir) Branch ($ApiBranch)" echo " -h Display this help message" echo exit 1 } # Read command line arguments while [[ $# -gt 0 ]]; do case "$1" in -v) VERSION="$2"; shift 2 ;; --web) BuildWeb="build"; shift ;; --api) BuildApi="build"; shift ;; *) usage ;; esac done # =================== build branch echo cd $BuildDir git checkout . git pull git checkout $BuildBranch git pull echo "===> build checkout directory: $BuildDir" # =================== Web echo # Determine if --web is passed in if [ -n "$BuildWeb" ]; then cd $WebDir git checkout . git pull git checkout $WebBranch git pull # remote replication #scpDir=/root/omc.git/fe.ems.vue3 #scp -r -P 18422 root@192.168.9.58:$scpDir/dist $WebDir/ # local compilation npm install --registry https://registry.npmmirror.com npm run build output=$BuildDir/linux/usr/local/etc/omc/web rm -rf $output && cp -rf dist $output echo "===> web build dist copy to $output" fi # =================== Api echo # Determine if --api is passed in if [ -n "$BuildApi" ]; then cd $ApiDir git checkout . git pull git checkout $ApiBranch git pull MOD_CONFIG="be.ems/src/framework/config" go build -o omc -v -ldflags "-s -w -X '$MOD_CONFIG.Version=$VERSION' -X '$MOD_CONFIG.BuildTime=$(date)' -X '$MOD_CONFIG.GoVer=$(go version)'" output=$BuildDir/linux/usr/local/bin cp -rf omc $output/omc echo "===> go build omc copy to $output" # Vendor Database output=$BuildDir/linux/usr/local/etc/omc dirs="database default vendor" for v in ${dirs}; do rm -rf ${output}/${v} cp -rf ${ApiDir}/build/${v} ${output}/${v} done echo echo "===> vendor data copy to $output" fi # =================== deb/rpm echo bash $BuildDir/build.sh -v $VERSION # Compile the front-end and back-end and then package the version # bash pkg.sh --web --api -v 2.2503.2 # Packaged version of just the last compiled file/build directory # bash pkg.sh -v 2.2503.2