host_check/build.sh

42 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
# Default architecture
DEFAULT_ARCH="linux/amd64"
# Supported architectures (adjust as needed)
ARCHITECTURES=("linux/amd64" "linux/arm64" "linux/arm/v7")
# Build function (Updated)
build_binary() {
os=$1
arch=$2
output_name="host_check"
if [[ "$os/$arch" != "$DEFAULT_ARCH" ]]; then
output_name="${output_name}_${os}_${arch}"
fi
# Create the dist folder if it doesn't exist
mkdir -p dist
echo "Building for ${os}/${arch} -> dist/${output_name}"
GOOS=${os} GOARCH=${arch} go build -o dist/${output_name} .
}
# Main Build Process (Updated)
for arch in "${ARCHITECTURES[@]}"; do
IFS='/' read -r -a parts <<< "$arch"
os=${parts[0]}
arch=${parts[1]}
# Ensure module files are present in the current directory
if [ ! -f "go.mod" ] || [ ! -f "go.sum" ]; then
echo "Error: 'go.mod' and/or 'go.sum' not found in the current directory."
echo "Make sure you're in the root of your Go module before running the build."
exit 1
fi
build_binary $os $arch
done