package main import ( "fmt" "runtime" "strings" ) // buildTime is stamped at build time via -ldflags "-X main.buildTime=..." // (build.sh does this). A plain "go build" with no ldflags leaves it at // "dev" — still a meaningful, comparable value: two "dev" builds are only // ever the same binary bytes copied around (self-deploy), never two // independently built ones landing on the same value by chance. var buildTime = "dev" // versionString is what `clonetool version` prints, and what a remote // host's own `version` output is compared against (see remoteBuildTag) to // tell whether it's running the same build as this binary. func versionString() string { return fmt.Sprintf("clonetool %s/%s build=%s", runtime.GOOS, runtime.GOARCH, buildTime) } // remoteBuildTag extracts the "build=..." tag from a clonetool `version` // line, ignoring its GOOS/GOARCH — those are expected to legitimately // differ across a cross-compiled deploy — and any surrounding ssh/shell // noise on other lines. Returns "" if the line isn't a clonetool version // line at all (e.g. "command not found"). func remoteBuildTag(out string) string { line := firstLine(out) i := strings.Index(line, "build=") if i < 0 { return "" } return strings.TrimSpace(line[i+len("build="):]) }