Update application builder

This commit is contained in:
David Newhall II 2021-03-15 00:41:09 -07:00
parent b0044155f5
commit d897916345
21 changed files with 330 additions and 242 deletions

48
.gitignore vendored
View File

@ -1,18 +1,23 @@
/up.conf # Change this line.
/unifi-poller /unifi-poller
/unifi-poller*.gz /init/macos/*.app/Contents/MacOS/*
/unifi-poller*.txz # The rest is probably fine.
/unifi-poller*.zip /rsrc*.syso
/unifi-poller*.1 /*.log
/unifi-poller*.deb /*.conf
/unifi-poller*.rpm /*.gz
/unifi-poller*.arm /*.zip
/unifi-poller*.exe /*.upx
/unifi-poller*.macos /unpackerr*.1
/unifi-poller*.freebsd /*.deb
/unifi-poller*.bsd /*.rpm
/unifi-poller*.linux /*.txz
/unifi-poller.rb /*.*.arm
/*.*.exe
/*.*.macos
/*.*.linux
/*.*.freebsd
/*.rb
*.sha256 *.sha256
/vendor /vendor
.DS_Store .DS_Store
@ -23,11 +28,10 @@ MANUAL
MANUAL.html MANUAL.html
README README
README.html README.html
/unifi-poller_manual.html /*_manual.html
/homebrew_release_repo /homebrew-mugs
/.metadata.make .secret*files.tar
bitly_token github_deploy_key*
github_deploy_key .metadata.make
gpg.signing.key /after-install-rendered.sh
.secret-files.tar /before-remove-rendered.sh
*.so

View File

@ -15,13 +15,14 @@ addons:
- debsigs - debsigs
- gnupg - gnupg
- expect - expect
- upx
go: go:
- 1.14.x - 1.15.x
services: services:
- docker - docker
install: install:
- rvm install 2.3.0 - rvm install 2.6.0
- rvm 2.3.0 do gem install --no-document fpm - rvm 2.6.0 do gem install --no-document fpm
# download super-linter: golangci-lint # download super-linter: golangci-lint
# - curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin latest # - curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin latest
before_script: before_script:
@ -31,15 +32,15 @@ before_script:
- tar -xf .secret-files.tar - tar -xf .secret-files.tar
- gpg --import gpg.signing.key - gpg --import gpg.signing.key
- rm -f gpg.signing.key .secret-files.tar - rm -f gpg.signing.key .secret-files.tar
- source .metadata.sh - source settings.sh
script: script:
# Test Go and Docker. # Test Go and Docker.
# - make test # - make test
- make docker - make docker
# Test built docker image. # Test built docker image.
- docker run $BINARY -v 2>&1 | grep -Eq "^$BINARY v$VERSION" - docker run $BINARY -v 2>&1 | grep -Eq "^$BINARY, version $VERSION"
# Build everything # Build everything
- rvm 2.3.0 do make release - rvm 2.6.0 do make release
after_success: after_success:
# Display Release Folder # Display Release Folder
- ls -l release/ - ls -l release/

253
Makefile
View File

@ -1,12 +1,18 @@
# This Makefile is written as generic as possible. # This Makefile is written as generic as possible.
# Setting the variables in .metadata.sh and creating the paths in the repo makes this work. # Setting the variables in settings.sh and creating the paths in the repo makes this work.
# See more: https://github.com/golift/application-builder # See more: https://github.com/golift/application-builder
# Suck in our application information. # Suck in our application information.
IGNORED:=$(shell bash -c "source .metadata.sh ; env | sed 's/=/:=/;s/^/export /' > .metadata.make") IGNORED:=$(shell bash -c "source settings.sh ; env | grep -v BASH_FUNC | sed 's/=/:=/;s/^/export /' > .metadata.make")
# md2roff turns markdown into man files and html files. # md2roff turns markdown into man files and html files.
MD2ROFF_BIN=github.com/github/hub/md2roff-bin MD2ROFF_BIN=github.com/davidnewhall/md2roff
# rsrc adds an ico file to a Windows exe file.
RSRC_BIN=github.com/akavel/rsrc
# If upx is available, use it to compress the binaries.
UPXPATH=$(shell which upx)
# Travis CI passes the version in. Local builds get it from the current git tag. # Travis CI passes the version in. Local builds get it from the current git tag.
ifeq ($(VERSION),) ifeq ($(VERSION),)
@ -20,13 +26,15 @@ else
ITERATION:=$(_ITERATION) ITERATION:=$(_ITERATION)
endif endif
# rpm is wierd and changes - to _ in versions. # rpm is wierd and changes - to _ in versions.
RPMVERSION:=$(shell echo $(VERSION) | tr -- - _) RPMVERSION:=$(shell echo $(VERSION) | tr -- - _)
# used for freebsd packages.
BINARYU:=$(shell echo $(BINARY) | tr -- - _) BINARYU:=$(shell echo $(BINARY) | tr -- - _)
PACKAGE_SCRIPTS= PACKAGE_SCRIPTS=
ifeq ($(FORMULA),service) ifeq ($(FORMULA),service)
PACKAGE_SCRIPTS=--after-install scripts/after-install.sh --before-remove scripts/before-remove.sh PACKAGE_SCRIPTS=--after-install after-install-rendered.sh --before-remove before-remove-rendered.sh
endif endif
define PACKAGE_ARGS define PACKAGE_ARGS
@ -36,118 +44,159 @@ $(PACKAGE_SCRIPTS) \
--rpm-os linux \ --rpm-os linux \
--iteration $(ITERATION) \ --iteration $(ITERATION) \
--license $(LICENSE) \ --license $(LICENSE) \
--url $(URL) \ --url $(SOURCE_URL) \
--maintainer "$(MAINT)" \ --maintainer "$(MAINT)" \
--vendor "$(VENDOR)" \ --vendor "$(VENDOR)" \
--description "$(DESC)" \ --description "$(DESC)" \
--config-files "/etc/$(BINARY)/$(CONFIG_FILE)" \ --config-files "/etc/$(BINARY)/$(CONFIG_FILE)" \
--freebsd-origin "$(BINARY)/$(BINARY)" --freebsd-origin "$(SOURCE_URL)"
endef endef
PLUGINS:=$(patsubst plugins/%/main.go,%,$(wildcard plugins/*/main.go)) PLUGINS:=$(patsubst plugins/%/main.go,%,$(wildcard plugins/*/main.go))
VERSION_LDFLAGS:= \ VERSION_LDFLAGS:= -X \"$(VERSION_PATH).Branch=$(BRANCH) ($(COMMIT))\" \
-X github.com/prometheus/common/version.Branch=$(BRANCH) \ -X \"$(VERSION_PATH).BuildDate=$(DATE)\" \
-X github.com/prometheus/common/version.BuildDate=$(DATE) \ -X \"$(VERSION_PATH).BuildUser=$(shell whoami)\" \
-X github.com/prometheus/common/version.Revision=$(COMMIT) \ -X \"$(VERSION_PATH).Revision=$(ITERATION)\" \
-X github.com/prometheus/common/version.Version=$(VERSION)-$(ITERATION) -X \"$(VERSION_PATH).Version=$(VERSION)\"
# Makefile targets follow. # Makefile targets follow.
all: clean build all: clean build
####################
##### Releases #####
####################
# Prepare a release. Called in Travis CI. # Prepare a release. Called in Travis CI.
release: clean macos windows linux_packages freebsd_packages release: clean linux_packages freebsd_packages windows
# Prepareing a release! # Prepareing a release!
mkdir -p $@ mkdir -p $@
mv $(BINARY).*.macos $(BINARY).*.linux $(BINARY).*.freebsd $@/ mv $(BINARY).*.linux $(BINARY).*.freebsd $@/
gzip -9r $@/ gzip -9r $@/
for i in $(BINARY)*.exe; do zip -9qm $@/$$i.zip $$i;done for i in $(BINARY)*.exe ; do zip -9qj $@/$$i.zip $$i examples/*.example *.html; rm -f $$i;done
mv *.rpm *.deb *.txz $@/ mv *.rpm *.deb *.txz $@/
# Generating File Hashes # Generating File Hashes
openssl dgst -r -sha256 $@/* | sed 's#release/##' | tee $@/checksums.sha256.txt openssl dgst -r -sha256 $@/* | sed 's#release/##' | tee $@/checksums.sha256.txt
dmg: clean macapp
mkdir -p release
hdiutil create release/$(MACAPP).dmg -srcfolder $(MACAPP).app -ov
openssl dgst -r -sha256 release/* | sed 's#release/##' | tee release/dmg_checksum.sha256.txt
# Delete all build assets. # Delete all build assets.
clean: clean:
# Cleaning up. rm -f $(BINARY) $(BINARY).*.{macos,freebsd,linux,exe,upx}{,.gz,.zip} $(BINARY).1{,.gz} $(BINARY).rb
rm -f $(BINARY) $(BINARY).*.{macos,freebsd,linux,exe}{,.gz,.zip} $(BINARY).1{,.gz} $(BINARY).rb
rm -f $(BINARY){_,-}*.{deb,rpm,txz} v*.tar.gz.sha256 examples/MANUAL .metadata.make rm -f $(BINARY){_,-}*.{deb,rpm,txz} v*.tar.gz.sha256 examples/MANUAL .metadata.make
rm -f cmd/$(BINARY)/README{,.html} README{,.html} ./$(BINARY)_manual.html rm -f cmd/$(BINARY)/README{,.html} README{,.html} ./$(BINARY)_manual.html rsrc.syso $(MACAPP).app.zip
rm -rf package_build_* release rm -rf package_build_* release after-install-rendered.sh before-remove-rendered.sh $(MACAPP).app
####################
##### Sidecars #####
####################
# Build a man page from a markdown file using md2roff. # Build a man page from a markdown file using md2roff.
# This also turns the repo readme into an html file. # This also turns the repo readme into an html file.
# md2roff is needed to build the man file and html pages from the READMEs. # md2roff is needed to build the man file and html pages from the READMEs.
man: $(BINARY).1.gz man: $(BINARY).1.gz
$(BINARY).1.gz: $(BINARY).1.gz: md2roff
# Building man page. Build dependency first: md2roff # Building man page. Build dependency first: md2roff
go run $(MD2ROFF_BIN) --manual $(BINARY) --version $(VERSION) --date "$(DATE)" examples/MANUAL.md $(shell go env GOPATH)/bin/md2roff --manual $(BINARY) --version $(VERSION) --date "$(DATE)" examples/MANUAL.md
gzip -9nc examples/MANUAL > $@ gzip -9nc examples/MANUAL > $@
mv examples/MANUAL.html $(BINARY)_manual.html mv examples/MANUAL.html $(BINARY)_manual.html
md2roff: $(shell go env GOPATH)/bin/md2roff
$(shell go env GOPATH)/bin/md2roff:
cd /tmp ; go get $(MD2ROFF_BIN) ; go install $(MD2ROFF_BIN)
# TODO: provide a template that adds the date to the built html file. # TODO: provide a template that adds the date to the built html file.
readme: README.html readme: README.html
README.html: README.html: md2roff
# This turns README.md into README.html # This turns README.md into README.html
go run $(MD2ROFF_BIN) --manual $(BINARY) --version $(VERSION) --date "$(DATE)" README.md $(shell go env GOPATH)/bin/md2roff --manual $(BINARY) --version $(VERSION) --date "$(DATE)" README.md
# Binaries rsrc: rsrc.syso
rsrc.syso: init/windows/application.ico init/windows/manifest.xml $(shell go env GOPATH)/bin/rsrc
$(shell go env GOPATH)/bin/rsrc -ico init/windows/application.ico -manifest init/windows/manifest.xml
$(shell go env GOPATH)/bin/rsrc:
cd /tmp ; go get $(RSRC_BIN) ; go install $(RSRC_BIN)
####################
##### Binaries #####
####################
build: $(BINARY) build: $(BINARY)
$(BINARY): main.go $(BINARY): main.go
go build -o $(BINARY) -ldflags "-w -s $(VERSION_LDFLAGS)" go build -o $(BINARY) -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@
linux: $(BINARY).amd64.linux linux: $(BINARY).amd64.linux
$(BINARY).amd64.linux: main.go $(BINARY).amd64.linux: main.go
# Building linux 64-bit x86 binary. # Building linux 64-bit x86 binary.
GOOS=linux GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)" GOOS=linux GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@
linux386: $(BINARY).i386.linux linux386: $(BINARY).i386.linux
$(BINARY).i386.linux: main.go $(BINARY).i386.linux: main.go
# Building linux 32-bit x86 binary. # Building linux 32-bit x86 binary.
GOOS=linux GOARCH=386 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)" GOOS=linux GOARCH=386 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@
arm: arm64 armhf arm: arm64 armhf
arm64: $(BINARY).arm64.linux arm64: $(BINARY).arm64.linux
$(BINARY).arm64.linux: main.go $(BINARY).arm64.linux: main.go
# Building linux 64-bit ARM binary. # Building linux 64-bit ARM binary.
GOOS=linux GOARCH=arm64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)" GOOS=linux GOARCH=arm64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@
armhf: $(BINARY).armhf.linux armhf: $(BINARY).armhf.linux
$(BINARY).armhf.linux: main.go $(BINARY).armhf.linux: main.go
# Building linux 32-bit ARM binary. # Building linux 32-bit ARM binary.
GOOS=linux GOARCH=arm GOARM=6 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)" GOOS=linux GOARCH=arm GOARM=6 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@
macos: $(BINARY).amd64.macos macos: $(BINARY).amd64.macos
$(BINARY).amd64.macos: main.go $(BINARY).amd64.macos: main.go
GOOS=darwin GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)" # Building darwin 64-bit x86 binary.
GOOS=darwin GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@
freebsd: $(BINARY).amd64.freebsd freebsd: $(BINARY).amd64.freebsd
$(BINARY).amd64.freebsd: main.go $(BINARY).amd64.freebsd: main.go
GOOS=freebsd GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)" GOOS=freebsd GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
freebsd386: $(BINARY).i386.freebsd freebsd386: $(BINARY).i386.freebsd
$(BINARY).i386.freebsd: main.go $(BINARY).i386.freebsd: main.go
GOOS=freebsd GOARCH=386 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)" GOOS=freebsd GOARCH=386 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@ || true
freebsdarm: $(BINARY).armhf.freebsd freebsdarm: $(BINARY).armhf.freebsd
$(BINARY).armhf.freebsd: main.go $(BINARY).armhf.freebsd: main.go
GOOS=freebsd GOARCH=arm go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)" GOOS=freebsd GOARCH=arm go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
exe: $(BINARY).amd64.exe exe: $(BINARY).amd64.exe
windows: $(BINARY).amd64.exe windows: $(BINARY).amd64.exe
$(BINARY).amd64.exe: main.go $(BINARY).amd64.exe: rsrc.syso main.go
# Building windows 64-bit x86 binary. # Building windows 64-bit x86 binary.
GOOS=windows GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)" GOOS=windows GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) $(WINDOWS_LDFLAGS)"
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@
# Packages ####################
##### Packages #####
####################
linux_packages: rpm deb rpm386 deb386 debarm rpmarm debarmhf rpmarmhf linux_packages: rpm deb rpm386 deb386 debarm rpmarm debarmhf rpmarmhf
freebsd_packages: freebsd_pkg freebsd386_pkg freebsdarm_pkg freebsd_packages: freebsd_pkg freebsd386_pkg freebsdarm_pkg
macapp: $(MACAPP).app
$(MACAPP).app: macos
@[ "$(MACAPP)" != "" ] || (echo "Must set 'MACAPP' in settings.sh!" && exit 1)
mkdir -p init/macos/$(MACAPP).app/Contents/MacOS
cp $(BINARY).amd64.macos init/macos/$(MACAPP).app/Contents/MacOS/$(MACAPP)
cp -rp init/macos/$(MACAPP).app $(MACAPP).app
rpm: $(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm rpm: $(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm
$(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm: package_build_linux check_fpm $(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm: package_build_linux check_fpm
@echo "Building 'rpm' package for $(BINARY) version '$(RPMVERSION)-$(ITERATION)'." @echo "Building 'rpm' package for $(BINARY) version '$(RPMVERSION)-$(ITERATION)'."
@ -212,13 +261,12 @@ $(BINARY)-$(VERSION)_$(ITERATION).armhf.txz: package_build_freebsd_arm check_fpm
fpm -s dir -t freebsd $(PACKAGE_ARGS) -a arm -v $(VERSION) -p $(BINARY)-$(VERSION)_$(ITERATION).armhf.txz -C $< fpm -s dir -t freebsd $(PACKAGE_ARGS) -a arm -v $(VERSION) -p $(BINARY)-$(VERSION)_$(ITERATION).armhf.txz -C $<
# Build an environment that can be packaged for linux. # Build an environment that can be packaged for linux.
package_build_linux: readme man plugins_linux_amd64 linux package_build_linux: readme man plugins_linux_amd64 after-install-rendered.sh before-remove-rendered.sh linux
# Building package environment for linux. # Building package environment for linux.
mkdir -p $@/usr/bin $@/etc/$(BINARY) $@/usr/share/man/man1 $@/usr/share/doc/$(BINARY) $@/usr/lib/$(BINARY)/web mkdir -p $@/usr/bin $@/etc/$(BINARY) $@/usr/share/man/man1 $@/usr/share/doc/$(BINARY) $@/usr/lib/$(BINARY)
# Copying the binary, config file, unit file, and man page into the env. # Copying the binary, config file, unit file, and man page into the env.
cp $(BINARY).amd64.linux $@/usr/bin/$(BINARY) cp $(BINARY).amd64.linux $@/usr/bin/$(BINARY)
cp *.1.gz $@/usr/share/man/man1 cp *.1.gz $@/usr/share/man/man1
cp -r init/webserver/* $@/usr/lib/$(BINARY)/web/
rm -f $@/usr/lib/$(BINARY)/*.so rm -f $@/usr/lib/$(BINARY)/*.so
[ ! -f *amd64.so ] || cp *amd64.so $@/usr/lib/$(BINARY)/ [ ! -f *amd64.so ] || cp *amd64.so $@/usr/lib/$(BINARY)/
cp examples/$(CONFIG_FILE).example $@/etc/$(BINARY)/ cp examples/$(CONFIG_FILE).example $@/etc/$(BINARY)/
@ -229,6 +277,12 @@ package_build_linux: readme man plugins_linux_amd64 linux
sed -e "s/{{BINARY}}/$(BINARY)/g" -e "s/{{DESC}}/$(DESC)/g" \ sed -e "s/{{BINARY}}/$(BINARY)/g" -e "s/{{DESC}}/$(DESC)/g" \
init/systemd/template.unit.service > $@/lib/systemd/system/$(BINARY).service init/systemd/template.unit.service > $@/lib/systemd/system/$(BINARY).service
after-install-rendered.sh:
sed -e "s/{{BINARY}}/$(BINARY)/g" scripts/after-install.sh > after-install-rendered.sh
before-remove-rendered.sh:
sed -e "s/{{BINARY}}/$(BINARY)/g" scripts/before-remove.sh > before-remove-rendered.sh
package_build_linux_386: package_build_linux linux386 package_build_linux_386: package_build_linux linux386
mkdir -p $@ mkdir -p $@
cp -r $</* $@/ cp -r $</* $@/
@ -248,11 +302,10 @@ package_build_linux_armhf: package_build_linux armhf
cp $(BINARY).armhf.linux $@/usr/bin/$(BINARY) cp $(BINARY).armhf.linux $@/usr/bin/$(BINARY)
# Build an environment that can be packaged for freebsd. # Build an environment that can be packaged for freebsd.
package_build_freebsd: readme man freebsd package_build_freebsd: readme man after-install-rendered.sh before-remove-rendered.sh freebsd
mkdir -p $@/usr/local/bin $@/usr/local/etc/$(BINARY) $@/usr/local/share/man/man1 $@/usr/local/share/doc/$(BINARY) $@/usr/local/lib/$(BINARY)/web mkdir -p $@/usr/local/bin $@/usr/local/etc/$(BINARY) $@/usr/local/share/man/man1 $@/usr/local/share/doc/$(BINARY)
cp $(BINARY).amd64.freebsd $@/usr/local/bin/$(BINARY) cp $(BINARY).amd64.freebsd $@/usr/local/bin/$(BINARY)
cp *.1.gz $@/usr/local/share/man/man1 cp *.1.gz $@/usr/local/share/man/man1
cp -r init/webserver/* $@/usr/local/lib/$(BINARY)/web/
cp examples/$(CONFIG_FILE).example $@/usr/local/etc/$(BINARY)/ cp examples/$(CONFIG_FILE).example $@/usr/local/etc/$(BINARY)/
cp examples/$(CONFIG_FILE).example $@/usr/local/etc/$(BINARY)/$(CONFIG_FILE) cp examples/$(CONFIG_FILE).example $@/usr/local/etc/$(BINARY)/$(CONFIG_FILE)
cp LICENSE *.html examples/*?.?* $@/usr/local/share/doc/$(BINARY)/ cp LICENSE *.html examples/*?.?* $@/usr/local/share/doc/$(BINARY)/
@ -275,41 +328,9 @@ package_build_freebsd_arm: package_build_freebsd freebsdarm
check_fpm: check_fpm:
@fpm --version > /dev/null || (echo "FPM missing. Install FPM: https://fpm.readthedocs.io/en/latest/installing.html" && false) @fpm --version > /dev/null || (echo "FPM missing. Install FPM: https://fpm.readthedocs.io/en/latest/installing.html" && false)
docker: ##################
docker build -f init/docker/Dockerfile \ ##### Extras #####
--build-arg "BUILD_DATE=$(DATE)" \ ##################
--build-arg "COMMIT=$(COMMIT)" \
--build-arg "VERSION=$(VERSION)-$(ITERATION)" \
--build-arg "LICENSE=$(LICENSE)" \
--build-arg "DESC=$(DESC)" \
--build-arg "URL=$(URL)" \
--build-arg "VENDOR=$(VENDOR)" \
--build-arg "AUTHOR=$(MAINT)" \
--build-arg "BINARY=$(BINARY)" \
--build-arg "SOURCE_URL=$(SOURCE_URL)" \
--build-arg "CONFIG_FILE=$(CONFIG_FILE)" \
--tag $(BINARY) .
# This builds a Homebrew formula file that can be used to install this app from source.
# The source used comes from the released version on GitHub. This will not work with local source.
# This target is used by Travis CI to update the released Forumla when a new tag is created.
formula: $(BINARY).rb
v$(VERSION).tar.gz.sha256:
# Calculate the SHA from the Github source file.
curl -sL $(URL)/archive/v$(VERSION).tar.gz | openssl dgst -r -sha256 | tee $@
$(BINARY).rb: v$(VERSION).tar.gz.sha256 init/homebrew/$(FORMULA).rb.tmpl
# Creating formula from template using sed.
sed -e "s/{{Version}}/$(VERSION)/g" \
-e "s/{{Iter}}/$(ITERATION)/g" \
-e "s/{{SHA256}}/$(shell head -c64 $<)/g" \
-e "s/{{Desc}}/$(DESC)/g" \
-e "s%{{URL}}%$(URL)%g" \
-e "s%{{SOURCE_PATH}}%$(SOURCE_PATH)%g" \
-e "s%{{SOURCE_URL}}%$(SOURCE_URL)%g" \
-e "s%{{CONFIG_FILE}}%$(CONFIG_FILE)%g" \
-e "s%{{Class}}%$(shell echo $(BINARY) | perl -pe 's/(?:\b|-)(\p{Ll})/\u$$1/g')%g" \
init/homebrew/$(FORMULA).rb.tmpl | tee $(BINARY).rb
# That perl line turns hello-world into HelloWorld, etc.
plugins: $(patsubst %,%.so,$(PLUGINS)) plugins: $(patsubst %,%.so,$(PLUGINS))
$(patsubst %,%.so,$(PLUGINS)): $(patsubst %,%.so,$(PLUGINS)):
@ -324,44 +345,84 @@ plugins_darwin: $(patsubst %,%.darwin.so,$(PLUGINS))
$(patsubst %,%.darwin.so,$(PLUGINS)): $(patsubst %,%.darwin.so,$(PLUGINS)):
GOOS=darwin go build -o $@ -ldflags "$(VERSION_LDFLAGS)" -buildmode=plugin ./plugins/$(patsubst %.darwin.so,%,$@) GOOS=darwin go build -o $@ -ldflags "$(VERSION_LDFLAGS)" -buildmode=plugin ./plugins/$(patsubst %.darwin.so,%,$@)
# Extras
# Run code tests and lint. # Run code tests and lint.
test: test: lint
# Testing. # Testing.
go test -race -covermode=atomic ./... go test -race -covermode=atomic ./...
lint:
# Checking lint. # Checking lint.
golangci-lint run $(GOLANGCI_LINT_ARGS) GOOS=linux $(shell go env GOPATH)/bin/golangci-lint run $(GOLANGCI_LINT_ARGS)
GOOS=freebsd $(shell go env GOPATH)/bin/golangci-lint run $(GOLANGCI_LINT_ARGS)
GOOS=windows $(shell go env GOPATH)/bin/golangci-lint run $(GOLANGCI_LINT_ARGS)
# Mockgen and bindata are examples.
# Your `go generate` may require other tools; add them!
# Don't run this unless you're ready to debug untested vendored dependencies. mockgen: $(shell go env GOPATH)/bin/mockgen
deps: $(shell go env GOPATH)/bin/mockgen:
go get -u github.com/unifi-poller/unifi cd /tmp ; go get github.com/golang/mock/mockgen ; go install github.com/golang/mock/mockgen
go get -u github.com/unifi-poller/influxunifi
go get -u github.com/unifi-poller/promunifi
go get -u github.com/unifi-poller/lokiunifi
go get -u github.com/unifi-poller/webserver
go get -u github.com/unifi-poller/inputunifi
go get -u github.com/unifi-poller/poller
bindata: $(shell go env GOPATH)/bin/go-bindata
$(shell go env GOPATH)/bin/go-bindata:
cd /tmp ; go get -u github.com/go-bindata/go-bindata/... ; go install github.com/go-bindata/go-bindata
# Homebrew stuff. macOS only. generate: mockgen bindata
go generate ./...
##################
##### Docker #####
##################
docker:
docker build -f init/docker/Dockerfile \
--build-arg "BUILD_DATE=$(DATE)" \
--build-arg "COMMIT=$(COMMIT)" \
--build-arg "VERSION=$(VERSION)-$(ITERATION)" \
--build-arg "LICENSE=$(LICENSE)" \
--build-arg "DESC=$(DESC)" \
--build-arg "VENDOR=$(VENDOR)" \
--build-arg "AUTHOR=$(MAINT)" \
--build-arg "BINARY=$(BINARY)" \
--build-arg "SOURCE_URL=$(SOURCE_URL)" \
--build-arg "CONFIG_FILE=$(CONFIG_FILE)" \
--tag $(BINARY) .
####################
##### Homebrew #####
####################
# This builds a Homebrew formula file that can be used to install this app from source.
# The source used comes from the released version on GitHub. This will not work with local source.
# This target is used by Travis CI to update the released Forumla when a new tag is created.
formula: $(BINARY).rb
v$(VERSION).tar.gz.sha256:
# Calculate the SHA from the Github source file.
curl -sL $(SOURCE_URL)/archive/v$(VERSION).tar.gz | openssl dgst -r -sha256 | tee $@
$(BINARY).rb: v$(VERSION).tar.gz.sha256 init/homebrew/$(FORMULA).rb.tmpl
# Creating formula from template using sed.
sed -e "s/{{Version}}/$(VERSION)/g" \
-e "s/{{Iter}}/$(ITERATION)/g" \
-e "s/{{SHA256}}/$(shell head -c64 $<)/g" \
-e "s/{{Desc}}/$(DESC)/g" \
-e "s%{{SOURCE_URL}}%$(SOURCE_URL)%g" \
-e "s%{{SOURCE_PATH}}%$(SOURCE_PATH)%g" \
-e "s%{{CONFIG_FILE}}%$(CONFIG_FILE)%g" \
-e "s%{{Class}}%$(shell echo $(BINARY) | perl -pe 's/(?:\b|-)(\p{Ll})/\u$$1/g')%g" \
init/homebrew/$(FORMULA).rb.tmpl | tee $(BINARY).rb
# That perl line turns hello-world into HelloWorld, etc.
# Used for Homebrew only. Other distros can create packages. # Used for Homebrew only. Other distros can create packages.
install: man readme $(BINARY) plugins_darwin install: man readme $(BINARY) plugins_darwin
@echo - Done Building! - @echo - Done Building -
@echo - Local installation with the Makefile is only supported on macOS. @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://$(SOURCE_URL)/wiki/Installation
@echo - Otherwise, build and install a package: make rpm -or- make deb @echo - Otherwise, build and install a package: make rpm -or- make deb
@echo See the Package Install wiki for more info: https://$(SOURCE_URL)/wiki/Package-Install
@[ "$(shell uname)" = "Darwin" ] || (echo "Unable to continue, not a Mac." && false) @[ "$(shell uname)" = "Darwin" ] || (echo "Unable to continue, not a Mac." && false)
@[ "$(PREFIX)" != "" ] || (echo "Unable to continue, PREFIX not set. Use: make install PREFIX=/usr/local ETC=/usr/local/etc" && false) @[ "$(PREFIX)" != "" ] || (echo "Unable to continue, PREFIX not set. Use: make install PREFIX=/usr/local ETC=/usr/local/etc" && false)
@[ "$(ETC)" != "" ] || (echo "Unable to continue, ETC not set. Use: make install PREFIX=/usr/local ETC=/usr/local/etc" && false) @[ "$(ETC)" != "" ] || (echo "Unable to continue, ETC not set. Use: make install PREFIX=/usr/local ETC=/usr/local/etc" && false)
# Copying the binary, config file, unit file, and man page into the env. # Copying the binary, config file, unit file, and man page into the env.
/usr/bin/install -m 0755 -d $(PREFIX)/bin $(PREFIX)/share/man/man1 $(ETC)/$(BINARY) $(PREFIX)/share/doc/$(BINARY) $(PREFIX)/lib/$(BINARY)/web /usr/bin/install -m 0755 -d $(PREFIX)/bin $(PREFIX)/share/man/man1 $(ETC)/$(BINARY) $(PREFIX)/share/doc/$(BINARY) $(PREFIX)/lib/$(BINARY)
/usr/bin/install -m 0755 -cp $(BINARY) $(PREFIX)/bin/$(BINARY) /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 $(BINARY).1.gz $(PREFIX)/share/man/man1
/usr/bin/install -m 0644 -cp examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/ /usr/bin/install -m 0644 -cp examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/
/usr/bin/install -m 0644 -cp init/webserver/* $(PREFIX)/lib/$(BINARY)/web/
[ -f $(ETC)/$(BINARY)/$(CONFIG_FILE) ] || /usr/bin/install -m 0644 -cp examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/$(CONFIG_FILE) [ -f $(ETC)/$(BINARY)/$(CONFIG_FILE) ] || /usr/bin/install -m 0644 -cp examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/$(CONFIG_FILE)
/usr/bin/install -m 0644 -cp LICENSE *.html examples/* $(PREFIX)/share/doc/$(BINARY)/ /usr/bin/install -m 0644 -cp LICENSE *.html examples/* $(PREFIX)/share/doc/$(BINARY)/

View File

@ -117,7 +117,7 @@
# Password for UniFi controller user (above). # Password for UniFi controller user (above).
# If the password provided here begins with file:// then the password is read in from # If the password provided here begins with file:// then the password is read in from
# the file path that follows the file:// prefix. ex: file:///etc/unifi/password.file # the file path that follows the file:// prefix. ex: file:///etc/unifi/password.file
# ex: file:///etc/unifi/passwd.file # ex: file:///etc/unifi/passwd.file, windows: file://C:\\UserData\\Unifi\\Passwd.txt
pass = "unifipoller" pass = "unifipoller"
# If the controller has more than one site, specify which sites to poll here. # If the controller has more than one site, specify which sites to poll here.
@ -127,7 +127,7 @@
# Enable collection of site data. This data powers the Network Sites dashboard. # Enable collection of site data. This data powers the Network Sites dashboard.
# It's not valuable to everyone and setting this to false will save resources. # It's not valuable to everyone and setting this to false will save resources.
#save_sites = true save_sites = true
# Hash, with md5, client names and MAC addresses. This attempts to protect # Hash, with md5, client names and MAC addresses. This attempts to protect
# personally identifiable information. Most users won't want to enable this. # personally identifiable information. Most users won't want to enable this.

View File

@ -12,7 +12,7 @@ name="{{BINARYU}}"
real_name="{{BINARY}}" real_name="{{BINARY}}"
rcvar="{{BINARYU}}_enable" rcvar="{{BINARYU}}_enable"
{{BINARYU}}_command="/usr/local/bin/${real_name}" {{BINARYU}}_command="/usr/local/bin/${real_name}"
{{BINARYU}}_user="nobody" {{BINARYU}}_user="{{BINARY}}"
{{BINARYU}}_config="/usr/local/etc/${real_name}/{{CONFIG_FILE}}" {{BINARYU}}_config="/usr/local/etc/${real_name}/{{CONFIG_FILE}}"
pidfile="/var/run/${real_name}/pid" pidfile="/var/run/${real_name}/pid"

22
init/buildinfo.sh Normal file
View File

@ -0,0 +1,22 @@
# This file is read in by settings.sh.
# These values are not generally user configurable and this file is overwritten on upgrades.
# Override values in here by setting them in settings.sh; do not change this file.
##########
VENDOR="Go Lift <code@golift.io>"
# Dynamic. Recommend not changing.
VVERSION=$(git describe --abbrev=0 --tags $(git rev-list --tags --max-count=1) 2>/dev/null)
VERSION="$(echo $VVERSION | tr -d v | grep -E '^\S+$' || echo development)"
# This produces a 0 in some envirnoments (like Homebrew), but it's only used for packages.
ITERATION=$(git rev-list --count --all || echo 0)
DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
COMMIT="$(git rev-parse --short HEAD || echo 0)"
GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD || echo unknown)"
BRANCH="${TRAVIS_BRANCH:-${GIT_BRANCH}}"
# Defines docker manifest/build types.
BUILDS="linux:armhf:arm linux:arm64:arm64 linux:amd64:amd64 linux:i386:386"
export VENDOR VVERSION VERSION ITERATION DATE BRANCH COMMIT BUILDS

View File

@ -10,7 +10,7 @@ ARG COMMIT=0
ARG VERSION=unknown ARG VERSION=unknown
ARG BINARY=application-builder ARG BINARY=application-builder
FROM golang:stretch as builder FROM golang:latest as builder
ARG ARCH ARG ARCH
ARG OS ARG OS
ARG BINARY ARG BINARY
@ -19,7 +19,9 @@ RUN mkdir -p $GOPATH/pkg/mod $GOPATH/bin $GOPATH/src /${BINARY}
COPY . /${BINARY} COPY . /${BINARY}
WORKDIR /${BINARY} WORKDIR /${BINARY}
RUN CGO_ENABLED=0 make ${BINARY}.${ARCH}.${OS} RUN apt update && \
apt install -y upx && \
CGO_ENABLED=0 make ${BINARY}.${ARCH}.${OS}
FROM scratch FROM scratch
ARG ARCH ARG ARCH
@ -30,7 +32,6 @@ ARG VERSION
ARG LICENSE=MIT ARG LICENSE=MIT
ARG BINARY ARG BINARY
ARG SOURCE_URL=http://github.com/golift/application-builder ARG SOURCE_URL=http://github.com/golift/application-builder
ARG URL=http://github.com/golift/application-builder
ARG DESC=application-builder ARG DESC=application-builder
ARG VENDOR=golift ARG VENDOR=golift
ARG AUTHOR=golift ARG AUTHOR=golift
@ -41,7 +42,7 @@ LABEL org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.title="${BINARY}" \ org.opencontainers.image.title="${BINARY}" \
org.opencontainers.image.documentation="${SOURCE_URL}/wiki/Docker" \ org.opencontainers.image.documentation="${SOURCE_URL}/wiki/Docker" \
org.opencontainers.image.description="${DESC}" \ org.opencontainers.image.description="${DESC}" \
org.opencontainers.image.url="${URL}" \ org.opencontainers.image.url="${SOURCE_URL}" \
org.opencontainers.image.revision="${COMMIT}" \ org.opencontainers.image.revision="${COMMIT}" \
org.opencontainers.image.source="${SOURCE_URL}" \ org.opencontainers.image.source="${SOURCE_URL}" \
org.opencontainers.image.vendor="${VENDOR}" \ org.opencontainers.image.vendor="${VENDOR}" \

View File

@ -1,28 +0,0 @@
# Application Builder
[https://github.com/golift/application-builder](https://github.com/golift/application-builder)
## Docker Build Hooks
The files in this folder are used by Docker Cloud to automate image builds.
Do not edit these files.
If you want to build, maintain and push multi-architecture Docker images, you may
follow the example provided here. All of the hooks are generic, and will work with
any build. Two environment variables must be passed in from Docker Cloud config.
1. `BUILDS` must be set to the builds you're trying to perform. This repo is currently set to:
- `linux:armhf:arm linux:arm64:arm64 linux:amd64:amd64 linux:i386:386`
- The format is `os:name:arch`.
- `os` and `name` are passed into the Dockerfile.
- `os`, `arch` are passed into `docker manifest annotate`.
- This does not yet work with an OS other than `linux`.
1. Set `DOCKER_CLI_EXPERIMENTAL` to `enabled`. Not optional.
Keep the build simple; see screenshot. This only supports one build tag, but it creates many more.
![UniFi Poller Docker Cloud Build Rules](https://raw.githubusercontent.com/wiki/unifi-poller/unifi-poller/images/unifi-poller-build-rules.png "UniFi Poller Docker Cloud Build Rules")
The fancy source tag is `/^v((\d+\.\d+)(?:\.\d+)?)$/` and it allows you to capture
the minor version without patch-level in `{\2}`. I no longer use `{\2}` in my build.
[See how it works here](https://regex101.com/r/fzt6ki/1).

View File

@ -9,7 +9,7 @@ set -e -o pipefail
# This always run local to the Dockerfile folder, so the path is ../.. # This always run local to the Dockerfile folder, so the path is ../..
pushd ../.. pushd ../..
source .metadata.sh source settings.sh
# Build each configured image from Docker Cloud. # Build each configured image from Docker Cloud.
for build in $BUILDS; do for build in $BUILDS; do
@ -24,7 +24,6 @@ for build in $BUILDS; do
--build-arg "VERSION=${VERSION}-${ITERATION}" \ --build-arg "VERSION=${VERSION}-${ITERATION}" \
--build-arg "LICENSE=${LICENSE}" \ --build-arg "LICENSE=${LICENSE}" \
--build-arg "DESC=${DESC}" \ --build-arg "DESC=${DESC}" \
--build-arg "URL=${URL}" \
--build-arg "VENDOR=${VENDOR}" \ --build-arg "VENDOR=${VENDOR}" \
--build-arg "AUTHOR=${MAINT}" \ --build-arg "AUTHOR=${MAINT}" \
--build-arg "BINARY=${BINARY}" \ --build-arg "BINARY=${BINARY}" \

View File

@ -4,13 +4,11 @@
# This is part of Application Builder. # This is part of Application Builder.
# https://github.com/golift/application-builder # https://github.com/golift/application-builder
#set -e -o pipefail
pushd ../.. pushd ../..
source .metadata.sh source settings.sh
popd popd
if [ "$TAGS" == "" ]; then if [ "$BUILDS" != "" ]; then
TAGS=$DOCKER_TAG TAGS=$DOCKER_TAG
fi fi
@ -26,14 +24,14 @@ for build in $BUILDS; do
done done
echo "Annotating Images: ${IMAGES}" echo "Annotating Images: ${IMAGES}"
# Build all the Docker tags if the source branch is a release and not a branch. # Build all the Docker tags if the source branch is a release and not a branch or pre-release.
if [ "v$VERSION" = "$SOURCE_BRANCH" ]; then if [ "v$VERSION" = "$SOURCE_BRANCH" ]; then
TAGS="$VERSION $(echo $VERSION | cut -d. -f1,2) $(echo $VERSION | cut -d. -f1)" TAGS="$VERSION"
echo $SOURCE_BRANCH | grep -q -- - echo $SOURCE_BRANCH | grep -q -- -
if [ "$?" = "1" ]; then if [ "$?" = "1" ]; then
# tag does not contain a dash, so assume it's a prod tag. # tag does not contain a dash, so assume it's a prod tag.
TAGS="$TAGS latest stable" TAGS="$TAGS latest stable $(echo $VERSION | cut -d. -f1,2) $(echo $VERSION | cut -d. -f1)"
fi fi
fi fi
@ -43,7 +41,7 @@ echo "Version: $VERSION, Source: $SOURCE_BRANCH, Building tags: ${TAGS}"
for tag in $TAGS; do for tag in $TAGS; do
docker manifest create --amend ${DOCKER_REPO}:${tag} $IMAGES docker manifest create --amend ${DOCKER_REPO}:${tag} $IMAGES
for build in $BUILDS; do for build in $BUILDS; do
# os:name:arch:variant, ie linux:amd64:amd64: (no variant is ok) # os:name:arch, ie linux:amd64:amd64
os=$(echo $build | cut -d: -f1) os=$(echo $build | cut -d: -f1)
name=$(echo $build | cut -d: -f2) name=$(echo $build | cut -d: -f2)
arch=$(echo $build | cut -d: -f3) arch=$(echo $build | cut -d: -f3)

View File

@ -1,6 +1,7 @@
# macOS Homebrew Formula Template. Built by Makefile: `make fomula` # Homebrew Formula Template. Built by Makefile: `make fomula`
# This is part of Application Builder. # This is part of Application Builder.
# https://github.com/golift/application-builder # https://github.com/golift/application-builder
# This file is used when FORMULA is set to 'service'.
class {{Class}} < Formula class {{Class}} < Formula
desc "{{Desc}}" desc "{{Desc}}"
homepage "{{URL}}" homepage "{{URL}}"
@ -9,6 +10,7 @@ class {{Class}} < Formula
head "{{SOURCE_URL}}" head "{{SOURCE_URL}}"
depends_on "go" => :build depends_on "go" => :build
depends_on "upx" => :build
def install def install
bin_path = buildpath/"#{name}" bin_path = buildpath/"#{name}"

View File

@ -1,2 +0,0 @@
This file isn't used by the build or for any packages. The homebrew launchd is
in the [homebrew](../homebrew) folder. This macOS launchd file is for reference only.

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.github.unifi-poller.unifi-poller</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/unifi-poller</string>
<string>-c</string>
<string>/usr/local/etc/unifi-poller/up.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/unifi-poller.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/unifi-poller.log</string>
</dict>
</plist>

View File

@ -1,6 +1,7 @@
# Linux Systemd service unit for {{BINARY}}. # Systemd service unit for {{BINARY}}.
# This is part of Application Builder. # This is part of Application Builder.
# https://github.com/golift/application-builder # https://github.com/golift/application-builder
# This file is installed when FORMULA is set to 'service'.
[Unit] [Unit]
Description={{BINARY}} - {{DESC}} Description={{BINARY}} - {{DESC}}
@ -17,7 +18,12 @@ StandardOutput=syslog
StandardError=syslog StandardError=syslog
SyslogIdentifier={{BINARY}} SyslogIdentifier={{BINARY}}
Type=simple Type=simple
User=nobody WorkingDirectory=/tmp
# These should be set correctly for your environment.
UMask=0002
User={{BINARY}}
Group={{BINARY}}
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

29
init/windows/manifest.xml Normal file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="unifi-poller" type="win32"/>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
</dependentAssembly>
</dependency>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True</dpiAware>
</windowsSettings>
</application>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
</assembly>

29
scripts/after-install.sh Executable file → Normal file
View File

@ -1,14 +1,29 @@
#!/bin/sh #!/bin/sh
# This file is used by txz, deb and rpm packages. # This file is used by deb, rpm and BSD packages.
# FPM adds this as the after-install script to all packages. # FPM adds this as the after-install script.
# Edit this file as needed for your application.
# This file is only installed if FORMULA is set to service.
OS="$(uname -s)"
if [ "${OS}" = "Linux" ]; then
# Make a user and group for this app, but only if it does not already exist.
id {{BINARY}} >/dev/null 2>&1 || \
useradd --system --user-group --no-create-home --home-dir /tmp --shell /bin/false {{BINARY}}
elif [ "${OS}" = "OpenBSD" ]; then
id {{BINARY}} >/dev/null 2>&1 || \
useradd -g =uid -d /tmp -s /bin/false {{BINARY}}
elif [ "${OS}" = "FreeBSD" ]; then
id {{BINARY}} >/dev/null 2>&1 || \
pw useradd {{BINARY}} -d /tmp -w no -s /bin/false
else
echo "Unknown OS: ${OS}, please add system user {{BINARY}} manually."
fi
if [ -x "/bin/systemctl" ]; then if [ -x "/bin/systemctl" ]; then
# Reload and restart - this starts the application as user nobody. # Reload and restart - this starts the application as user nobody.
/bin/systemctl daemon-reload /bin/systemctl daemon-reload
/bin/systemctl enable unifi-poller /bin/systemctl enable {{BINARY}}
/bin/systemctl restart unifi-poller /bin/systemctl restart {{BINARY}}
elif [ -x /usr/sbin/service ]; then
# Do not start or restart on freebsd. That's "bad practice."
/usr/sbin/service unifi-poller enabled || /usr/sbin/service unifi-poller enable
fi fi

13
scripts/before-remove.sh Executable file → Normal file
View File

@ -1,15 +1,14 @@
#!/bin/sh #!/bin/bash
# This file is used by txz, rpm and deb packages. FPM use. # This file is used by rpm and deb packages. FPM use.
# Edit this file as needed for your application.
# This file is only installed if FORMULA is set to service.
if [ "$1" = "upgrade" ] || [ "$1" = "1" ] ; then if [ "$1" = "upgrade" ] || [ "$1" = "1" ] ; then
exit 0 exit 0
fi fi
if [ -x "/bin/systemctl" ]; then if [ -x "/bin/systemctl" ]; then
/bin/systemctl stop unifi-poller /bin/systemctl stop {{BINARY}}
/bin/systemctl disable unifi-poller /bin/systemctl disable {{BINARY}}
elif [ -x /usr/sbin/service ]; then
/usr/sbin/service unifi-poller stop
/usr/sbin/service unifi-poller disable
fi fi

22
scripts/formula-deploy.sh Executable file → Normal file
View File

@ -3,10 +3,9 @@
# Deploys a new homebrew formula file to a github homebrew formula repo: $HBREPO # Deploys a new homebrew formula file to a github homebrew formula repo: $HBREPO
# Requires SSH credentials in ssh-agent to work. # Requires SSH credentials in ssh-agent to work.
# Run by Travis-CI when a new release is created on GitHub. # Run by Travis-CI when a new release is created on GitHub.
# Do not edit this file. It's part of application-builder. # Do not edit this file.
# https://github.com/golift/application-builder
source .metadata.sh source settings.sh
make ${BINARY}.rb make ${BINARY}.rb
@ -16,6 +15,23 @@ git config --global user.name "${BINARY}-auto-releaser"
rm -rf homebrew_release_repo rm -rf homebrew_release_repo
git clone git@github.com:${HBREPO}.git homebrew_release_repo git clone git@github.com:${HBREPO}.git homebrew_release_repo
# If a bitly token file exists, we'll use that to shorten the link (and allow download counting).
if [ -f "bitly_token" ]; then
API=https://api-ssl.bitly.com/v4/bitlinks
# Request payload. In single quotes with double quotes escaped. :see_no_evil:
JSON='{\"domain\": \"bit.ly\",\"title\": \"${BINARY}.v${VERSION}-${ITERATION}.tgz\", \
\"tags\": [\"${BINARY}\"], \"long_url\": \"${SOURCE_PATH}\"}'
# Request with headers and data. Using bash -c to hide token from bash -x in travis logs.
OUT=$(bash -c "curl -s -X POST -H 'Content-type: application/json' ${API} -H \"\$(<bitly_token)\" -d \"${JSON}\"")
# Extract link from reply.
LINK="$(echo ${OUT} | jq -r .link | sed 's/http:/https:/')?v=v${VERSION}"
# Replace link in formula.
sed "s#^ url.*\$# url \"${LINK}\"#" ${BINARY}.rb > ${BINARY}.rb.new
if [ "$?" = "0" ] && [ "$LINK" != "null?v=v${VERSION}" ] && [ "$LINK" != "?v=v${VERSION}" ]; then
mv ${BINARY}.rb.new ${BINARY}.rb
fi
fi
cp ${BINARY}.rb homebrew_release_repo/Formula cp ${BINARY}.rb homebrew_release_repo/Formula
pushd homebrew_release_repo pushd homebrew_release_repo
git add Formula/${BINARY}.rb git add Formula/${BINARY}.rb

17
scripts/install.sh Executable file → Normal file
View File

@ -1,11 +1,11 @@
#!/bin/sh #!/bin/bash
#
# This is a quick and dirty script to install the latest Linux package. # This is a quick and dirty script to install the latest package.
# #
# Use it like this, pick curl or wget: (sudo is optional) # Use it like this, pick curl or wget: (sudo is optional)
# ---- # ----
# curl -s https://raw.githubusercontent.com/unifi-poller/unifi-poller/master/scripts/install.sh | sudo sh # curl -sL https://raw.githubusercontent.com/unifi-poller/unifi-poller/main/scripts/install.sh | sudo bash
# wget -qO- https://raw.githubusercontent.com/unifi-poller/unifi-poller/master/scripts/install.sh | sudo sh # wget -qO- https://raw.githubusercontent.com/unifi-poller/unifi-poller/main/scripts/install.sh | sudo bash
# ---- # ----
# #
# - If you're on RedHat/CentOS/Fedora, installs the latest rpm package. # - If you're on RedHat/CentOS/Fedora, installs the latest rpm package.
@ -15,15 +15,18 @@
# This is part of application-builder. # This is part of application-builder.
# https://github.com/golift/application-builder # https://github.com/golift/application-builder
# Set the repo name correctly.
REPO=unifi-poller/unifi-poller REPO=unifi-poller/unifi-poller
BREW=golift/mugs/unifi-poller BREW=golift/mugs/unifi-poller
# Nothing else needs to be changed. Unless you're fixing things!
LATEST=https://api.github.com/repos/${REPO}/releases/latest LATEST=https://api.github.com/repos/${REPO}/releases/latest
ISSUES=https://github.com/${REPO}/issues/new ISSUES=https://github.com/${REPO}/issues/new
ARCH=$(uname -m) ARCH=$(uname -m)
OS=$(uname -s) OS=$(uname -s)
P=" ==>" P=" ==>"
# Nothing else needs to be changed. Unless you're fixing things!
echo "<-------------------------------------------------->" echo "<-------------------------------------------------->"
if [ "$OS" = "Darwin" ]; then if [ "$OS" = "Darwin" ]; then
@ -108,7 +111,7 @@ INSTALLER="rpm -Uvh"
if [ "$FILE" = "deb" ]; then if [ "$FILE" = "deb" ]; then
INSTALLER="dpkg --force-confdef --force-confold --install" INSTALLER="dpkg --force-confdef --force-confold --install"
elif [ "$FILE" = "txz" ]; then elif [ "$FILE" = "txz" ]; then
INSTALLER="pkg install" INSTALLER="pkg install --yes"
fi fi
FILE=$(basename ${URL}) FILE=$(basename ${URL})

View File

@ -2,6 +2,9 @@
# This file is parsed and sourced by the Makefile, Docker and Homebrew builds. # This file is parsed and sourced by the Makefile, Docker and Homebrew builds.
# Powered by Application Builder: https://github.com/golift/application-builder # Powered by Application Builder: https://github.com/golift/application-builder
# Bring in dynamic repo/pull/source info.
source $(dirname "${BASH_SOURCE[0]}")/init/buildinfo.sh
# Must match the repo name. # Must match the repo name.
BINARY="unifi-poller" BINARY="unifi-poller"
# Github repo containing homebrew formula repo. # Github repo containing homebrew formula repo.
@ -17,32 +20,13 @@ LICENSE="MIT"
# This affects the homebrew formula (launchd) and linux packages (systemd). # This affects the homebrew formula (launchd) and linux packages (systemd).
FORMULA="service" FORMULA="service"
# Defines docker manifest/build types.
BUILDS="linux:armhf:arm linux:arm64:arm64 linux:amd64:amd64 linux:i386:386"
export BINARY HBREPO MAINT VENDOR DESC GOLANGCI_LINT_ARGS CONFIG_FILE LICENSE FORMULA BUILDS
# The rest is mostly automatic.
# Fix the repo if it doesn't match the binary name.
# Provide a better URL if one exists.
# Used for source links and wiki links. # Used for source links and wiki links.
SOURCE_URL="https://github.com/${BINARY}/${BINARY}" SOURCE_URL="https://github.com/${BINARY}/${BINARY}"
# Used for documentation links.
URL="${SOURCE_URL}"
# Dynamic. Recommend not changing. VERSION_PATH="golift.io/version"
VVERSION=$(git describe --abbrev=0 --tags $(git rev-list --tags --max-count=1))
VERSION="$(echo $VVERSION | tr -d v | grep -E '^\S+$' || echo development)"
# This produces a 0 in some envirnoments (like Homebrew), but it's only used for packages.
ITERATION=$(git rev-list --count --all || echo 0)
DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
COMMIT="$(git rev-parse --short HEAD || echo 0)"
GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD || echo unknown)"
BRANCH="${TRAVIS_BRANCH:-${GIT_BRANCH}}"
# This is a custom download path for homebrew formula. # This is a custom download path for homebrew formula.
SOURCE_PATH=https://golift.io/${BINARY}/archive/v${VERSION}.tar.gz SOURCE_PATH=https://golift.io/${BINARY}/archive/v${VERSION}.tar.gz
export SOURCE_URL URL VVERSION VERSION ITERATION DATE BRANCH COMMIT SOURCE_PATH export BINARY HBREPO MAINT VENDOR DESC GOLANGCI_LINT_ARGS CONFIG_FILE
export LICENSE FORMULA SOURCE_URL VERSION_PATH SOURCE_PATH