diff --git a/.gitignore b/.gitignore index db76dd791..ba79d0276 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /init/macos/*.app/Contents/MacOS/* # The rest is probably fine. /rsrc*.syso +/aur /*.log /*.conf /*.gz @@ -34,6 +35,7 @@ README.html /homebrew-mugs .secret*files.tar github_deploy_key* +aur_deploy_key* .metadata.make /after-install-rendered.sh /before-remove-rendered.sh diff --git a/.secret_files.tar.enc b/.secret_files.tar.enc index c23618b5f..115c159e6 100644 Binary files a/.secret_files.tar.enc and b/.secret_files.tar.enc differ diff --git a/.travis.yml b/.travis.yml index 6d4eaa455..50d8e58cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -62,13 +62,20 @@ after_success: # This is an ssh key added to your homebrew forumla repo. - | mkdir -p $HOME/.ssh - declare -r SSH_FILE="$(mktemp -u $HOME/.ssh/XXXXX)" - echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> $HOME/.ssh/config - [ ! -f github_deploy_key ] || (mv github_deploy_key $SSH_FILE \ - && chmod 600 "$SSH_FILE" \ + declare -r HB_FILE="$(mktemp -u $HOME/.ssh/XXXXX)" + [ ! -f github_deploy_key ] || (mv github_deploy_key "${HB_FILE}" \ + && chmod 600 "$HB_FILE" \ && printf "%s\n" \ "Host github.com" \ - " IdentityFile $SSH_FILE" \ + " IdentityFile ${HB_FILE}" \ + " StrictHostKeyChecking no" \ + " LogLevel ERROR" >> $HOME/.ssh/config) + declare -r AU_FILE="$(mktemp -u $HOME/.ssh/XXXXX)" + [ ! -f aur_deploy_key ] || (mv aur_deploy_key "${AU_FILE}" \ + && chmod 600 "${AU_FILE}" \ + && printf "%s\n" \ + "Host github.com-aurepo" \ + " IdentityFile ${AU_FILE}" \ " StrictHostKeyChecking no" \ " LogLevel ERROR" >> $HOME/.ssh/config) deploy: @@ -143,3 +150,9 @@ deploy: on: tags: true condition: "$TRAVIS_OS_NAME = osx" + # Upload aur PKGBUILD file to a special repo. + - provider: script + script: bash scripts/aur-deploy.sh + on: + tags: true + condition: "$TRAVIS_OS_NAME = linux" diff --git a/Makefile b/Makefile index 1a491b76b..8733a7751 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,15 @@ RSRC_BIN=github.com/akavel/rsrc # If upx is available, use it to compress the binaries. UPXPATH=$(shell which upx) +# Skip upx in Mac ARM environments: https://github.com/upx/upx/issues/446 +ifeq ($(shell uname -ps),Darwin arm) + UPXPATH= +endif + +ifeq ($(shell grep -o 'Arch Linux' /etc/issue 2>/dev/null),Arch Linux) + UPXPATH= +endif + # Travis CI passes the version in. Local builds get it from the current git tag. ifeq ($(VERSION),) include .metadata.make @@ -91,7 +100,8 @@ clean: rm -f $(BINARY) $(BINARY).*.{macos,freebsd,linux,exe,upx}{,.gz,.zip} $(BINARY).1{,.gz} $(BINARY).rb rm -f $(BINARY){_,-}*.{deb,rpm,txz} v*.tar.gz.sha256 examples/MANUAL .metadata.make rsrc_*.syso rm -f cmd/$(BINARY)/README{,.html} README{,.html} ./$(BINARY)_manual.html rsrc.syso $(MACAPP).app.zip - rm -rf package_build_* release after-install-rendered.sh before-remove-rendered.sh $(MACAPP).app + rm -f $(BINARY).aur.install PKGBUILD $(BINARY).service + rm -rf aur package_build_* release after-install-rendered.sh before-remove-rendered.sh $(MACAPP).app #################### ##### Sidecars ##### @@ -198,6 +208,34 @@ $(MACAPP).app: macos [ -z "$(MACAPP)" ] || cp $(BINARY).amd64.macos init/macos/$(MACAPP).app/Contents/MacOS/$(MACAPP) [ -z "$(MACAPP)" ] || cp -rp init/macos/$(MACAPP).app $(MACAPP).app +aur: PKGBUILD SRCINFO $(BINARY).aur.install + mkdir -p $@ + mv PKGBUILD $(BINARY).aur.install $@/ + mv SRCINFO $@/.SRCINFO + +PKGBUILD: v$(VERSION).tar.gz.sha256 + @echo "Creating 'aur' PKGBUILD file for $(BINARY) version '$(RPMVERSION)-$(ITERATION)'." + 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%{{BINARY}}%$(BINARY)%g" \ + -e "s%{{SOURCE_URL}}%$(SOURCE_URL)%g" \ + -e "s%{{SOURCE_PATH}}%$(SOURCE_PATH)%g" \ + -e "s%{{CONFIG_FILE}}%$(CONFIG_FILE)%g" \ + init/archlinux/PKGBUILD.template | tee PKGBUILD + +SRCINFO: v$(VERSION).tar.gz.sha256 + 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%{{BINARY}}%$(BINARY)%g" \ + -e "s%{{SOURCE_URL}}%$(SOURCE_URL)%g" \ + -e "s%{{SOURCE_PATH}}%$(SOURCE_PATH)%g" \ + -e "s%{{CONFIG_FILE}}%$(CONFIG_FILE)%g" \ + init/archlinux/SRCINFO.template | tee SRCINFO + rpm: $(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm $(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm: package_build_linux check_fpm @echo "Building 'rpm' package for $(BINARY) version '$(RPMVERSION)-$(ITERATION)'." @@ -262,7 +300,7 @@ $(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 $< $(EXTRA_FPM_FLAGS) # Build an environment that can be packaged for linux. -package_build_linux: readme man plugins_linux_amd64 after-install-rendered.sh before-remove-rendered.sh linux +package_build_linux: readme man plugins_linux_amd64 after-install-rendered.sh before-remove-rendered.sh $(BINARY).service linux # Building package environment for linux. 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. @@ -274,9 +312,12 @@ package_build_linux: readme man plugins_linux_amd64 after-install-rendered.sh be cp examples/$(CONFIG_FILE).example $@/etc/$(BINARY)/$(CONFIG_FILE) cp LICENSE *.html examples/*?.?* $@/usr/share/doc/$(BINARY)/ [ "$(FORMULA)" != "service" ] || mkdir -p $@/lib/systemd/system + [ "$(FORMULA)" != "service" ] || mv $(BINARY).service $@/lib/systemd/system/ + +$(BINARY).service: [ "$(FORMULA)" != "service" ] || \ 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 > $(BINARY).service after-install-rendered.sh: sed -e "s/{{BINARY}}/$(BINARY)/g" scripts/after-install.sh > after-install-rendered.sh @@ -284,6 +325,17 @@ after-install-rendered.sh: before-remove-rendered.sh: sed -e "s/{{BINARY}}/$(BINARY)/g" scripts/before-remove.sh > before-remove-rendered.sh +# This is used for arch linux +$(BINARY).aur.install: + echo "post_upgrade() {" >> $@ + echo " /bin/systemctl restart $(BINARY)" >> $@ + echo "}" >> $@ + echo "" >> $@ + echo "pre_remove() {" >> $@ + echo " /bin/systemctl stop $(BINARY)" >> $@ + echo " /bin/systemctl disable $(BINARY)" >> $@ + echo "}" >> $@ + package_build_linux_386: package_build_linux linux386 mkdir -p $@ cp -r $ sysusers.conf + install -Dm0644 "sysusers.conf" "${pkgdir}/usr/lib/sysusers.d/notifiarr.conf" + rm sysusers.conf + # Systemd Service Unit. + install -Dm644 "${pkgname}.service" "${pkgdir}/usr/lib/systemd/system/${pkgname}.service" +} diff --git a/init/archlinux/README.md b/init/archlinux/README.md new file mode 100644 index 000000000..b075956fe --- /dev/null +++ b/init/archlinux/README.md @@ -0,0 +1 @@ +This template file is built by Travis-CI and uploaded to a [different github repo](https://github.com/golift/aur). diff --git a/init/archlinux/SRCINFO.template b/init/archlinux/SRCINFO.template new file mode 100644 index 000000000..0c5b53c5a --- /dev/null +++ b/init/archlinux/SRCINFO.template @@ -0,0 +1,21 @@ +pkgbase = {{BINARY}} + pkgdesc = {{Desc}} + pkgver = {{VERSION}} + pkgrel = {{Iter}} + url = {{SOURCE_URL}} + install = {{BINARY}}.aur.install + arch = x86_64 + arch = arm + arch = armv6h + arch = armv7h + arch = aarch64 + arch = i686 + arch = pentium4 + license = MIT + makedepends = go + makedepends = make + backup = etc/{{BINARY}}/{{CONFIG_FILE}} + source = {{BINARY}}-{{VERSION}}.tar.gz::{{SOURCE_PATH}} + sha256sums = {{SHA256}} + +pkgname = {{BINARY}} diff --git a/init/buildinfo.sh b/init/buildinfo.sh index 465618ec6..996318390 100644 --- a/init/buildinfo.sh +++ b/init/buildinfo.sh @@ -4,19 +4,28 @@ ########## VENDOR="Go Lift " - -# 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 +export VENDOR DATE BUILDS + +[ "$GOFLAGS" != "" ] || export GOFLAGS="-trimpath -mod=readonly -modcacherw" +export CGO_CPPFLAGS="${CPPFLAGS}" +export CGO_CFLAGS="${CFLAGS}" +export CGO_CXXFLAGS="${CXXFLAGS}" +export CGO_LDFLAGS="${LDFLAGS}" + +if git status > /dev/null 2>&1; then + # 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) + COMMIT="$(git rev-parse --short HEAD || echo 0)" + + GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD || echo unknown)" + BRANCH="${TRAVIS_BRANCH:-${GIT_BRANCH}}" +fi + +export VVERSION VERSION ITERATION BRANCH COMMIT diff --git a/scripts/after-install.sh b/scripts/after-install.sh index d06888c95..96eb64aa4 100644 --- a/scripts/after-install.sh +++ b/scripts/after-install.sh @@ -1,6 +1,6 @@ #!/bin/sh -# This file is used by deb, rpm and BSD packages. +# This file is used by aur, deb, rpm and BSD 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. diff --git a/scripts/aur-deploy.sh b/scripts/aur-deploy.sh new file mode 100644 index 000000000..b45613c10 --- /dev/null +++ b/scripts/aur-deploy.sh @@ -0,0 +1,24 @@ +#!/bin/bash -x + +# Deploys a new aur PKGBUILD file to a github repo: $AUREPO +# Requires SSH credentials in ssh-agent to work. +# Run by Travis-CI when a new release is created on GitHub. +# Do not edit this file. + +source settings.sh + +make aur + +git config --global user.email "${BINARY}@auto.releaser" +git config --global user.name "${BINARY}-auto-releaser" + +rm -rf aur_release_repo +git clone git@github.com-aurepo:${AUREPO}.git aur_release_repo + +mkdir -p "aur_release_repo/${BINARY}" +cp aur/* "aur_release_repo/${BINARY}/" +pushd aur_release_repo +git add ${BINARY} +git commit -m "Update ${BINARY} on Release: v${VERSION}-${ITERATION}" +git push +popd diff --git a/scripts/before-remove.sh b/scripts/before-remove.sh index 589bf0bb2..419aa3e94 100644 --- a/scripts/before-remove.sh +++ b/scripts/before-remove.sh @@ -1,6 +1,6 @@ #!/bin/bash -# This file is used by rpm and deb packages. FPM use. +# This file is used by aur, 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. diff --git a/settings.sh b/settings.sh index 446880410..f71c0e1e5 100644 --- a/settings.sh +++ b/settings.sh @@ -12,7 +12,8 @@ BINARY="notifiarr" REPO="Notifiarr/notifiarr" # Github repo containing homebrew formula repo. HBREPO="golift/homebrew-mugs" -MAINT="David Newhall II " +AUREPO="golift/aur" +MAINT="David Newhall II " DESC="Unified Client for Notifiarr.com" GOLANGCI_LINT_ARGS="--enable-all -D exhaustivestruct,nlreturn,forbidigo,cyclop,interfacer,maligned,scopelint,dupl,tagliatelle,golint" # Example must exist at examples/$CONFIG_FILE.example @@ -30,8 +31,8 @@ SOURCE_URL="https://github.com/${REPO}" # Name the Version-containing library the same as the github repo, without dashes. VERSION_PATH="golift.io/version" -# Used by homebrew downloads. -SOURCE_PATH=https://codeload.github.com/${REPO}/tar.gz/v${VERSION} +# Used by homebrew and arch linux downloads. +SOURCE_PATH=https://codeload.github.com/${REPO}/tar.gz/refs/tags/v${VERSION} export BINARY HBREPO MAINT VENDOR DESC GOLANGCI_LINT_ARGS CONFIG_FILE export LICENSE FORMULA SOURCE_URL VERSION_PATH SOURCE_PATH @@ -46,7 +47,6 @@ export WINDOWS_LDFLAGS="" export MACAPP="Notifiarr" export EXTRA_FPM_FLAGS="--conflicts=discordnotifier-client>0.0.1 --provides=notifiarr --provides=discordnotifier-client" - # Make sure Docker builds work locally. # These do not affect automated builds, just allow the docker build scripts to run from a local clone. [ -n "$SOURCE_BRANCH" ] || export SOURCE_BRANCH=$BRANCH