5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 13:00:47 +00:00

Imprint build name and version number if available

This commit is contained in:
Neil Alexander 2018-12-07 22:20:11 +00:00
parent 4bc009d845
commit 8e784438c7
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
3 changed files with 29 additions and 2 deletions

5
build
View File

@ -14,10 +14,11 @@ go get -d -v yggdrasil
for file in *.go ; do for file in *.go ; do
echo "Building: $file" echo "Building: $file"
#go build $@ $file #go build $@ $file
IMPRINT="-X yggdrasil.buildName=$(sh contrib/semver/name.sh) -X yggdrasil.buildVersion=$(sh contrib/semver/version.sh)"
if [ $DEBUG ]; then if [ $DEBUG ]; then
go build -tags debug -v $file go build -ldflags="$IMPRINT" -tags debug -v $file
else else
go build -ldflags="-s -w" -v $file go build -ldflags="$IMPRINT -s -w" -v $file
fi fi
if [ $UPX ]; then if [ $UPX ]; then
upx --brute ${file%.go} upx --brute ${file%.go}

View File

@ -12,6 +12,9 @@ import (
"yggdrasil/defaults" "yggdrasil/defaults"
) )
var buildName string
var buildVersion string
// The Core object represents the Yggdrasil node. You should create a Core // The Core object represents the Yggdrasil node. You should create a Core
// object for each Yggdrasil node you plan to run. // object for each Yggdrasil node you plan to run.
type Core struct { type Core struct {
@ -59,6 +62,24 @@ func (c *Core) init(bpub *boxPubKey,
c.tun.init(c) c.tun.init(c)
} }
// Get the current build name. This is usually injected if built from git,
// or returns "unknown" otherwise.
func GetBuildName() string {
if buildName == "" {
return "unknown"
}
return buildName
}
// Get the current build version. This is usually injected if built from git,
// or returns "unknown" otherwise.
func GetBuildVersion() string {
if buildVersion == "" {
return "unknown"
}
return buildVersion
}
// Starts up Yggdrasil using the provided NodeConfig, and outputs debug logging // Starts up Yggdrasil using the provided NodeConfig, and outputs debug logging
// through the provided log.Logger. The started stack will include TCP and UDP // through the provided log.Logger. The started stack will include TCP and UDP
// sockets, a multicast discovery socket, an admin socket, router, switch and // sockets, a multicast discovery socket, an admin socket, router, switch and

View File

@ -100,10 +100,15 @@ func main() {
normaliseconf := flag.Bool("normaliseconf", false, "use in combination with either -useconf or -useconffile, outputs your configuration normalised") normaliseconf := flag.Bool("normaliseconf", false, "use in combination with either -useconf or -useconffile, outputs your configuration normalised")
confjson := flag.Bool("json", false, "print configuration from -genconf or -normaliseconf as JSON instead of HJSON") confjson := flag.Bool("json", false, "print configuration from -genconf or -normaliseconf as JSON instead of HJSON")
autoconf := flag.Bool("autoconf", false, "automatic mode (dynamic IP, peer with IPv6 neighbors)") autoconf := flag.Bool("autoconf", false, "automatic mode (dynamic IP, peer with IPv6 neighbors)")
version := flag.Bool("version", false, "prints the version of this build")
flag.Parse() flag.Parse()
var cfg *nodeConfig var cfg *nodeConfig
switch { switch {
case *version:
fmt.Println("Build name:", yggdrasil.GetBuildName())
fmt.Println("Build version:", yggdrasil.GetBuildVersion())
os.Exit(0)
case *autoconf: case *autoconf:
// Use an autoconf-generated config, this will give us random keys and // Use an autoconf-generated config, this will give us random keys and
// port numbers, and will use an automatically selected TUN/TAP interface. // port numbers, and will use an automatically selected TUN/TAP interface.