Makefile and build pipeline updates.

This commit is contained in:
David Newhall II
2019-06-07 12:19:17 -07:00
parent 47d0acf718
commit ab180e1fa0
5 changed files with 125 additions and 133 deletions
-52
View File
@@ -1,52 +0,0 @@
#!/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 for ${BINARY} version ${VERSION}."
# eh, don't change these.
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}.linux package_build${BINFIX}/bin/${BINARY}
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
# Make a package.
fpm -s dir -t ${OUTPUT} \
--name ${BINARY} \
--version ${VERSION} \
--iteration $(git rev-list --all --count) \
--after-install scripts/after-install.sh \
--before-remove scripts/before-remove.sh \
--license MIT \
--url 'https://github.com/davidnewhall/unifi-poller' \
--maintainer 'david at sleepers dot pro' \
--description 'This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database.' \
--chdir package_build
-46
View File
@@ -1,46 +0,0 @@
#!/bin/bash
# This script builds a simple macos Installer pkg. Run by the Makefile.
# Use: `make osxpkg`
OUTPUT=osxpkg
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 '${OUTPUT}' package for ${BINARY} version ${VERSION}."
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}.macos package_build${BINFIX}/bin/${BINARY}
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 ${OUTPUT} \
--name ${BINARY} \
--version ${VERSION} \
--iteration $(git rev-list --all --count) \
--after-install scripts/after-install-osx.sh \
--osxpkg-identifier-prefix com.github.davidnewhall \
--license MIT \
--maintainer 'david at sleepers dot pro' \
--url 'https://github.com/davidnewhall/unifi-poller' \
--description 'This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database.' \
--chdir package_build
+79
View File
@@ -0,0 +1,79 @@
#!/bin/bash
# This script builds a deb, rpm or osx package. Run by the Makefile.
# Use: `make rpm`, `make deb`, or `make osxpkg`
set -e -o pipefail
BINARY=unifi-poller
OUTPUT=$1
VERSION=$2
ITERATION=$3
[ "$VERSION" != "" ] || VERSION=$(git tag -l --merged | tail -n1 | tr -d v)
[ "$ITERATION" != "" ] || ITERATION=$(git rev-list --all --count)
if [ "$OUTPUT" != "deb" ] && [ "$OUTPUT" != "rpm" ] && [ "$OUTPUT" != "osxpkg" ]; then
echo "first argument must be 'deb' or 'rpm' or 'osxpkg'"
exit 1
fi
fpm -h > /dev/null 2>&1
if [ "$?" != "0" ]; then
echo "Package Build Failure. FPM missing. Install FPM: https://fpm.readthedocs.io/en/latest/installing.html"
exit 1
fi
echo "Building '${OUTPUT}' package for ${BINARY} version '${VERSION}-${ITERATION}'."
# These paths work on Linux. Suggest not changing.
PREFIX=
BINFIX=/usr
UNAME=linux
AFTER=scripts/after-install.sh
if [ "$OUTPUT" = "osxpkg" ]; then
# These paths work on OSX. Do not change.
PREFIX=/usr/local
BINFIX=/usr/local
UNAME=macos
AFTER=scripts/after-install-osx.sh
fi
# Make a build environment.
rm -rf package_build
mkdir -p package_build${BINFIX}/bin package_build${PREFIX}/etc/${BINARY}
mkdir -p package_build${BINFIX}/share/man/man1 package_build${BINFIX}/share/doc/unifi-poller
# Copy the binary, config file and man page into the env.
cp ${BINARY}.${UNAME} package_build${BINFIX}/bin/${BINARY}
cp *.1.gz package_build${BINFIX}/share/man/man1
cp examples/*.conf.example package_build${PREFIX}/etc/${BINARY}/
cp examples/* package_build${BINFIX}/share/doc/unifi-poller
# Copy startup file. Different for osx vs linux.
if [ "$UNAME" = "linux" ]; then
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
else # macos
# Sometimes the log folder is missing on osx. Create it.
mkdir -p package_build${PREFIX}/var/log
mkdir -p package_build/Library/LaunchAgents
cp init/launchd/com.github.davidnewhall.unifi-poller.plist package_build/Library/LaunchAgents/
fi
# Make a package.
fpm -s dir -t ${OUTPUT} \
--name ${BINARY} \
--version ${VERSION} \
--iteration ${ITERATION} \
--after-install ${AFTER} \
--before-remove scripts/before-remove.sh \
--osxpkg-identifier-prefix com.github.davidnewhall \
--license MIT \
--url 'https://github.com/davidnewhall/unifi-poller' \
--maintainer 'david at sleepers dot pro' \
--description 'This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database.' \
--chdir package_build