From df1978c9a50998e31a8ccda29bfd45600db0dc6a Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 12 Jun 2019 03:53:42 -0700 Subject: [PATCH 1/7] Add SHAs and build man page without ruby. --- integrations/inputunifi/Makefile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/integrations/inputunifi/Makefile b/integrations/inputunifi/Makefile index 9a592550..be0a866c 100644 --- a/integrations/inputunifi/Makefile +++ b/integrations/inputunifi/Makefile @@ -16,20 +16,23 @@ release: clean test $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm $(BINARY)_$(VER gzip -9 $(BINARY).macos mv $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb \ $(BINARY)-$(VERSION).pkg $(BINARY).macos.gz $(BINARY).linux.gz release/ + openssl dgst -sha256 release/* | tee release/$(BINARY)_checksums_$(VERSION)-$(ITERATION).txt # Delete all build assets. clean: # Cleaning up. rm -f $(BINARY){.macos,.linux,.1,}{,.gz} rm -f $(BINARY){_,-}*.{deb,rpm,pkg} - rm -rf package_build_* release + rm -rf package_build_* release cmd/unifi-poller/README{,.html} -# Build a man page from a markdown file using ronn. +# Build a man page from a markdown file using md2roff. man: $(BINARY).1.gz $(BINARY).1.gz: - # Building man page. - @ronn --version > /dev/null || (echo "Ronn missing. Install ronn: $(URL)/wiki/Ronn" && false) - ronn < "$(PACKAGE)/README.md" | gzip -9 > "$(BINARY).1.gz" + # Building man page. Build dependency first: md2roff + go build -o ./md2roff github.com/github/hub/md2roff-bin + ./md2roff --manual $(BINARY) --version $(VERSION) --date "$$(date)" cmd/unifi-poller/README.md + gzip -9nc cmd/unifi-poller/README > unifi-poller.1.gz + rm ./md2roff # Binaries From bb0e00a538d1e40d741324428e5101d71f45283f Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 12 Jun 2019 04:16:21 -0700 Subject: [PATCH 2/7] Build more. --- integrations/inputunifi/.gitignore | 4 +++ integrations/inputunifi/Makefile | 44 ++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/integrations/inputunifi/.gitignore b/integrations/inputunifi/.gitignore index 61d1785f..f99dc2a2 100644 --- a/integrations/inputunifi/.gitignore +++ b/integrations/inputunifi/.gitignore @@ -12,3 +12,7 @@ *~ /package_build_* /release +README +README.html +/md2roff +/unifi-poller_manual.html diff --git a/integrations/inputunifi/Makefile b/integrations/inputunifi/Makefile index be0a866c..965d618e 100644 --- a/integrations/inputunifi/Makefile +++ b/integrations/inputunifi/Makefile @@ -1,6 +1,6 @@ BINARY:=unifi-poller URL=https://github.com/davidnewhall/unifi-poller -MAINT="david at sleepers dot pro" +MAINT="David Newhall II " DESC="This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database." PACKAGE:=./cmd/$(BINARY) VERSION:=$(shell git tag -l --merged | tail -n1 | tr -d v) @@ -16,23 +16,35 @@ release: clean test $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm $(BINARY)_$(VER gzip -9 $(BINARY).macos mv $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb \ $(BINARY)-$(VERSION).pkg $(BINARY).macos.gz $(BINARY).linux.gz release/ + # Generating File Hashes openssl dgst -sha256 release/* | tee release/$(BINARY)_checksums_$(VERSION)-$(ITERATION).txt # Delete all build assets. clean: # Cleaning up. rm -f $(BINARY){.macos,.linux,.1,}{,.gz} - rm -f $(BINARY){_,-}*.{deb,rpm,pkg} + rm -f $(BINARY){_,-}*.{deb,rpm,pkg} md2roff rm -rf package_build_* release cmd/unifi-poller/README{,.html} -# Build a man page from a markdown file using md2roff. -man: $(BINARY).1.gz -$(BINARY).1.gz: - # Building man page. Build dependency first: md2roff +# md2roff is needed to build the man file and html pages from the READMEs. +md2roff: go build -o ./md2roff github.com/github/hub/md2roff-bin + +# Build a man page from a markdown file using md2roff. +# This also turns the repo readme into an html file. +man: $(BINARY).1.gz +$(BINARY).1.gz: md2roff + # Building man page. Build dependency first: md2roff ./md2roff --manual $(BINARY) --version $(VERSION) --date "$$(date)" cmd/unifi-poller/README.md - gzip -9nc cmd/unifi-poller/README > unifi-poller.1.gz - rm ./md2roff + gzip -9nc cmd/$(BINARY)/README > $(BINARY).1.gz + mv cmd/$(BINARY)/README.html ./$(BINARY)_manual.html + +# TODO: provide a template that adds the date to the built html file. +readme: README.html +README.html: md2roff + # This turns README.md into README.html + ./md2roff --manual $(BINARY) --version $(VERSION) --date "$$(date)" README.md + @rm -f README # Delete useless "man" formatted version. # Binaries @@ -99,28 +111,32 @@ $(BINARY)-$(VERSION).pkg: check_fpm package_build_osx --chdir package_build_osx # OSX packages use /usr/local because Apple doesn't allow writing many other places. -package_build_osx: man macos +package_build_osx: readme man macos # Building package environment for macOS. mkdir -p $@/usr/local/bin $@/usr/local/etc/$(BINARY) $@/Library/LaunchAgents - mkdir -p $@/usr/local/share/man/man1 $@/usr/local/share/doc/$(BINARY) $@/usr/local/var/log/unifi-poller + mkdir -p $@/usr/local/share/man/man1 $@/usr/local/share/doc/$(BINARY)/examples $@/usr/local/var/log/unifi-poller # Copying the binary, config file and man page into the env. cp $(BINARY).macos $@/usr/local/bin/$(BINARY) cp *.1.gz $@/usr/local/share/man/man1 cp examples/*.conf.example $@/usr/local/etc/$(BINARY)/ - cp examples/{*dash.json,up.conf.example} $@/usr/local/share/doc/$(BINARY)/ + cp *.html examples/{*dash.json,up.conf.example} $@/usr/local/share/doc/$(BINARY)/ + # These go to their own folder so the img src in the html pages continue to work. + cp examples/*.png $@/usr/local/share/doc/$(BINARY)/examples cp init/launchd/com.github.davidnewhall.$(BINARY).plist $@/Library/LaunchAgents/ # Build an environment that can be packaged for linux. -package_build_linux: man linux +package_build_linux: readme man linux # Building package environment for linux. mkdir -p $@/usr/bin $@/etc/$(BINARY) $@/lib/systemd/system - mkdir -p $@/usr/share/man/man1 $@/usr/share/doc/$(BINARY) + mkdir -p $@/usr/share/man/man1 $@/usr/share/doc/$(BINARY)/examples # Copying the binary, config file, unit file, and man page into the env. cp $(BINARY).linux $@/usr/bin/$(BINARY) cp *.1.gz $@/usr/share/man/man1 cp examples/*.conf.example $@/etc/$(BINARY)/ cp examples/up.conf.example $@/etc/$(BINARY)/up.conf - cp examples/{*dash.json,up.conf.example} $@/usr/share/doc/$(BINARY)/ + cp *.html examples/{*dash.json,up.conf.example} $@/usr/share/doc/$(BINARY)/ + # These go to their own folder so the img src in the html pages continue to work. + cp examples/*.png $@/usr/share/doc/$(BINARY)/examples cp init/systemd/$(BINARY).service $@/lib/systemd/system/ check_fpm: From 73fa2ab3416abccb88e6bc7ed8a7b9ffbd0eb1a3 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 12 Jun 2019 11:05:05 -0700 Subject: [PATCH 3/7] Make version/git optional --- integrations/inputunifi/Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/integrations/inputunifi/Makefile b/integrations/inputunifi/Makefile index 965d618e..1f99e583 100644 --- a/integrations/inputunifi/Makefile +++ b/integrations/inputunifi/Makefile @@ -3,8 +3,10 @@ URL=https://github.com/davidnewhall/unifi-poller MAINT="David Newhall II " DESC="This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database." PACKAGE:=./cmd/$(BINARY) -VERSION:=$(shell git tag -l --merged | tail -n1 | tr -d v) -ITERATION:=$(shell git rev-list --count HEAD) +ifeq ($(VERSION),) + VERSION:=$(shell git tag -l --merged | tail -n1 | tr -d v||echo development) +endif +ITERATION:=$(shell git rev-list --count HEAD||echo 0) all: man build From 4cc22bccb900f043d9008ba2a1983d79e136be4b Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 12 Jun 2019 11:55:07 -0700 Subject: [PATCH 4/7] Add make install back, for brew. --- integrations/inputunifi/Makefile | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/integrations/inputunifi/Makefile b/integrations/inputunifi/Makefile index 1f99e583..91d34674 100644 --- a/integrations/inputunifi/Makefile +++ b/integrations/inputunifi/Makefile @@ -30,6 +30,7 @@ clean: # md2roff is needed to build the man file and html pages from the READMEs. md2roff: + go get -u github.com/github/hub/md2roff-bin go build -o ./md2roff github.com/github/hub/md2roff-bin # Build a man page from a markdown file using md2roff. @@ -155,13 +156,24 @@ lint: golangci-lint run --enable-all -D gochecknoglobals # Deprecated. -install: - @echo - Local installation with the Makefile is no longer possible. - @echo If you wish to install the application manually, check out the wiki: \ - https://github.com/davidnewhall/unifi-poller/wiki/Installation - @echo - Otherwise, build and install a package: make rpm, make deb, make osxpkg - @echo See the Package Install wiki for more info: \ - https://github.com/davidnewhall/unifi-poller/wiki/Package-Install +install: man readme $(BINARY) + @echo - Done Building! - + @echo - Local installation with the Makefile is only supported on macOS. + @echo If you wish to install the application manually on Linux, check out the wiki: https://github.com/davidnewhall/unifi-poller/wiki/Installation + @echo - Otherwise, build and install a package: make rpm -or- make deb + @echo See the Package Install wiki for more info: https://github.com/davidnewhall/unifi-poller/wiki/Package-Install + @[ "$$(uname)" = "Darwin" ] || (echo "Unable to continue, not a Mac." && exit) + @[ "$(PREFIX)" != "" ] || (echo "Unable to continue, PREFIX not set. Use: make install PREFIX=/usr/local" && exit) + mkdir -p $(PREFIX)/bin $(PREFIX)/etc/$(BINARY) $(PREFIX)/var/log/unifi-poller + mkdir -p $(PREFIX)/share/man/man1 $(PREFIX)/share/doc/$(BINARY)/examples + # Copying the binary, config file, unit file, and man page into the env. + cp $(BINARY) $(PREFIX)/bin/$(BINARY) + cp *.1.gz $(PREFIX)/share/man/man1 + cp examples/*.conf.example $(PREFIX)/etc/$(BINARY)/ + cp examples/up.conf.example $(PREFIX)/etc/$(BINARY)/up.conf + cp *.html examples/{*dash.json,up.conf.example} $(PREFIX)/share/doc/$(BINARY)/ + # These go to their own folder so the img src in the html pages continue to work. + cp examples/*.png $(PREFIX)/share/doc/$(BINARY)/examples # If you installed with `make install` run `make uninstall` before installing a binary package. # This will remove the package install from macOS, it will not remove a package install from Linux. From 83c02560ac6b69e31fc43b3e13ed75d6c8281ba8 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 12 Jun 2019 12:25:53 -0700 Subject: [PATCH 5/7] Use install instead of cp. Add homebrew formula. --- integrations/inputunifi/.travis.yml | 2 +- .../inputunifi/Formula/unifi-poller.rb | 36 +++++++++++++++++++ integrations/inputunifi/Makefile | 19 +++++----- 3 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 integrations/inputunifi/Formula/unifi-poller.rb diff --git a/integrations/inputunifi/.travis.yml b/integrations/inputunifi/.travis.yml index 827c4edf..839da165 100644 --- a/integrations/inputunifi/.travis.yml +++ b/integrations/inputunifi/.travis.yml @@ -22,7 +22,7 @@ before_install: - curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin latest install: - dep ensure -- rvm $brew_ruby do gem install --no-document ronn fpm +- rvm $brew_ruby do gem install --no-document fpm script: - rvm $brew_ruby do make release deploy: diff --git a/integrations/inputunifi/Formula/unifi-poller.rb b/integrations/inputunifi/Formula/unifi-poller.rb new file mode 100644 index 00000000..a2b33b0c --- /dev/null +++ b/integrations/inputunifi/Formula/unifi-poller.rb @@ -0,0 +1,36 @@ +# Homebrew Formula, still under development - June 2019 +require "language/go" + +# Classname should match the name of the installed package. +class UnifiPoller < Formula + version "1.2.3" + desc "This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database." + homepage "https://github.com/davidnewhall/unifi-poller" + + # Source code archive. Each tagged release will have one + url "https://github.com/davidnewhall/unifi-poller/archive/v#{version}.tar.gz" + sha256 "d536cb767b663a1c24410b27bd7e51a2b9a78820ed1ceeb2bb61e30e27235890" + head "https://github.com/davidnewhall/unifi-poller" + + depends_on "go" => :build + depends_on "dep" + + def install + ENV["GOPATH"] = buildpath + + bin_path = buildpath/"src/github.com/davidnewhall/unifi-poller" + # Copy all files from their current location (GOPATH root) + # to $GOPATH/src/github.com/davidnewhall/unifi-poller + bin_path.install Dir["*"] + cd bin_path do + # Install the compiled binary into Homebrew's `bin` - a pre-existing + # global variable + system "dep", "ensure" + system "make", "install", "VERSION=#{version}", "PREFIX=#{prefix}" + end + end + + test do + assert_match "unifi-poller v#{version}", shell_output("#{bin}/unifi-poller -v 2>&1", 2) + end +end diff --git a/integrations/inputunifi/Makefile b/integrations/inputunifi/Makefile index 91d34674..66ee193d 100644 --- a/integrations/inputunifi/Makefile +++ b/integrations/inputunifi/Makefile @@ -162,18 +162,17 @@ install: man readme $(BINARY) @echo If you wish to install the application manually on Linux, check out the wiki: https://github.com/davidnewhall/unifi-poller/wiki/Installation @echo - Otherwise, build and install a package: make rpm -or- make deb @echo See the Package Install wiki for more info: https://github.com/davidnewhall/unifi-poller/wiki/Package-Install - @[ "$$(uname)" = "Darwin" ] || (echo "Unable to continue, not a Mac." && exit) - @[ "$(PREFIX)" != "" ] || (echo "Unable to continue, PREFIX not set. Use: make install PREFIX=/usr/local" && exit) - mkdir -p $(PREFIX)/bin $(PREFIX)/etc/$(BINARY) $(PREFIX)/var/log/unifi-poller - mkdir -p $(PREFIX)/share/man/man1 $(PREFIX)/share/doc/$(BINARY)/examples + @[ "$$(uname)" = "Darwin" ] || (echo "Unable to continue, not a Mac." && false) + @[ "$(PREFIX)" != "" ] || (echo "Unable to continue, PREFIX not set. Use: make install PREFIX=/usr/local" && false) # Copying the binary, config file, unit file, and man page into the env. - cp $(BINARY) $(PREFIX)/bin/$(BINARY) - cp *.1.gz $(PREFIX)/share/man/man1 - cp examples/*.conf.example $(PREFIX)/etc/$(BINARY)/ - cp examples/up.conf.example $(PREFIX)/etc/$(BINARY)/up.conf - cp *.html examples/{*dash.json,up.conf.example} $(PREFIX)/share/doc/$(BINARY)/ + /usr/bin/install -m 0755 -d $(PREFIX)/bin $(PREFIX)/share/man/man1 $(PREFIX)/etc/$(BINARY) $(PREFIX)/share/doc/$(BINARY)/examples + /usr/bin/install -m 0755 -cp $(BINARY) $(PREFIX)/bin/$(BINARY) + /usr/bin/install -m 0644 -cp $(BINARY).1.gz $(PREFIX)/share/man/man1 + /usr/bin/install -m 0644 -cp examples/up.conf.example $(PREFIX)/etc/$(BINARY)/ + [ -f $(PREFIX)/etc/$(BINARY)/up.conf ] || /usr/bin/install -m 0644 -cp examples/up.conf.example $(PREFIX)/etc/$(BINARY)/up.conf + /usr/bin/install -m 0644 -cp *.html examples/{*dash.json,up.conf.example} $(PREFIX)/share/doc/$(BINARY)/ # These go to their own folder so the img src in the html pages continue to work. - cp examples/*.png $(PREFIX)/share/doc/$(BINARY)/examples + /usr/bin/install -m 0644 -cp examples/*.png $(PREFIX)/share/doc/$(BINARY)/examples # If you installed with `make install` run `make uninstall` before installing a binary package. # This will remove the package install from macOS, it will not remove a package install from Linux. From ce38009ad387ecad802c07f4aa9b417036d16f82 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 12 Jun 2019 12:49:52 -0700 Subject: [PATCH 6/7] do not include generated formula file --- .../inputunifi/Formula/unifi-poller.rb | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 integrations/inputunifi/Formula/unifi-poller.rb diff --git a/integrations/inputunifi/Formula/unifi-poller.rb b/integrations/inputunifi/Formula/unifi-poller.rb deleted file mode 100644 index a2b33b0c..00000000 --- a/integrations/inputunifi/Formula/unifi-poller.rb +++ /dev/null @@ -1,36 +0,0 @@ -# Homebrew Formula, still under development - June 2019 -require "language/go" - -# Classname should match the name of the installed package. -class UnifiPoller < Formula - version "1.2.3" - desc "This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database." - homepage "https://github.com/davidnewhall/unifi-poller" - - # Source code archive. Each tagged release will have one - url "https://github.com/davidnewhall/unifi-poller/archive/v#{version}.tar.gz" - sha256 "d536cb767b663a1c24410b27bd7e51a2b9a78820ed1ceeb2bb61e30e27235890" - head "https://github.com/davidnewhall/unifi-poller" - - depends_on "go" => :build - depends_on "dep" - - def install - ENV["GOPATH"] = buildpath - - bin_path = buildpath/"src/github.com/davidnewhall/unifi-poller" - # Copy all files from their current location (GOPATH root) - # to $GOPATH/src/github.com/davidnewhall/unifi-poller - bin_path.install Dir["*"] - cd bin_path do - # Install the compiled binary into Homebrew's `bin` - a pre-existing - # global variable - system "dep", "ensure" - system "make", "install", "VERSION=#{version}", "PREFIX=#{prefix}" - end - end - - test do - assert_match "unifi-poller v#{version}", shell_output("#{bin}/unifi-poller -v 2>&1", 2) - end -end From acfbef3eda1e4c7544137067c62fa5cee9ccccb0 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 12 Jun 2019 12:59:41 -0700 Subject: [PATCH 7/7] Cleanup clean. --- integrations/inputunifi/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/integrations/inputunifi/Makefile b/integrations/inputunifi/Makefile index 66ee193d..c884c635 100644 --- a/integrations/inputunifi/Makefile +++ b/integrations/inputunifi/Makefile @@ -26,7 +26,8 @@ clean: # Cleaning up. rm -f $(BINARY){.macos,.linux,.1,}{,.gz} rm -f $(BINARY){_,-}*.{deb,rpm,pkg} md2roff - rm -rf package_build_* release cmd/unifi-poller/README{,.html} + rm -f cmd/$(BINARY)/README{,.html} README{,.html} ./$(BINARY)_manual.html + rm -rf package_build_* release # md2roff is needed to build the man file and html pages from the READMEs. md2roff: @@ -40,7 +41,7 @@ $(BINARY).1.gz: md2roff # Building man page. Build dependency first: md2roff ./md2roff --manual $(BINARY) --version $(VERSION) --date "$$(date)" cmd/unifi-poller/README.md gzip -9nc cmd/$(BINARY)/README > $(BINARY).1.gz - mv cmd/$(BINARY)/README.html ./$(BINARY)_manual.html + mv cmd/$(BINARY)/README.html $(BINARY)_manual.html # TODO: provide a template that adds the date to the built html file. readme: README.html