Skip to content

Commit

Permalink
Merge pull request #137 from Notifiarr/dn2_arch
Browse files Browse the repository at this point in the history
Start on arch linux support.
  • Loading branch information
davidnewhall authored Nov 22, 2021
2 parents 81e3c74 + 57477c2 commit a98753e
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/init/macos/*.app/Contents/MacOS/*
# The rest is probably fine.
/rsrc*.syso
/aur
/*.log
/*.conf
/*.gz
Expand Down Expand Up @@ -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
Expand Down
Binary file modified .secret_files.tar.enc
Binary file not shown.
23 changes: 18 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
58 changes: 55 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 #####
Expand Down Expand Up @@ -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)'."
Expand Down Expand Up @@ -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.
Expand All @@ -274,16 +312,30 @@ 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

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 $</* $@/
Expand Down
64 changes: 64 additions & 0 deletions init/archlinux/PKGBUILD.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
pkgname={{BINARY}}
pkgver={{VERSION}}
pkgrel={{Iter}}
pkgdesc='{{Desc}}'
arch=('x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64' 'i686' 'pentium4')
url='{{SOURCE_URL}}'
license=('MIT')
makedepends=('go' 'make')
source=("notifiarr-${pkgver}.tar.gz::{{SOURCE_PATH}}")
sha256sums=('{{SHA256}}')
configfile='{{CONFIG_FILE}}'
backup=("etc/${pkgname}/${configfile}")
install="${pkgname}.aur.install"

build() {
cd "$pkgname-$pkgver"
export EXTRA_LDFLAGS=-linkmode=external
export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
make man VERSION="${pkgver}" ITERATION="${pkgrel}"
make "${pkgname}.service" VERSION="${pkgver}" ITERATION="${pkgrel}"

if [ "$CARCH" == "x86_64" ]; then
make linux VERSION="${pkgver}" ITERATION="${pkgrel}"
mv "$pkgname.amd64.linux" "$pkgname"
elif [ "$CARCH" == "arm" ] || [ "$CARCH" == "armv6h" ] || [ "$CARCH" == "armv7h" ]; then
make armhf VERSION="${pkgver}" ITERATION="${pkgrel}"
mv "$pkgname.armhf.linux" "$pkgname"
elif [ "$CARCH" == "aarch64" ]; then
make arm64 VERSION="${pkgver}" ITERATION="${pkgrel}"
mv "$pkgname.arm64.linux" "$pkgname"
elif [ "$CARCH" == "i686" ] || [ "$CARCH" == "pentium4" ]; then
make linux386 VERSION="${pkgver}" ITERATION="${pkgrel}"
mv "$pkgname.i386.linux" "$pkgname"
fi
}

check() {
cd "$pkgname-$pkgver"
go test ./...
}

package() {
cd "$pkgname-$pkgver"
# Binary.
install -Dm755 "${pkgname}" "${pkgdir}/usr/bin/${pkgname}"
# Directories.
install -dm0755 "${pkgdir}/share/doc/${pkgname}" \
"${pkgdir}/usr/share/licenses/${pkgname}" "${pkgdir}/etc/${pkgname}"
# Man file.
install -Dm644 "${pkgname}.1.gz" "${pkgdir}/share/man/man1/${pkgname}.1.gz"
# Config file, ane example config file.
install -m644 "examples/${configfile}.example" "${pkgdir}/etc/$pkgname/${configfile}.example"
install -m644 "examples/${configfile}.example" "${pkgdir}/etc/${pkgname}/${configfile}"
# Extra documentation.
install -m644 *.html examples/* "${pkgdir}/share/doc/${pkgname}/"
# License.
install -m644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
# User and group.
echo 'u notifiarr - "notifiarr.com client" -' > 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"
}
1 change: 1 addition & 0 deletions init/archlinux/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This template file is built by Travis-CI and uploaded to a [different github repo](https://github.com/golift/aur).
21 changes: 21 additions & 0 deletions init/archlinux/SRCINFO.template
Original file line number Diff line number Diff line change
@@ -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}}
33 changes: 21 additions & 12 deletions init/buildinfo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@
##########

VENDOR="Go Lift <[email protected]>"

# 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
2 changes: 1 addition & 1 deletion scripts/after-install.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
24 changes: 24 additions & 0 deletions scripts/aur-deploy.sh
Original file line number Diff line number Diff line change
@@ -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 [email protected]:${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
2 changes: 1 addition & 1 deletion scripts/before-remove.sh
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
8 changes: 4 additions & 4 deletions settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ BINARY="notifiarr"
REPO="Notifiarr/notifiarr"
# Github repo containing homebrew formula repo.
HBREPO="golift/homebrew-mugs"
MAINT="David Newhall II <david at sleepers dot pro>"
AUREPO="golift/aur"
MAINT="David Newhall II <captain at golift dot io>"
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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a98753e

Please sign in to comment.