Merge pull request #23 from davidnewhall/dn2_vendor_fixes
Update build procedures. Add rpm and deb package scripts.
This commit is contained in:
commit
b7c1368a1a
|
|
@ -2,6 +2,10 @@
|
||||||
/unifi-poller
|
/unifi-poller
|
||||||
/*.gz
|
/*.gz
|
||||||
/*.1
|
/*.1
|
||||||
|
/*.deb
|
||||||
|
/*.rpm
|
||||||
|
/*.pkg
|
||||||
/vendor
|
/vendor
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*~
|
*~
|
||||||
|
/package_build
|
||||||
|
|
|
||||||
55
Makefile
55
Makefile
|
|
@ -5,6 +5,7 @@ all: clean man build
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
for p in $(PACKAGES); do rm -f `echo $${p}|cut -d/ -f3`{,.1,.1.gz}; done
|
for p in $(PACKAGES); do rm -f `echo $${p}|cut -d/ -f3`{,.1,.1.gz}; done
|
||||||
|
rm -rf package_build unifi-poller_*.deb unifi-poller-*.rpm unifi-poller-*.pkg
|
||||||
|
|
||||||
build:
|
build:
|
||||||
for p in $(PACKAGES); do go build -ldflags "-w -s" $${p}; done
|
for p in $(PACKAGES); do go build -ldflags "-w -s" $${p}; done
|
||||||
|
|
@ -12,41 +13,30 @@ build:
|
||||||
linux:
|
linux:
|
||||||
for p in $(PACKAGES); do GOOS=linux go build -ldflags "-w -s" $${p}; done
|
for p in $(PACKAGES); do GOOS=linux go build -ldflags "-w -s" $${p}; done
|
||||||
|
|
||||||
install: man test build
|
darwin:
|
||||||
@echo "If you get errors, you may need sudo."
|
for p in $(PACKAGES); do GOOS=darwin go build -ldflags "-w -s" $${p}; done
|
||||||
# Install binary. binary.
|
|
||||||
GOBIN=/usr/local/bin go install -ldflags "-w -s" ./...
|
|
||||||
# Making config folders and installing man page.
|
|
||||||
mkdir -p /usr/local/etc/$(BINARY) /usr/local/share/man/man1
|
|
||||||
mv *.1.gz /usr/local/share/man/man1
|
|
||||||
# Installing config file, man page and launch agent or systemd unit file.
|
|
||||||
test -f /usr/local/etc/$(BINARY)/up.conf || cp up.conf.example /usr/local/etc/$(BINARY)/up.conf
|
|
||||||
test -d ~/Library/LaunchAgents && cp startup/launchd/com.github.davidnewhall.$(BINARY).plist ~/Library/LaunchAgents || true
|
|
||||||
test -d /etc/systemd/system && cp startup/systemd/$(BINARY).service /etc/systemd/system || true
|
|
||||||
# Making systemd happy by telling it to reload.
|
|
||||||
test -x /bin/systemctl && /bin/systemctl --system daemon-reload || true
|
|
||||||
@echo
|
|
||||||
@echo "Installation Complete. Edit the config file @ /usr/local/etc/$(BINARY)/up.conf "
|
|
||||||
@echo "Then start the daemon with:"
|
|
||||||
@test -d ~/Library/LaunchAgents && echo " launchctl load ~/Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist" || true
|
|
||||||
@test -d /etc/systemd/system && echo " sudo /bin/systemctl start $(BINARY)" || true
|
|
||||||
@echo "Examine the log file at: /usr/local/var/log/$(BINARY).log (logs may go elsewhere on linux, check syslog)"
|
|
||||||
|
|
||||||
uninstall:
|
|
||||||
@echo "If you get errors, you may need sudo."
|
|
||||||
# Stopping the daemon
|
|
||||||
test -x /bin/systemctl && /bin/systemctl stop $(BINARY) || true
|
|
||||||
test -x /bin/launchctl && /bin/launchctl unload ~/Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist || true
|
|
||||||
# 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.
|
|
||||||
test -x /bin/systemctl && /bin/systemctl --system daemon-reload || true
|
|
||||||
|
|
||||||
test: lint
|
test: lint
|
||||||
for p in $(PACKAGES) $(LIBRARYS); do go test -race -covermode=atomic $${p}; done
|
for p in $(PACKAGES) $(LIBRARYS); do go test -race -covermode=atomic $${p}; done
|
||||||
|
|
||||||
|
man:
|
||||||
|
scripts/build_manpages.sh ./
|
||||||
|
|
||||||
|
rpm: clean man linux
|
||||||
|
scripts/build_linux_packages.sh rpm
|
||||||
|
|
||||||
|
deb: clean man linux
|
||||||
|
scripts/build_linux_packages.sh deb
|
||||||
|
|
||||||
|
osxpkg: clean man darwin
|
||||||
|
scripts/build_osx_package.sh
|
||||||
|
|
||||||
|
install: all
|
||||||
|
scripts/local_install.sh
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
scripts/local_uninstall.sh
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
goimports -l $(PACKAGES)
|
goimports -l $(PACKAGES)
|
||||||
gofmt -l $(PACKAGES)
|
gofmt -l $(PACKAGES)
|
||||||
|
|
@ -54,8 +44,5 @@ lint:
|
||||||
golint $(PACKAGES)
|
golint $(PACKAGES)
|
||||||
go vet $(PACKAGES)
|
go vet $(PACKAGES)
|
||||||
|
|
||||||
man:
|
|
||||||
script/build_manpages.sh ./
|
|
||||||
|
|
||||||
deps:
|
deps:
|
||||||
dep ensure -update
|
dep ensure -update
|
||||||
|
|
|
||||||
16
README.md
16
README.md
|
|
@ -43,13 +43,6 @@ I only, personally, run this on a Mac 10.13.something. I know others are using
|
||||||
Linux and it's working, but I need more feedback. Does the unit file work? Are
|
Linux and it's working, but I need more feedback. Does the unit file work? Are
|
||||||
you able to stop and start the service? Does the Makefile do the right things?
|
you able to stop and start the service? Does the Makefile do the right things?
|
||||||
|
|
||||||
- I probably suck at InfluxDB.
|
|
||||||
|
|
||||||
I don't know what should be a tag and what should be a field. I think
|
|
||||||
I did my best, but there's certainly room for improvements in both
|
|
||||||
the data input and the Grafana graphs (output). I'm always iterating, but
|
|
||||||
if you find a deficiency or something that can be improved, let me know.
|
|
||||||
|
|
||||||
- Are there other devices that need to be included?
|
- Are there other devices that need to be included?
|
||||||
|
|
||||||
I have: switch, router, access point. Three total, and the type structs are
|
I have: switch, router, access point. Three total, and the type structs are
|
||||||
|
|
@ -64,11 +57,6 @@ Issue and lets discuss.
|
||||||
If you're a nerd you can probably figure it out. I'd still like some pretty
|
If you're a nerd you can probably figure it out. I'd still like some pretty
|
||||||
pictures and maybe even a Twitch VOD.
|
pictures and maybe even a Twitch VOD.
|
||||||
|
|
||||||
- Sanity Checking
|
|
||||||
|
|
||||||
Did I actually graph the right data in the right way? Some validation would
|
|
||||||
be nice.
|
|
||||||
|
|
||||||
- Radios, Frequencies, Interfaces, vAPs
|
- Radios, Frequencies, Interfaces, vAPs
|
||||||
|
|
||||||
My access points only seem to have two radios, one interface and vAP per radio.
|
My access points only seem to have two radios, one interface and vAP per radio.
|
||||||
|
|
@ -84,12 +72,12 @@ isolate why this happens. We may need to issue a reconnect and get a new cookie.
|
||||||
|
|
||||||
Here's a picture of the Client dashboard.
|
Here's a picture of the Client dashboard.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Here's a picture of the UAP dashboard. This only shows one device, but you can
|
Here's a picture of the UAP dashboard. This only shows one device, but you can
|
||||||
select multiple to put specific stats side-by-side.
|
select multiple to put specific stats side-by-side.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
## Copyright & License
|
## Copyright & License
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
# Grafana Dashboards & Examples
|
||||||
|
|
||||||
|
This folder contains grafana dashboards to get you started with the new data pool.
|
||||||
|
Import these into Grafana to quickly visualize data from your devices.
|
||||||
|
|
||||||
|
They may/do use a few plugins: Clock, Discrete, Singlestat, Table
|
||||||
|
|
||||||
|
This folder also contains an example configuration file and some dashboard screenshots.
|
||||||
|
Before Width: | Height: | Size: 246 KiB After Width: | Height: | Size: 246 KiB |
|
Before Width: | Height: | Size: 141 KiB After Width: | Height: | Size: 141 KiB |
|
|
@ -1,5 +0,0 @@
|
||||||
# Grafana Dashboards
|
|
||||||
|
|
||||||
Import these into Grafana to quickly visualize data from your devices.
|
|
||||||
|
|
||||||
They may/do use a few plugins: Clock, Discrete, Singlestat, Table
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# untested, feedback welcomed.
|
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Unifi Poller - Ubiquiti Metrics->InfluxDB
|
Description=Unifi Poller - Ubiquiti Metrics->InfluxDB
|
||||||
After=network.target
|
After=network.target
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This file is used by osxpkg packages. FPM use.
|
||||||
|
|
||||||
|
# Copy the config file into place if it does not exist.
|
||||||
|
if [ ! -f /usr/local/etc/unifi-poller/up.conf ] && [ -f /usr/local/etc/unifi-poller/up.conf.example ]; then
|
||||||
|
cp /usr/local/etc/unifi-poller/up.conf.example /usr/local/etc/unifi-poller/up.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Allow admins to change the configuration and write logs.
|
||||||
|
chgrp -R admin /usr/local/etc/unifi-poller
|
||||||
|
chmod -R g+wr /usr/local/etc/unifi-poller
|
||||||
|
|
||||||
|
# Make sure admins can write logs.
|
||||||
|
chgrp admin /usr/local/var/log
|
||||||
|
chmod g=rwx /usr/local/var/log
|
||||||
|
|
||||||
|
# This starts it as root. no no no .... not sure how to fix that.
|
||||||
|
# launchctl load /Library/LaunchAgents/com.github.davidnewhall.unifi-poller.plist
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This file is used by rpm and deb packages. FPM use.
|
||||||
|
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable unifi-poller
|
||||||
|
systemctl restart unifi-poller
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This file is used by rpm and deb packages. FPM use.
|
||||||
|
|
||||||
|
systemctl stop unifi-poller
|
||||||
|
systemctl disable unifi-poller
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This script builds a deb or rpm package. Run by the Makefile.
|
||||||
|
# Use: `make rpm` or `make deb`
|
||||||
|
|
||||||
|
OUTPUT=$1
|
||||||
|
BINARY=unifi-poller
|
||||||
|
VERSION=$(git tag -l --merged | tail -n1 | tr -d v)
|
||||||
|
|
||||||
|
if [ "$OUTPUT" != "deb" ] && [ "$OUTPUT" != "rpm" ]; then
|
||||||
|
echo "first argument must be 'deb' or 'rpm'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
fpm -h > /dev/null 2>&1
|
||||||
|
if [ "$?" != "0" ]; then
|
||||||
|
echo "fpm missing. Install fpm: https://fpm.readthedocs.io/en/latest/installing.html"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Building '${OUTPUT}' package."
|
||||||
|
|
||||||
|
PREFIX=
|
||||||
|
BINFIX=/usr
|
||||||
|
|
||||||
|
# Make a build environment.
|
||||||
|
rm -rf package_build
|
||||||
|
mkdir -p package_build${BINFIX}/bin package_build${PREFIX}/etc/${BINARY} package_build${BINFIX}/share/man/man1
|
||||||
|
|
||||||
|
# Copy the binary, config file and man page into the env.
|
||||||
|
cp ${BINARY} package_build${BINFIX}/bin
|
||||||
|
cp *.1.gz package_build${BINFIX}/share/man/man1
|
||||||
|
cp examples/up.conf.example package_build${PREFIX}/etc/${BINARY}/up.conf
|
||||||
|
|
||||||
|
# Fix the paths in the systemd unit file before copying it into the emv.
|
||||||
|
mkdir -p package_build/lib/systemd/system
|
||||||
|
sed "s#ExecStart.*#ExecStart=${BINFIX}/bin/${BINARY} --config=${PREFIX}/etc/${BINARY}/up.conf#" \
|
||||||
|
init/systemd/unifi-poller.service > package_build/lib/systemd/system/${BINARY}.service
|
||||||
|
|
||||||
|
fpm -s dir -t ${OUTPUT} \
|
||||||
|
--name ${BINARY} \
|
||||||
|
--version ${VERSION} \
|
||||||
|
--after-install scripts/after-install.sh \
|
||||||
|
--before-remove scripts/before-remove.sh \
|
||||||
|
--chdir package_build
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This file uses ronn to build a man page for unifi-poller.
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
OUTPUT=$1
|
OUTPUT=$1
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This script builds a simple macos Installer pkg. Run by the Makefile.
|
||||||
|
# Use: `make osx`
|
||||||
|
|
||||||
|
OUTPUT=$1
|
||||||
|
BINARY=unifi-poller
|
||||||
|
VERSION=$(git tag -l --merged | tail -n1 | tr -d v)
|
||||||
|
|
||||||
|
fpm -h > /dev/null 2>&1
|
||||||
|
if [ "$?" != "0" ]; then
|
||||||
|
echo "fpm missing. Install fpm: https://fpm.readthedocs.io/en/latest/installing.html"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Building 'osxpkg' package."
|
||||||
|
|
||||||
|
PREFIX=/usr/local
|
||||||
|
BINFIX=/usr/local
|
||||||
|
|
||||||
|
# Make a build environment.
|
||||||
|
rm -rf package_build
|
||||||
|
mkdir -p package_build${BINFIX}/bin package_build${PREFIX}/etc/${BINARY} package_build${BINFIX}/share/man/man1
|
||||||
|
mkdir -p package_build${PREFIX}/var/log
|
||||||
|
|
||||||
|
# Copy the binary, config file and man page into the env.
|
||||||
|
cp ${BINARY} package_build${BINFIX}/bin
|
||||||
|
cp *.1.gz package_build${BINFIX}/share/man/man1
|
||||||
|
cp examples/up.conf.example package_build${PREFIX}/etc/${BINARY}/
|
||||||
|
|
||||||
|
# Copy in launch agent.
|
||||||
|
mkdir -p package_build/Library/LaunchAgents
|
||||||
|
cp init/launchd/com.github.davidnewhall.unifi-poller.plist package_build/Library/LaunchAgents/
|
||||||
|
|
||||||
|
# Make a package.
|
||||||
|
fpm -s dir -t osxpkg \
|
||||||
|
--name ${BINARY} \
|
||||||
|
--version ${VERSION} \
|
||||||
|
--after-install scripts/after-install-osx.sh \
|
||||||
|
--osxpkg-identifier-prefix com.github.davidnewhall \
|
||||||
|
--chdir package_build
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This script creates a local installation of unifi-poller.
|
||||||
|
# Recommend using Makefile to invoke: make install
|
||||||
|
# Supports Linux (systemd only) and macOS.
|
||||||
|
|
||||||
|
BINARY=unifi-poller
|
||||||
|
|
||||||
|
echo "Installing unifi-poller. If you get errors, you may need sudo."
|
||||||
|
|
||||||
|
# Install binary.
|
||||||
|
GOBIN=/usr/local/bin go install -ldflags "-w -s" ./...
|
||||||
|
|
||||||
|
# Making config folders and installing man page.
|
||||||
|
mkdir -p /usr/local/etc/${BINARY} /usr/local/share/man/man1
|
||||||
|
mv *.1.gz /usr/local/share/man/man1
|
||||||
|
|
||||||
|
# Installing config file, man page and launch agent or systemd unit file.
|
||||||
|
if [ ! -f /usr/local/etc/${BINARY}/up.conf ]; then
|
||||||
|
cp examples/up.conf.example /usr/local/etc/${BINARY}/up.conf
|
||||||
|
fi
|
||||||
|
if [ -d ~/Library/LaunchAgents ]; then
|
||||||
|
cp init/launchd/com.github.davidnewhall.${BINARY}.plist ~/Library/LaunchAgents
|
||||||
|
fi
|
||||||
|
if [ -d /etc/systemd/system ]; then
|
||||||
|
cp init/systemd/${BINARY}.service /etc/systemd/system
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Making systemd happy by telling it to reload.
|
||||||
|
if [ -x /bin/systemctl ]; then
|
||||||
|
/bin/systemctl --system daemon-reload
|
||||||
|
/bin/systemctl start unifi-poller
|
||||||
|
/bin/systemctl enable unifi-poller
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Installation Complete. Edit the config file @ /usr/local/etc/${BINARY}/up.conf"
|
||||||
|
echo "Then start the daemon with:"
|
||||||
|
if [ -d ~/Library/LaunchAgents ]; then
|
||||||
|
echo " launchctl load ~/Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist"
|
||||||
|
fi
|
||||||
|
if [ -x /bin/systemctl ]; then
|
||||||
|
echo " sudo /bin/systemctl restart ${BINARY}"
|
||||||
|
fi
|
||||||
|
echo "Examine the log file at: /usr/local/var/log/${BINARY}.log (logs may go elsewhere on linux, check syslog)"
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
#!/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
|
||||||
Loading…
Reference in New Issue