]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
Add undocumented --version flag
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 23 May 2018 23:52:22 +0000 (01:52 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 24 May 2018 00:25:36 +0000 (02:25 +0200)
Makefile
main.go
version.go [new file with mode: 0644]

index 4cba1de59dbc6ec0106ebe9a85e80c32fd1df0c2..93874e9fe9d0ad7411fc793bcbd6dc6546ec0ea0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,14 @@ export GOPATH := $(CURDIR)/.gopath
 export PATH := $(PATH):$(CURDIR)/.gopath/bin
 GO_IMPORT_PATH := git.zx2c4.com/wireguard-go
 
+version.go:
+       @export GIT_CEILING_DIRECTORIES="$(realpath $(CURDIR)/..)" && \
+       tag="$$(git describe --dirty 2>/dev/null)" && \
+       ver="$$(printf 'package main\nconst WireGuardGoVersion = "%s"\n' "$$tag")" && \
+       [ "$$(cat $@ 2>/dev/null)" != "$$ver" ] && \
+       echo "$$ver" > $@ && \
+       git update-index --assume-unchanged $@ || true
+
 .gopath/.created:
        rm -rf .gopath
        mkdir -p $(dir .gopath/src/$(GO_IMPORT_PATH))
@@ -27,7 +35,7 @@ vendor/.created: Gopkg.toml Gopkg.lock | .gopath/.created
        cd .gopath/src/$(GO_IMPORT_PATH) && dep ensure -vendor-only -v
        touch $@
 
-wireguard-go: $(wildcard *.go) $(wildcard */*.go) .gopath/.created vendor/.created
+wireguard-go: $(wildcard *.go) $(wildcard */*.go) .gopath/.created vendor/.created version.go
        go build $(GO_BUILD_EXTRA_ARGS) -v $(GO_IMPORT_PATH)
 
 install: wireguard-go
@@ -40,4 +48,4 @@ update-dep: | .gopath/.created
        command -v dep >/dev/null || go get -v github.com/golang/dep/cmd/dep
        cd .gopath/src/$(GO_IMPORT_PATH) && dep ensure -update -v
 
-.PHONY: clean install update-dep
+.PHONY: clean install update-dep version.go
diff --git a/main.go b/main.go
index 29693eb291485567fad3e9b62846f428ccd10196..f21de41a58d0ec3ccffbe2479392deeda0d66b7c 100644 (file)
--- a/main.go
+++ b/main.go
@@ -74,6 +74,11 @@ func warning() {
 }
 
 func main() {
+       if len(os.Args) == 2 && os.Args[1] == "--version" {
+               fmt.Printf("wireguard-go v%s\n\nUserspace WireGuard daemon for %s-%s.\nInformation available at https://www.wireguard.com.\nCopyright (C) Jason A. Donenfeld <Jason@zx2c4.com>.\n", WireGuardGoVersion, runtime.GOOS, runtime.GOARCH)
+               return
+       }
+
        warning()
 
        // parse arguments
diff --git a/version.go b/version.go
new file mode 100644 (file)
index 0000000..25edead
--- /dev/null
@@ -0,0 +1,2 @@
+package main
+const WireGuardGoVersion = "0.0.20180519"