More cleanup. Move uninstall to Makefile.

This commit is contained in:
David Newhall II 2019-06-07 15:12:06 -07:00
parent 0c9431d09e
commit f0aa7db84a
3 changed files with 38 additions and 57 deletions

View File

@ -9,7 +9,8 @@ ITERATION:=$(shell git rev-list --all --count)
all: man build
# Prepare a release. Called in Travis CI.
release: clean test rpm deb osxpkg
release: clean test $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb $(BINARY)-$(VERSION).pkg
# Prepareing a release!
mkdir -p release
gzip -9 $(BINARY).linux
gzip -9 $(BINARY).macos
@ -18,6 +19,7 @@ release: clean test rpm deb osxpkg
# 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
@ -25,8 +27,8 @@ clean:
# Build a man page from a markdown file using ronn.
man: $(BINARY).1.gz
$(BINARY).1.gz:
# Building man page.
@ronn --version > /dev/null || (echo "Ronn missing. Install ronn: $(URL)/wiki/Ronn" && false)
@echo "Creating Man Page: $(PACKAGE)/README.md -> $(BINARY).1.gz"
ronn < "$(PACKAGE)/README.md" | gzip -9 > "$(BINARY).1.gz"
# Binaries
@ -37,15 +39,17 @@ $(BINARY):
linux: $(BINARY).linux
$(BINARY).linux:
# Building linux binary.
GOOS=linux go build -o $(BINARY).linux -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE)
macos: $(BINARY).macos
$(BINARY).macos:
# Building darwin binary.
GOOS=darwin go build -o $(BINARY).macos -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE)
# Packages
rpm: $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm
rpm: clean $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm
$(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm: check_fpm package_build_linux
@echo "Building 'rpm' package for $(BINARY) version '$(VERSION)-$(ITERATION)'."
fpm -s dir -t rpm \
@ -60,7 +64,7 @@ $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm: check_fpm package_build_linux
--description $(DESC) \
--chdir package_build_linux
deb: $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb
deb: clean $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb
$(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb: check_fpm package_build_linux
@echo "Building 'deb' package for $(BINARY) version '$(VERSION)-$(ITERATION)'."
fpm -s dir -t deb \
@ -75,7 +79,7 @@ $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb: check_fpm package_build_linux
--description $(DESC) \
--chdir package_build_linux
osxpkg: $(BINARY)-$(VERSION).pkg
osxpkg: clean $(BINARY)-$(VERSION).pkg
$(BINARY)-$(VERSION).pkg: check_fpm package_build_osx
@echo "Building 'osx' package for $(BINARY) version '$(VERSION)-$(ITERATION)'."
fpm -s dir -t osxpkg \
@ -92,32 +96,29 @@ $(BINARY)-$(VERSION).pkg: check_fpm package_build_osx
# OSX packages use /usr/local because Apple doesn't allow writing many other places.
package_build_osx: man macos
# Build package environment for macOS.
mkdir -p $@/usr/local/bin $@/usr/local/etc/$(BINARY)
mkdir -p $@/usr/local/share/man/man1 $@/usr/local/share/doc/$(BINARY)
# Copy the binary, config file and man page into the env.
# 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
# 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/* $@/usr/local/share/doc/$(BINARY)/
mkdir -p $@/usr/local/var/log
mkdir -p $@/Library/LaunchAgents
cp init/launchd/com.github.davidnewhall.unifi-poller.plist $@/Library/LaunchAgents/
# Build an environment that can be packaged for linux.
package_build_linux: man linux
# Build package environment for linux.
mkdir -p $@/usr/bin $@/etc/$(BINARY)
# Building package environment for linux.
mkdir -p $@/usr/bin $@/etc/$(BINARY) $@/lib/systemd/system
mkdir -p $@/usr/share/man/man1 $@/usr/share/doc/$(BINARY)
# Copy the binary, config file and man page into the env.
cp ${BINARY}.linux $@/usr/bin/$(BINARY)
# Copying the binary, config 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/* $@/usr/share/doc/$(BINARY)/
cp examples/up.conf.example $@/etc/$(BINARY)/up.conf
# Fix the paths in the systemd unit file before copying it into the emv.
mkdir -p $@/lib/systemd/system
sed "s%ExecStart.*%ExecStart=/usr/bin/$(BINARY) --config=/etc/${BINARY}/up.conf%" \
cp examples/* $@/usr/share/doc/$(BINARY)/
# Fixing the paths in the systemd unit file before copying it into the emv.
sed "s%ExecStart.*%ExecStart=/usr/bin/$(BINARY) --config=/etc/$(BINARY)/up.conf%" \
init/systemd/unifi-poller.service > $@/lib/systemd/system/$(BINARY).service
check_fpm:
@ -127,8 +128,10 @@ check_fpm:
# Run code tests and lint.
test: lint
# Testing.
go test -race -covermode=atomic $(PACKAGE)
lint:
# Checking lint.
golangci-lint run --enable-all -D gochecknoglobals
# Install locally into /usr/local. Not recommended.
@ -136,8 +139,20 @@ install: man
scripts/local_install.sh
# 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.
uninstall:
scripts/local_uninstall.sh
[ -x /bin/systemctl ] && /bin/systemctl disable $(BINARY) || true
[ -x /bin/systemctl ] && /bin/systemctl stop $(BINARY) || true
[ -x /bin/launchctl ] && [ -f ~/Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist ] \
&& /bin/launchctl unload ~/Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist || true
[ -x /bin/launchctl ] && [ -f /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist ] \
&& /bin/launchctl unload /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist || true
rm -rf /usr/local/{etc,bin}/$(BINARY) /usr/local/share/man/man1/$(BINARY).1.gz
rm -f ~/Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist
rm -f /etc/systemd/system/$(BINARY).service
[ -x /bin/systemctl ] && /bin/systemctl --system daemon-reload || true
@[ -x /bin/launchctl ] && [ -f /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist ] \
&& echo " ==> Delete this file manually: sudo rm -f /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist" || true
# Don't run this unless you're ready to debug untested vendored dependencies.
deps:

View File

@ -33,7 +33,9 @@ unifi-poller(1) -- Utility to poll UniFi Controller Metrics and store them in In
`sites` default: ["default"]
This list of strings should represent the names of sites on the unifi
controller that will be polled for data. Pass `all` in the list to
poll all sites.
poll all sites. On startup, the application prints out all site names
found in the controller; they're cryptic, but they have the human-name
next to them. The cryptic names go into the config file `sites` list.
`interval` default: 30s
How often to poll the controller for updated client and device data.

View File

@ -1,36 +0,0 @@
#!/bin/bash
# This script removes a local installation of unifi-poller.
# Recommend using Makefile to invoke: make uninstall
# Supports Linux (systemd only) and macOS.
BINARY=unifi-poller
echo "Uninstall unifi-poller. You may need sudo on Linux. Do not use sudo on macOS."
# Stopping the daemon
if [ -x /bin/systemctl ]; then
/bin/systemctl disable ${BINARY}
/bin/systemctl stop ${BINARY}
fi
if [ -x /bin/launchctl ] && [ -f ~/Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist ]; then
echo Unloading ~/Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist
/bin/launchctl unload ~/Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist || true
fi
if [ -x /bin/launchctl ] && [ -f /Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist ]; then
echo Unloading /Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist
/bin/launchctl unload /Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist || true
echo "Delete this file manually: sudo rm -f /Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist"
fi
# Deleting config file, binary, man page, launch agent or unit file.
rm -rf /usr/local/{etc,bin}/${BINARY} /usr/local/share/man/man1/${BINARY}.1.gz
rm -f ~/Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist
rm -f /etc/systemd/system/${BINARY}.service
# Making systemd happy by telling it to reload.
if [ -x /bin/systemctl ]; then
/bin/systemctl --system daemon-reload
fi