From 14c403ec22cdcc412877fe7573f2ef59648bc8a0 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 18 Apr 2024 10:36:57 -0400 Subject: [PATCH] Fixup --- build.sh | 24 +++++++++++++----------- go.mod | 3 +++ 2 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 go.mod diff --git a/build.sh b/build.sh index e1cde39..fb2435b 100755 --- a/build.sh +++ b/build.sh @@ -6,36 +6,38 @@ DEFAULT_ARCH="linux/amd64" # Supported architectures (adjust as needed) ARCHITECTURES=("linux/amd64" "linux/arm64" "linux/arm/v7") -# Build function (Updated) +# Find the appropriate directory containing Go code (assumes 'src' or project root) +find_go_directory() { + if [ -d "src" ] && [ -f "src/go.mod" ]; then + echo "src" # Source code is within 'src' + else + echo "." # Source code is in the root directory + fi +} + +# Build function build_binary() { os=$1 arch=$2 output_name="host_check" + go_dir=$(find_go_directory) 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} . + GOOS=${os} GOARCH=${arch} go build -o dist/${output_name} $go_dir } -# Main Build Process (Updated) +# Main Build Process 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 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f76e398 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.nixc.us/Nixius/host_check + +go 1.21.1