From a3d23a96221dc3b75b2403a9b0d6be068da7caa1 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Tue, 9 Aug 2016 10:28:31 -0400 Subject: [PATCH] Fixed tests, added Makefile instead of Python script --- Makefile | 55 ++++++++++++++++++++++++++++++++++++++++++ main.go | 12 ++++++++-- main_test.go | 2 +- makeBinaries.py | 63 ------------------------------------------------- 4 files changed, 66 insertions(+), 66 deletions(-) create mode 100644 Makefile delete mode 100755 makeBinaries.py diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2a3c480 --- /dev/null +++ b/Makefile @@ -0,0 +1,55 @@ +SOURCEDIR=. +SOURCES := $(shell find $(SOURCEDIR) -name '*.go') + +BINARY=findclient + +VERSION=0.5 +BUILD_TIME=`date +%FT%T%z` +BUILD=`git rev-parse HEAD` + +LDFLAGS=-ldflags "-X main.VersionNum=${VERSION} -X main.Build=${BUILD} -X main.BuildTime=${BUILD_TIME}" + +.DEFAULT_GOAL: $(BINARY) + +$(BINARY): $(SOURCES) + go get github.com/stretchr/testify/assert + go get github.com/codegangsta/cli + go get github.com/op/go-logging + go build ${LDFLAGS} -o ${BINARY} ${SOURCES} + +.PHONY: install +install: + go install ${LDFLAGS} ./... + +.PHONY: clean +clean: + if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi + rm -rf builds + rm -rf find + rm -rf findclient* + +.PHONY: binaries +binaries: + go test + rm -rf builds + mkdir builds + # Build Windows + env GOOS=windows GOARCH=amd64 go build ${LDFLAGS} -o findclient.exe -v *.go + zip -r findclient_${VERSION}_windows_amd64.zip findclient.exe LICENSE + mv findclient_${VERSION}_windows_amd64.zip builds/ + rm findclient.exe + # Build Linux + env GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o findclient -v *.go + zip -r findclient_${VERSION}_linux_amd64.zip findclient LICENSE + mv findclient_${VERSION}_linux_amd64.zip builds/ + rm findclient + # Build OS X + env GOOS=darwin GOARCH=amd64 go build ${LDFLAGS} -o findclient -v *.go + zip -r findclient_${VERSION}_osx.zip findclient LICENSE + mv findclient_${VERSION}_osx.zip builds/ + rm findclient + # Build Raspberry Pi / Chromebook + env GOOS=linux GOARCH=arm go build ${LDFLAGS} -o findclient -v *.go + zip -r findclient_${VERSION}_linux_arm.zip findclient LICENSE + mv findclient_${VERSION}_linux_arm.zip builds/ + rm findclient diff --git a/main.go b/main.go index d6ea1f9..e8ec8e4 100644 --- a/main.go +++ b/main.go @@ -89,6 +89,10 @@ func setupLogging() { } } +var VersionNum string +var Build string +var BuildTime string + func main() { var f Fingerprint var times int @@ -96,10 +100,14 @@ func main() { var wlan_interface string var osConfig OSConfig + if len(Build) == 0 { + Build = "devdevdevdevdevdev" + } + app := cli.NewApp() - app.Name = "fingerprint" + app.Name = "findclient" app.Usage = "client for sending WiFi fingerprints to a FIND server" - app.Version = "0.2" + app.Version = VersionNum + " " + Build[0:7] app.Flags = []cli.Flag{ cli.StringFlag{ Name: "server,s", diff --git a/main_test.go b/main_test.go index 902628a..7a01e1a 100644 --- a/main_test.go +++ b/main_test.go @@ -32,7 +32,7 @@ func ExampleSendFingerprintServerOnlineTrack() { fmt.Println(err) } fmt.Println(response) - // Output: Calculated location: zakhome floor 2 office + // Output: Current location: zakhome floor 2 office } func ExampleSendFingerprintServerOffline() { diff --git a/makeBinaries.py b/makeBinaries.py deleted file mode 100755 index 28f7b3d..0000000 --- a/makeBinaries.py +++ /dev/null @@ -1,63 +0,0 @@ -import os - -"""DEFUNCT -darwin arm -darwin arm64 -dragonfly amd64 -freebsd 386 -freebsd amd64 -freebsd arm -linux 386 -linux arm64 -linux ppc64le -netbsd 386 -netbsd amd64 -netbsd arm -openbsd 386 -openbsd amd64 -openbsd arm -plan9 386 -plan9 amd64 -solaris amd64 -windows 386 -darwin 386 -darwin amd64 -linux arm -linux ppc64 -windows amd64""" - -arches = """linux amd64 -linux arm -windows amd64 -darwin amd64""" - -arches = arches.split("\n") -version = "0.4" -try: - os.system("rm -rf builds") -except: - pass - -try: - os.mkdir("builds") -except: - pass - -for arch in arches: - goos = arch.split()[0] - goarch = arch.split()[1] - - exe = "" - if "windows" in goos: - exe = ".exe" - cmd1 = 'env GOOS=%(goos)s GOARCH=%(goarch)s go build -o builds/fingerprint%(exe)s -v *.go' % {'goos':goos,'goarch':goarch,'exe':exe,'version':version} - cmd2 = 'zip fingerprint-%(version)s-%(goos)s-%(goarch)s.zip ../LICENSE ../README.md fingerprint%(exe)s' % {'goos':goos,'goarch':goarch,'exe':exe,'version':version} - print(cmd1) - os.system(cmd1) - os.chdir("builds") - print(cmd2) - os.system(cmd2) - cmd3 = 'rm fingerprint%(exe)s' % {'goos':goos,'goarch':goarch,'exe':exe,'version':version} - print(cmd3) - os.system(cmd3) - os.chdir("../")