Modernized build and added an install so that adding this won't be a pain.
This commit is contained in:
parent
339bc8b0ea
commit
d3e101a938
51
build.sh
51
build.sh
|
@ -4,7 +4,24 @@
|
||||||
DEFAULT_ARCH="linux/amd64"
|
DEFAULT_ARCH="linux/amd64"
|
||||||
|
|
||||||
# Supported architectures (adjust as needed)
|
# Supported architectures (adjust as needed)
|
||||||
ARCHITECTURES=("linux/amd64" "linux/arm64" "linux/arm/v7")
|
ARCHITECTURES=("linux/amd64" "linux/arm64" "linux/arm/v7" "darwin/amd64" "darwin/arm64")
|
||||||
|
|
||||||
|
# Ensure all necessary directories exist and go modules are ready
|
||||||
|
prepare_build() {
|
||||||
|
# Create necessary directories if they don't exist
|
||||||
|
mkdir -p dist
|
||||||
|
mkdir -p build_logs
|
||||||
|
|
||||||
|
# Initialize go modules if go.mod does not exist
|
||||||
|
if [ ! -f go.mod ]; then
|
||||||
|
echo "Initializing Go modules"
|
||||||
|
go mod init go-glitch
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Fetch and ensure all dependencies are up to date
|
||||||
|
echo "Checking dependencies..."
|
||||||
|
go mod tidy
|
||||||
|
}
|
||||||
|
|
||||||
# Build function
|
# Build function
|
||||||
build_binary() {
|
build_binary() {
|
||||||
|
@ -16,14 +33,38 @@ build_binary() {
|
||||||
output_name="${output_name}_${os}_${arch}"
|
output_name="${output_name}_${os}_${arch}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Building for ${os}/${arch} -> ${output_name}"
|
output_name="dist/${output_name}"
|
||||||
GOOS=${os} GOARCH=${arch} go build -o ${output_name}
|
|
||||||
|
# Dynamic Linking
|
||||||
|
echo "Building dynamically linked for ${os}/${arch} -> ${output_name}"
|
||||||
|
GOOS=${os} GOARCH=${arch} go build -o ${output_name} main.go 2>build_logs/${os}_${arch}_build.log
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Successfully built ${output_name}"
|
||||||
|
else
|
||||||
|
echo "Failed to build ${output_name}. Check build_logs/${os}_${arch}_build.log for errors."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Static Linking
|
||||||
|
if [[ "$os" == "linux" ]]; then # Typically, static linking is most relevant for Linux environments
|
||||||
|
static_output_name="${output_name}_static"
|
||||||
|
echo "Building statically linked for ${os}/${arch} -> ${static_output_name}"
|
||||||
|
CGO_ENABLED=0 GOOS=${os} GOARCH=${arch} go build -a -ldflags '-extldflags "-static"' -o ${static_output_name} main.go 2>build_logs/${os}_${arch}_static_build.log
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Successfully built ${static_output_name}"
|
||||||
|
else
|
||||||
|
echo "Failed to build ${static_output_name}. Check build_logs/${os}_${arch}_static_build.log for errors."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main Build Process
|
# Main Build Process
|
||||||
|
prepare_build
|
||||||
for arch in "${ARCHITECTURES[@]}"; do
|
for arch in "${ARCHITECTURES[@]}"; do
|
||||||
IFS='/' read -r -a parts <<< "$arch" # Split architecture string
|
IFS='/' read -r -a parts <<< "$arch" # Split architecture string
|
||||||
os=${parts[0]}
|
os=${parts[0]}
|
||||||
arch=${parts[1]}
|
arch=${parts[1]}
|
||||||
build_binary $os $arch
|
build_binary $os $arch
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo "Build process completed."
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3
go.mod
3
go.mod
|
@ -2,8 +2,9 @@ module go-glitch
|
||||||
|
|
||||||
go 1.21.1
|
go 1.21.1
|
||||||
|
|
||||||
|
require github.com/getsentry/sentry-go v0.27.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/getsentry/sentry-go v0.27.0 // indirect
|
|
||||||
golang.org/x/sys v0.6.0 // indirect
|
golang.org/x/sys v0.6.0 // indirect
|
||||||
golang.org/x/text v0.8.0 // indirect
|
golang.org/x/text v0.8.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
16
go.sum
16
go.sum
|
@ -1,6 +1,22 @@
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps=
|
github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps=
|
||||||
github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
|
github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
|
||||||
|
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
|
||||||
|
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
|
||||||
|
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||||
|
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
|
||||||
|
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
|
||||||
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||||
|
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
|
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
|
||||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
INSTALL_DIR="/usr/local/bin"
|
||||||
|
BINARY_NAME="go-glitch"
|
||||||
|
BASE_URL="https://git.nixc.us/Nixius/go-glitch/raw/branch/main/dist"
|
||||||
|
|
||||||
|
declare -A binaries
|
||||||
|
binaries["linux/amd64"]="go-glitch_linux_amd64"
|
||||||
|
binaries["linux/arm64"]="go-glitch_linux_arm64"
|
||||||
|
binaries["linux/arm/v7"]="go-glitch_linux_arm"
|
||||||
|
binaries["darwin/amd64"]="go-glitch_darwin_amd64"
|
||||||
|
binaries["darwin/arm64"]="go-glitch_darwin_arm64"
|
||||||
|
|
||||||
|
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
||||||
|
ARCH="$(uname -m)"
|
||||||
|
|
||||||
|
case $ARCH in
|
||||||
|
x86_64) ARCH="amd64" ;;
|
||||||
|
arm64 | aarch64) ARCH="arm64" ;;
|
||||||
|
arm*) ARCH="arm/v7" ;;
|
||||||
|
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
KEY="${OS}/${ARCH}"
|
||||||
|
|
||||||
|
if [[ -z "${binaries[$KEY]}" ]]; then
|
||||||
|
echo "No pre-built binary for your system architecture ($KEY)."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
BINARY_URL="${BASE_URL}/${binaries[$KEY]}"
|
||||||
|
|
||||||
|
echo "Downloading and installing $BINARY_NAME from $BINARY_URL..."
|
||||||
|
sudo curl -sSL "$BINARY_URL" -o "${INSTALL_DIR}/${BINARY_NAME}"
|
||||||
|
|
||||||
|
sudo chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
|
||||||
|
echo "Installed $BINARY_NAME to $INSTALL_DIR"
|
Loading…
Reference in New Issue