From 92e266d22fbce193c7c76e286d807f37e1898767 Mon Sep 17 00:00:00 2001 From: Ivan Huang Date: Fri, 30 May 2025 02:08:00 +0800 Subject: [PATCH 1/2] Add shell script parameters to support build for different architectures or operating systems. --- build.sh | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 66175e53..7d821012 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,38 @@ #!/bin/sh +usage() { +cat << EOF +Usage: ./build.sh [-a <386|amd64|arm|arm64>] [-o ] +Build migration-verifier for mongosync. + +-a Specify the target architecture for the build, if not specified, it will use the current architecture. +-o Specify the target operating system for the build, if not specified, it will use the current OS. +-h Display this help message. +EOF +exit 1; +} + +while getopts "o:a:" option; do + case "$option" in + a) + arch=${OPTARG} + test "$arch" = "386" -o "$arch" = amd64 -o "$arch" = "arm" -o "$arch" = "arm64" || usage + ;; + o) + os=${OPTARG} + test "$os" = "linux" -o "$os" = "darwin" -o "$os" = "windows" || usage + ;; + h) + usage + ;; + *) + usage + ;; + esac +done +shift $((OPTIND-1)) + commit=$(git show --no-patch --format='%H') buildTime=$(date -u) -go build -ldflags="-X 'main.Revision=$commit' -X 'main.BuildTime=$buildTime'" main/migration_verifier.go +GOARCH=${arch:=$(go env GOARCH)} GOOS=${os:=$(go env GOOS)} go build -ldflags="-X 'main.Revision=$commit' -X 'main.BuildTime=$buildTime'" main/migration_verifier.go From 0489788f15985c4534d154301627e0ac7213b537 Mon Sep 17 00:00:00 2001 From: Ivan Huang Date: Fri, 30 May 2025 02:15:22 +0800 Subject: [PATCH 2/2] Using -h parameter should not be treated as an illegal option. --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 7d821012..767b9fc2 100755 --- a/build.sh +++ b/build.sh @@ -12,7 +12,7 @@ EOF exit 1; } -while getopts "o:a:" option; do +while getopts "o:a:h" option; do case "$option" in a) arch=${OPTARG}