From 83c02560ac6b69e31fc43b3e13ed75d6c8281ba8 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 12 Jun 2019 12:25:53 -0700 Subject: [PATCH] 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.