diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e4b2644 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +.PHONY: clean build test + +MAIN_DIRECTORY := . +BIN_OUTPUT := $(if $(filter $(shell go env GOOS), windows), mikrotik-fwban.exe, mikrotik-fwban) + +TAG_NAME := $(shell git tag -l --contains HEAD) +SHA := $(shell git rev-parse HEAD) +VERSION := $(if $(TAG_NAME),$(TAG_NAME),$(SHA)) + +default: clean test build + +clean: + @echo BIN_OUTPUT: ${BIN_OUTPUT} + rm -rf ${BIN_OUTPUT} coverage.out + +build: clean + @echo Version: $(VERSION) + go build -v -trimpath -ldflags '-X "main.version=${VERSION}"' -o ${BIN_OUTPUT} ${MAIN_DIRECTORY} + +test: clean + go test -cover ./... diff --git a/go.mod b/go.mod index 379e65d..55d3c4e 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,7 @@ module github.com/middelink/mikrotik-fwban +go 1.15 + require ( github.com/google/gops v0.3.5 github.com/howeyc/fsnotify v0.9.0 @@ -9,4 +11,5 @@ require ( gopkg.in/routeros.v2 v2.0.0-20171228113335-2dc19c12445c gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.2.2 + launchpad.net/gocheck v0.0.0-20140225173054-000000000087 // indirect ) diff --git a/go.sum b/go.sum index 7337b3c..f4209e4 100644 --- a/go.sum +++ b/go.sum @@ -16,3 +16,5 @@ gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54= +launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM= diff --git a/main.go b/main.go index c055dfb..e7277d0 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,7 @@ import ( "net" "os" "os/signal" + "runtime" "strings" "syscall" "time" @@ -41,8 +42,10 @@ var ( debug = flag.Bool("debug", false, "Be absolutely staggering in our logging.") verbose = flag.Bool("verbose", false, "Be more verbose in our logging.") configchanged = flag.Bool("configchange", false, "Exit process when config file changes.") + hasVersion = flag.Bool("version", false, "output version information and exit") - cfg Config + version = "dev" + cfg Config ) func setFlags(flags ...string) error { @@ -61,6 +64,11 @@ func setFlags(flags ...string) error { func main() { setFlags() + if *hasVersion { + fmt.Fprintf(flag.CommandLine.Output(), "mikrotik-fwban version %s %s/%s\n", version, runtime.GOOS, runtime.GOARCH) + return + } + var err error cfg, err = newConfigFile(*filename, uint16(*port), Duration(*blocktime), *autodelete, *verbose) if err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index 32119de..4ffa038 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,24 +1,34 @@ # github.com/google/gops v0.3.5 +## explicit github.com/google/gops/agent github.com/google/gops/internal github.com/google/gops/signal # github.com/howeyc/fsnotify v0.9.0 +## explicit github.com/howeyc/fsnotify # github.com/jeromer/syslogparser v0.0.0-20180622150051-323c7ad120db +## explicit github.com/jeromer/syslogparser github.com/jeromer/syslogparser/rfc3164 github.com/jeromer/syslogparser/rfc5424 # github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1 +## explicit github.com/kardianos/osext # gopkg.in/gcfg.v1 v1.2.3 +## explicit gopkg.in/gcfg.v1 gopkg.in/gcfg.v1/scanner gopkg.in/gcfg.v1/token gopkg.in/gcfg.v1/types # gopkg.in/routeros.v2 v2.0.0-20171228113335-2dc19c12445c +## explicit gopkg.in/routeros.v2 gopkg.in/routeros.v2/proto # gopkg.in/warnings.v0 v0.1.2 +## explicit gopkg.in/warnings.v0 # gopkg.in/yaml.v2 v2.2.2 +## explicit gopkg.in/yaml.v2 +# launchpad.net/gocheck v0.0.0-20140225173054-000000000087 +## explicit