From ac43cf65c75a217a2919902a7e2cf9f6fc8e57a8 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 3 Jul 2019 21:27:50 -0700 Subject: [PATCH 1/3] Make more packages. --- .gitignore | 5 ++- Makefile | 127 ++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 114 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 933a6837..53ba083f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,9 +5,10 @@ /unifi-poller*.1 /unifi-poller*.deb /unifi-poller*.rpm +/unifi-poller.*.arm /unifi-poller.exe -/unifi-poller.macos -/unifi-poller.linux +/unifi-poller.*.macos +/unifi-poller.*.linux /unifi-poller.rb *.sha256 /vendor diff --git a/Makefile b/Makefile index 59525791..ed7e7538 100644 --- a/Makefile +++ b/Makefile @@ -36,20 +36,20 @@ VERSION_PATH:=github.com/$(GHUSER)/$(BINARY)/$(shell echo $(BINARY) | tr -d -- - all: man build # Prepare a release. Called in Travis CI. -release: clean vendor test macos windows $(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb +release: clean vendor test macos arm windows linux_packages # Prepareing a release! mkdir -p release - mv $(BINARY).linux $(BINARY).macos release/ + mv $(BINARY).*.linux $(BINARY).*.macos release/ gzip -9r release/ - zip -9qm release/$(BINARY).exe.zip $(BINARY).exe - mv $(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb release/ + for i in $(BINARY)*.exe; do zip -9qm release/$$i.zip $$i;done + mv *.rpm *.deb release/ # Generating File Hashes for i in release/*; do /bin/echo -n "$$i " ; (openssl dgst -r -sha256 "$$i" | head -c64 ; echo) | tee "$$i.sha256.txt"; done # Delete all build assets. clean: # Cleaning up. - rm -f $(BINARY){.macos,.linux,.1,}{,.gz} $(BINARY).rb + rm -f $(BINARY) $(BINARY).*.{macos,linux,exe}{,.gz} $(BINARY).1{,.gz} $(BINARY).rb rm -f $(BINARY){_,-}*.{deb,rpm} v*.tar.gz.sha256 rm -f cmd/$(BINARY)/README{,.html} README{,.html} ./$(BINARY)_manual.html rm -rf package_build_* release @@ -79,28 +79,41 @@ build: $(BINARY) $(BINARY): go build -o $(BINARY) -ldflags "-w -s -X $(VERSION_PATH)" -linux: $(BINARY).linux -$(BINARY).linux: +linux: $(BINARY).amd64.linux +$(BINARY).amd64.linux: # Building linux binary. - GOOS=linux go build -o $(BINARY).linux -ldflags "-w -s -X $(VERSION_PATH)" + GOOS=linux GOARCH=amd64 go build -o $(BINARY).amd64.linux -ldflags "-w -s -X $(VERSION_PATH)" -macos: $(BINARY).macos -$(BINARY).macos: +linux386: $(BINARY).i386.linux +$(BINARY).i386.linux: + # Building linux binary. + GOOS=linux GOARCH=386 go build -o $(BINARY).i386.linux -ldflags "-w -s -X $(VERSION_PATH)" + +arm: $(BINARY).arm.linux +$(BINARY).arm.linux: + # Building linux binary. + GOOS=linux GOARCH=arm GOARM=5 go build -o $(BINARY).arm.linux -ldflags "-w -s -X $(VERSION_PATH)" + +macos: $(BINARY).amd64.macos +$(BINARY).amd64.macos: # Building darwin binary. - GOOS=darwin go build -o $(BINARY).macos -ldflags "-w -s -X $(VERSION_PATH)" + GOOS=darwin GOARCH=amd64 go build -o $(BINARY).amd64.macos -ldflags "-w -s -X $(VERSION_PATH)" -exe: $(BINARY).exe -windows: $(BINARY).exe -$(BINARY).exe: +exe: $(BINARY).amd64.exe +windows: $(BINARY).amd64.exe +$(BINARY).amd64.exe: # Building windows binary. - GOOS=windows go build -o $(BINARY).exe -ldflags "-w -s -X $(VERSION_PATH)" + GOOS=windows GOARCH=amd64 go build -o $(BINARY).amd64.exe -ldflags "-w -s -X $(VERSION_PATH)" # Packages +linux_packages: rpm deb rpm386 deb386 debarm rpmarm + rpm: $(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm $(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm: check_fpm package_build_linux @echo "Building 'rpm' package for $(BINARY) version '$(RPMVERSION)-$(ITERATION)'." fpm -s dir -t rpm \ + --architecture x86_64 \ --name $(BINARY) \ --rpm-os linux \ --version $(RPMVERSION) \ @@ -118,6 +131,7 @@ deb: $(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 \ + --architecture amd64 \ --name $(BINARY) \ --deb-no-default-config-files \ --version $(VERSION) \ @@ -131,6 +145,77 @@ $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb: check_fpm package_build_linux --config-files "/etc/$(BINARY)/$(CONFIG_FILE)" \ --chdir package_build_linux +rpm386: $(BINARY)-$(RPMVERSION)-$(ITERATION).i386.rpm +$(BINARY)-$(RPMVERSION)-$(ITERATION).i386.rpm: check_fpm package_build_linux_386 + @echo "Building 32-bit 'rpm' package for $(BINARY) version '$(RPMVERSION)-$(ITERATION)'." + fpm -s dir -t rpm \ + --architecture i386 \ + --name $(BINARY) \ + --rpm-os linux \ + --version $(RPMVERSION) \ + --iteration $(ITERATION) \ + --after-install scripts/after-install.sh \ + --before-remove scripts/before-remove.sh \ + --license MIT \ + --url $(URL) \ + --maintainer "$(MAINT)" \ + --description "$(DESC)" \ + --config-files "/etc/$(BINARY)/$(CONFIG_FILE)" \ + --chdir package_build_linux_386 + +deb386: $(BINARY)_$(VERSION)-$(ITERATION)_i386.deb +$(BINARY)_$(VERSION)-$(ITERATION)_i386.deb: check_fpm package_build_linux_386 + @echo "Building 32-bit 'deb' package for $(BINARY) version '$(VERSION)-$(ITERATION)'." + fpm -s dir -t deb \ + --architecture i386 \ + --name $(BINARY) \ + --deb-no-default-config-files \ + --version $(VERSION) \ + --iteration $(ITERATION) \ + --after-install scripts/after-install.sh \ + --before-remove scripts/before-remove.sh \ + --license MIT \ + --url $(URL) \ + --maintainer "$(MAINT)" \ + --description "$(DESC)" \ + --config-files "/etc/$(BINARY)/$(CONFIG_FILE)" \ + --chdir package_build_linux_386 + +rpmarm: $(BINARY)-$(RPMVERSION)-$(ITERATION).arm.rpm +$(BINARY)-$(RPMVERSION)-$(ITERATION).arm.rpm: check_fpm package_build_linux_arm + @echo "Building 32-bit ARM 'rpm' package for $(BINARY) version '$(RPMVERSION)-$(ITERATION)'." + fpm -s dir -t rpm \ + --architecture arm \ + --name $(BINARY) \ + --rpm-os linux \ + --version $(RPMVERSION) \ + --iteration $(ITERATION) \ + --after-install scripts/after-install.sh \ + --before-remove scripts/before-remove.sh \ + --license MIT \ + --url $(URL) \ + --maintainer "$(MAINT)" \ + --description "$(DESC)" \ + --config-files "/etc/$(BINARY)/$(CONFIG_FILE)" \ + --chdir package_build_linux_arm + +debarm: $(BINARY)_$(VERSION)-$(ITERATION)_arm.deb +$(BINARY)_$(VERSION)-$(ITERATION)_arm.deb: check_fpm package_build_linux_arm + @echo "Building 32-bit ARM 'deb' package for $(BINARY) version '$(VERSION)-$(ITERATION)'." + fpm -s dir -t deb \ + --architecture arm \ + --name $(BINARY) \ + --deb-no-default-config-files \ + --version $(VERSION) \ + --iteration $(ITERATION) \ + --after-install scripts/after-install.sh \ + --before-remove scripts/before-remove.sh \ + --license MIT \ + --url $(URL) \ + --maintainer "$(MAINT)" \ + --description "$(DESC)" \ + --config-files "/etc/$(BINARY)/$(CONFIG_FILE)" \ + --chdir package_build_linux_arm docker: docker build -f init/docker/Dockerfile -t $(DHUSER)/$(BINARY) . @@ -140,7 +225,7 @@ package_build_linux: readme man linux mkdir -p $@/usr/bin $@/etc/$(BINARY) $@/lib/systemd/system mkdir -p $@/usr/share/man/man1 $@/usr/share/doc/$(BINARY) # Copying the binary, config file, unit file, and man page into the env. - cp $(BINARY).linux $@/usr/bin/$(BINARY) + cp $(BINARY).amd64.linux $@/usr/bin/$(BINARY) cp *.1.gz $@/usr/share/man/man1 cp examples/$(CONFIG_FILE).example $@/etc/$(BINARY)/ cp examples/$(CONFIG_FILE).example $@/etc/$(BINARY)/$(CONFIG_FILE) @@ -148,6 +233,16 @@ package_build_linux: readme man linux # These go to their own folder so the img src in the html pages continue to work. cp init/systemd/$(BINARY).service $@/lib/systemd/system/ +package_build_linux_386: package_build_linux linux386 + mkdir -p package_build_linux_386 + cp -r package_build_linux/* package_build_linux_386/ + cp $(BINARY).i386.linux $@/usr/bin/$(BINARY) + +package_build_linux_arm: package_build_linux arm + mkdir -p package_build_linux_arm + cp -r package_build_linux/* package_build_linux_arm/ + cp $(BINARY).arm.linux $@/usr/bin/$(BINARY) + check_fpm: @fpm --version > /dev/null || (echo "FPM missing. Install FPM: https://fpm.readthedocs.io/en/latest/installing.html" && false) From 9ced568074560b5f50e81ab31352241c0dde8e93 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 3 Jul 2019 22:04:29 -0700 Subject: [PATCH 2/3] add install script --- scripts/install.sh | 92 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 scripts/install.sh diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 00000000..9bf9bfe5 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +# This is a quick and drity script to install the latest Linux package. +# +# Use it like this: (sudo is optional) +# === +# curl https://raw.githubusercontent.com/davidnewhall/unifi-poller/master/scripts/install.sh | sudo bash +# === +# If you're on redhat, this installs the latest rpm. If you're on Debian, it installs the latest deb package. +# + +REPO=davidnewhall/unifi-poller +LATEST=https://api.github.com/repos/${REPO}/releases/latest +ARCH=$(uname -m) + +# $ARCH is passed into egrep to find the right file. +if [ "$ARCH" = "x86_64" ]; then + ARCH="$ARCH|amd64" +elif [ "$ARCH" = "amd64" ]; then + ARCH="$ARCH|x86_64" +elif [[ $ARCH == *arm* ]]; then + ARCH="arm" +else + echo "Unknown Architecture. Submit a pull request to fix this, please." + echo ==> $ARCH + exit 1 +fi + +if [ "$1" == "deb" ] || [ "$1" == "rpm" ]; then + FILE=$1 +else + # If you have both, rpm wins. + rpm --version > /dev/null 2>&1 + if [ "$?" = "0" ]; then + FILE=rpm + else + dpkg --version > /dev/null 2>&1 + if [ "$?" = "0" ]; then + FILE=deb + fi + fi +fi + +if [ "$FILE" = "" ]; then + echo "No dpkg or rpm package managers found!" + exit 1 +fi + +# curl or wget? +curl --version > /dev/null 2>&1 +if [ "$?" = "0" ]; then + CMD="curl -L" +else + wget --version > /dev/null 2>&1 + if [ "$?" = "0" ]; then + CMD="wget -O-" + fi +fi + +if [ "$CMD" = "" ]; then + echo "Need curl or wget - could not find either!" + exit 1 +fi + +# Grab latest release file from github. +URL=$($CMD ${LATEST} | egrep "browser_download_url.*\.(${ARCH}).${FILE}\"" | cut -d\" -f 4) + +if [ "$?" != "0" ] || [ "$URL" = "" ]; then + echo "Error locating latest release at ${LATEST}" + exit 1 +fi + +INSTALLER="rpm -Uvh" +if [ "$FILE" = "deb" ]; then + INSTALLER="dpkg -i" +fi + +FILE=$(basename ${URL}) +echo "Downloading: ${URL} to /tmp/${FILE}" +$CMD ${URL} > /tmp/${FILE} + +# Install it. +if [ "$(id -u)" = "0" ]; then + echo "===================================" + echo "Downloaded. Installing the package!" + echo "Running: ${INSTALLER} /tmp/${FILE}" + $INSTALLER /tmp/${FILE} +else + echo "================================" + echo "Downloaded. Install the package:" + echo "sudo $INSTALLER /tmp/${FILE}" +fi From c652935f72b52fc118929263dd54a3718b138104 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 3 Jul 2019 22:06:59 -0700 Subject: [PATCH 3/3] fix docker. --- init/docker/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/init/docker/Dockerfile b/init/docker/Dockerfile index 81214a23..ba4312b7 100644 --- a/init/docker/Dockerfile +++ b/init/docker/Dockerfile @@ -17,16 +17,16 @@ RUN dep ensure \ && CGO_ENABLED=0 make linux # -# creating container for run -# to use this container use the following command: +# creating container for run +# to use this container use the following command: # # docker run -d -v /your/config/up.conf:/etc/unifi-poller/up.conf golift/unifi-poller # # by using "-e UNIFI_PASSWORD=your-secret-pasword" you can avoid this configuration in the config file # -FROM scratch +FROM scratch -COPY --from=builder /go/src/github.com/davidnewhall/unifi-poller/unifi-poller.linux /unifi-poller +COPY --from=builder /go/src/github.com/davidnewhall/unifi-poller/unifi-poller.amd64.linux /unifi-poller COPY --from=builder /go/src/github.com/davidnewhall/unifi-poller/examples/up.conf.example /etc/unifi-poller/up.conf VOLUME [ "/etc/unifi-poller"]