initial commit [141.14.140.180,mike]

This commit is contained in:
mike committed 2026-10-26 15:52:55 +01:00
commit e34ba75b7b
33 files changed
+6267

No files matched your search

Executable
+75
View File
@@ -0,0 +1,75 @@
#!/bin/sh
# Build nscan for the usual platforms into ./bin, auto-incrementing the patch
# version by 0.0.1 on every build.
#
# version.txt holds the currently built version. Each run increments the patch
# component, then builds every platform with that one version injected via
# -ldflags, and writes it back. So version.txt always reflects the version of
# the binaries just built, and all of them carry the same one. The literal in
# version.go is only ever what a bare `go build` picks up.
#
# The files in ./bin are named nscan-<goos>-<goarch>; `mgsh release` attaches
# them to the release as they are.
#
# Override the platform list to build just one, or to add a platform:
# PLATFORMS="linux/amd64" ./build.sh
# PLATFORMS="windows/amd64" ./build.sh
#
# A plain run only ever steps the patch. A minor or major step is taken by
# naming the version outright, which is then written back like any other:
# VERSION=1.1.0 ./build.sh
#
# Windows is not in the default list: it compiles, but ICMP there needs
# administrator rights and nothing of it has been tested, so shipping it would
# promise more than nscan keeps. PLATFORMS can add it.
#
# -s -w drops the symbol table and DWARF info, -trimpath keeps build paths out
# of the binary; together they roughly halve it. Neither affects a panic trace.
set -e
cd "$(dirname "$0")"
PLATFORMS=${PLATFORMS:-"darwin/arm64 darwin/amd64 linux/amd64 linux/arm64"}
if [ -n "$VERSION" ]; then
NV="$VERSION"
else
V=$(cat version.txt 2>/dev/null || echo 1.0.0)
# split MAJOR.MINOR.PATCH and increment PATCH (no carry: 1.0.9 -> 1.0.10)
MAJOR=${V%%.*}
REST=${V#*.}
MINOR=${REST%%.*}
PATCH=${REST#*.}
PATCH=$((PATCH + 1))
NV="$MAJOR.$MINOR.$PATCH"
fi
mkdir -p bin
HOST="$(go env GOOS)/$(go env GOARCH)"
for p in $PLATFORMS; do
os=${p%/*}
arch=${p#*/}
ext=""
if [ "$os" = "windows" ]; then
ext=".exe"
fi
out="bin/nscan-$os-$arch$ext"
# CGO_ENABLED=0 throughout: it makes the cross builds work without a
# toolchain per target and the binaries static. nscan talks to the network
# through its own sockets and reads the ARP table via sysctl or /proc, so
# nothing is lost by dropping cgo.
CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" \
go build -trimpath -ldflags "-s -w -X main.Version=$NV" -o "$out" .
if [ "$p" = "$HOST" ]; then
ln -sf "nscan-$os-$arch$ext" bin/nscan # the one for this machine
echo " $out -> bin/nscan"
else
echo " $out"
fi
done
echo "$NV" > version.txt
echo "built nscan v$NV"